Merge "Bluetooth: remove BluetoothDiscoveryReceiver" am: 1ad23a71e4 am: 184506a710
am: 83fb10ae1e

Change-Id: Ib7a51c9cae91202087bfcc11e6eb18b219e84d36
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e5467b4..9fc90d7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2048,15 +2048,6 @@
         </activity>
 
         <receiver
-            android:name=".bluetooth.BluetoothDiscoveryReceiver">
-            <intent-filter>
-                <action android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
-                <action android:name="android.bluetooth.adapter.action.DISCOVERY_FINISHED" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-        </receiver>
-
-        <receiver
             android:name=".bluetooth.DockEventReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.DOCK_EVENT" />
diff --git a/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java b/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java
deleted file mode 100644
index 1ba9f85..0000000
--- a/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.bluetooth;
-
-import android.bluetooth.BluetoothAdapter;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.util.Log;
-
-import com.android.settingslib.bluetooth.BluetoothEventManager;
-
-/**
- * BluetoothDiscoveryReceiver updates a timestamp when the
- * Bluetooth adapter starts or finishes discovery mode. This
- * is used to decide whether to open an alert dialog or
- * create a notification when we receive a pairing request.
- *
- * <p>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 020ca0c..52a015e 100644
--- a/src/com/android/settings/bluetooth/DockService.java
+++ b/src/com/android/settings/bluetooth/DockService.java
@@ -938,13 +938,7 @@
         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 401b13c..6a0bdcf 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
@@ -40,8 +40,6 @@
     // 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 @@
 
         // 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 @@
         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);
     }