Bluetooth: remove BluetoothDiscoveryReceiver

Use new function getDiscoveryEndMillis() to replace use of shared preferences
and intents.

Test: scan recently, then connect from external BT device
Bug: 34395439
Change-Id: Ia498b3bb4868b656cbbb9fbdc607a49af948343b
This commit is contained in:
Marie Janssen
2017-01-24 14:21:29 -08:00
parent 6a153ac4aa
commit 683528db8b
4 changed files with 8 additions and 85 deletions

View File

@@ -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);
}