Note that the discovery start/finish intents are also handled - * by {@link BluetoothEventManager} to update the UI, if visible. - */ -public final class BluetoothDiscoveryReceiver extends BroadcastReceiver { - private static final String TAG = "BluetoothDiscoveryReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - Log.v(TAG, "Received: " + action); - - if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED) || - action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { - LocalBluetoothPreferences.persistDiscoveringTimestamp(context); - } - } -} diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java index 020ca0c8a6b..52a015ebe38 100644 --- a/src/com/android/settings/bluetooth/DockService.java +++ b/src/com/android/settings/bluetooth/DockService.java @@ -938,13 +938,7 @@ public final class DockService extends Service implements ServiceListener { public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { } public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { } public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { } - - @Override - public void onScanningStateChanged(boolean started) { - // TODO: Find a more unified place for a persistent BluetoothCallback to live - // as this is not exactly dock related. - LocalBluetoothPreferences.persistDiscoveringTimestamp(mContext); - } + public void onScanningStateChanged(boolean started) { } @Override public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { diff --git a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java index 401b13c5ad9..6a0bdcf4b21 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java @@ -40,8 +40,6 @@ final class LocalBluetoothPreferences { // of raising notifications private static final int GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000; - private static final String KEY_DISCOVERING_TIMESTAMP = "last_discovering_time"; - private static final String KEY_LAST_SELECTED_DEVICE = "last_selected_device"; private static final String KEY_LAST_SELECTED_DEVICE_TIME = "last_selected_device_time"; @@ -95,11 +93,14 @@ final class LocalBluetoothPreferences { // If the device was discoverING recently LocalBluetoothAdapter adapter = manager.getBluetoothAdapter(); - if (adapter != null && adapter.isDiscovering()) { - return true; - } else if ((sharedPreferences.getLong(KEY_DISCOVERING_TIMESTAMP, 0) + + if (adapter != null) { + if (adapter.isDiscovering()) { + return true; + } + if ((adapter.getDiscoveryEndMillis() + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) { - return true; + return true; + } } // If the device was picked in the device picker recently @@ -147,20 +148,6 @@ final class LocalBluetoothPreferences { editor.apply(); } - static void persistDiscoveringTimestamp(final Context context) { - // Load the shared preferences and edit it on a background - // thread (but serialized!). - QueuedWork.singleThreadExecutor().submit(new Runnable() { - public void run() { - SharedPreferences.Editor editor = getSharedPreferences(context).edit(); - editor.putLong( - KEY_DISCOVERING_TIMESTAMP, - System.currentTimeMillis()); - editor.apply(); - } - }); - } - static boolean hasDockAutoConnectSetting(Context context, String addr) { return getSharedPreferences(context).contains(KEY_DOCK_AUTO_CONNECT + addr); }