Merge "Bluetooth: remove BluetoothDiscoveryReceiver" am: 1ad23a71e4

am: 184506a710

Change-Id: I6114e7b4617e7f23373434a54672497654d6d786
This commit is contained in:
Marie Janssen
2017-01-30 17:57:11 +00:00
committed by android-build-merger
4 changed files with 8 additions and 85 deletions

View File

@@ -2044,15 +2044,6 @@
</intent-filter>
</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>

View File

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

View File

@@ -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) {

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,12 +93,15 @@ final class LocalBluetoothPreferences {
// If the device was discoverING recently
LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
if (adapter != null && adapter.isDiscovering()) {
if (adapter != null) {
if (adapter.isDiscovering()) {
return true;
} else if ((sharedPreferences.getLong(KEY_DISCOVERING_TIMESTAMP, 0) +
}
if ((adapter.getDiscoveryEndMillis() +
GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
return true;
}
}
// If the device was picked in the device picker recently
if (deviceAddress != null) {
@@ -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);
}