summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth/DockService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/bluetooth/DockService.java')
-rw-r--r--src/com/android/settings/bluetooth/DockService.java68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java
index c9a18a3..c4f6485 100644
--- a/src/com/android/settings/bluetooth/DockService.java
+++ b/src/com/android/settings/bluetooth/DockService.java
@@ -16,9 +16,6 @@
package com.android.settings.bluetooth;
-import com.android.settings.R;
-import com.android.settings.bluetooth.LocalBluetoothProfileManager.ServiceListener;
-
import android.app.AlertDialog;
import android.app.Notification;
import android.app.Service;
@@ -27,6 +24,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
@@ -44,6 +42,16 @@ import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
+import com.android.settings.R;
+import com.android.settingslib.bluetooth.BluetoothCallback;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfile;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
+import com.android.settingslib.bluetooth.LocalBluetoothProfileManager.ServiceListener;
+
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -126,7 +134,7 @@ public final class DockService extends Service implements ServiceListener {
public void onCreate() {
if (DEBUG) Log.d(TAG, "onCreate");
- LocalBluetoothManager manager = LocalBluetoothManager.getInstance(this);
+ LocalBluetoothManager manager = Utils.getLocalBtManager(this);
if (manager == null) {
Log.e(TAG, "Can't get LocalBluetoothManager: exiting");
return;
@@ -918,4 +926,56 @@ public final class DockService extends Service implements ServiceListener {
public void onServiceDisconnected() {
// FIXME: shouldn't I do something on service disconnected too?
}
+
+ public static class DockBluetoothCallback implements BluetoothCallback {
+ private final Context mContext;
+
+ public DockBluetoothCallback(Context context) {
+ mContext = context;
+ }
+
+ public void onBluetoothStateChanged(int bluetoothState) { }
+ public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { }
+ public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { }
+
+ @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);
+ }
+
+ @Override
+ public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+ BluetoothDevice device = cachedDevice.getDevice();
+ if (bondState == BluetoothDevice.BOND_NONE) {
+ if (device.isBluetoothDock()) {
+ // After a dock is unpaired, we will forget the settings
+ LocalBluetoothPreferences
+ .removeDockAutoConnectSetting(mContext, device.getAddress());
+
+ // if the device is undocked, remove it from the list as well
+ if (!device.getAddress().equals(getDockedDeviceAddress(mContext))) {
+ cachedDevice.setVisible(false);
+ }
+ }
+ }
+ }
+
+ // This can't be called from a broadcast receiver where the filter is set in the Manifest.
+ private static String getDockedDeviceAddress(Context context) {
+ // This works only because these broadcast intents are "sticky"
+ Intent i = context.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
+ if (i != null) {
+ int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
+ if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
+ BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (device != null) {
+ return device.getAddress();
+ }
+ }
+ }
+ return null;
+ }
+ }
}