diff options
author | Michael Chan <mchan@android.com> | 2010-03-03 21:29:22 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-03-03 21:29:22 -0800 |
commit | 4f94e0bee65105d2cb351001babdbd09ae4c84ff (patch) | |
tree | d5cc5976d0407106d61ecc111414ba016138d724 /src/com/android/settings | |
parent | 1d6e7b8192d7b025c65f9014a0c05a919bcf190e (diff) | |
parent | 76098b7f7ac4f19af776fcad8413b582904bfdc2 (diff) | |
download | packages_apps_Settings-4f94e0bee65105d2cb351001babdbd09ae4c84ff.tar.gz packages_apps_Settings-4f94e0bee65105d2cb351001babdbd09ae4c84ff.tar.bz2 packages_apps_Settings-4f94e0bee65105d2cb351001babdbd09ae4c84ff.zip |
Merge "b/2310373 Show pairing dialogs if the device has been scanning for bt devices recently."
Diffstat (limited to 'src/com/android/settings')
-rw-r--r-- | src/com/android/settings/bluetooth/BluetoothEventRedirector.java | 16 | ||||
-rw-r--r-- | src/com/android/settings/bluetooth/LocalBluetoothManager.java | 13 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java index c1a211602..dbdf6c156 100644 --- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java +++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java @@ -16,6 +16,9 @@ package com.android.settings.bluetooth; +import com.android.settings.R; +import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; + import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; @@ -25,11 +28,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.util.Log; -import com.android.settings.R; -import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; - /** * BluetoothEventRedirector receives broadcasts and callbacks from the Bluetooth * API and dispatches the event on the UI thread to the right class in the @@ -53,9 +54,11 @@ public class BluetoothEventRedirector { BluetoothAdapter.ERROR); mManager.setBluetoothStateInt(state); } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { + persistDiscoveringTimestamp(); mManager.onScanningStateChanged(true); } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { + persistDiscoveringTimestamp(); mManager.onScanningStateChanged(false); } else if (action.equals(BluetoothDevice.ACTION_FOUND)) { @@ -191,4 +194,11 @@ public class BluetoothEventRedirector { } return null; } + + private void persistDiscoveringTimestamp() { + SharedPreferences.Editor editor = mManager.getSharedPreferences().edit(); + editor.putLong(LocalBluetoothManager.SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP, + System.currentTimeMillis()); + editor.commit(); + } } diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java index 43d4343dd..2ffb1393d 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java @@ -72,6 +72,9 @@ public class LocalBluetoothManager { // of raising notifications private static long GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000; + public static final String SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP = + "last_discovering_time"; + private static final String SHARED_PREFERENCES_KEY_LAST_SELECTED_DEVICE = "last_selected_device"; @@ -314,7 +317,7 @@ public class LocalBluetoothManager { long currentTimeMillis = System.currentTimeMillis(); SharedPreferences sharedPreferences = getSharedPreferences(); - // If the device was in discoverable mode recently + // If the device was in discoverABLE mode recently long lastDiscoverableEndTime = sharedPreferences.getLong( BluetoothDiscoverableEnabler.SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, 0); if ((lastDiscoverableEndTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) @@ -322,6 +325,14 @@ public class LocalBluetoothManager { return true; } + // If the device was discoverING recently + if (mAdapter != null && mAdapter.isDiscovering()) { + return true; + } else if ((sharedPreferences.getLong(SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP, 0) + + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) { + return true; + } + // If the device was picked in the device picker recently if (deviceAddress != null) { String lastSelectedDevice = sharedPreferences.getString( |