Move isolatable bluetooth code to SettingsLib

Move the non-ui bluetooth control/tracking code to SettingsLib so
that it can be shared with others.

Mostly just move classes to frameworks/base/packages/SettingsLib,
however a few things had to move around.
 - Dock handling had to move back to code still in settings
 - Local preference related code had to be moved back to settings
 - Added an error flow from SettingsLib to Settings

Depends on I69fd888362c6dbb325f6113b32c4b15cc6a23a41
Bug: 19180466
Change-Id: Ie57fe26a27bbb0adc2ef69e042a05c7290c6a52a
This commit is contained in:
Jason Monk
2015-02-04 10:24:29 -05:00
parent fc1b00cfe4
commit f2982a9ba1
70 changed files with 163 additions and 3882 deletions

View File

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