diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java index 3023dafb770..fa0c2c3c64c 100644 --- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java +++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java @@ -128,13 +128,11 @@ class BluetoothEventRedirector { mManager.getCachedDeviceManager().onProfileStateChanged(device, Profile.A2DP, newState); - } else if (action.equals(BluetoothInputDevice.ACTION_INPUT_DEVICE_STATE_CHANGED)) { - final int newState = intent.getIntExtra( - BluetoothInputDevice.EXTRA_INPUT_DEVICE_STATE, 0); - final int oldState = intent.getIntExtra( - BluetoothInputDevice.EXTRA_PREVIOUS_INPUT_DEVICE_STATE, 0); - if (newState == BluetoothInputDevice.STATE_DISCONNECTED && - oldState == BluetoothInputDevice.STATE_CONNECTING) { + } else if (action.equals(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED)) { + final int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); + final int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0); + if (newState == BluetoothProfile.STATE_DISCONNECTED && + oldState == BluetoothProfile.STATE_CONNECTING) { Log.i(TAG, "Failed to connect BT HID"); } @@ -202,7 +200,7 @@ class BluetoothEventRedirector { // Fine-grained state broadcasts filter.addAction(BluetoothPan.ACTION_PAN_STATE_CHANGED); - filter.addAction(BluetoothInputDevice.ACTION_INPUT_DEVICE_STATE_CHANGED); + filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_CLASS_CHANGED); diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index de15dcc50fa..889cb8ae3f9 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -639,29 +639,39 @@ abstract class LocalBluetoothProfileManager { } } - private static class HidProfileManager extends LocalBluetoothProfileManager { - private final BluetoothInputDevice mService; + private static class HidProfileManager extends LocalBluetoothProfileManager + implements BluetoothProfile.ServiceListener { + private BluetoothInputDevice mService; public HidProfileManager(LocalBluetoothManager localManager) { super(localManager); - mService = new BluetoothInputDevice(localManager.getContext()); + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + adapter.getProfileProxy(localManager.getContext(), this, BluetoothProfile.INPUT_DEVICE); + } + + public void onServiceConnected(int profile, BluetoothProfile proxy) { + mService = (BluetoothInputDevice) proxy; + } + + public void onServiceDisconnected(int profile) { + mService = null; } @Override public boolean connect(BluetoothDevice device) { - return mService.connectInputDevice(device); + return mService.connect(device); } @Override public int convertState(int hidState) { switch (hidState) { - case BluetoothInputDevice.STATE_CONNECTED: + case BluetoothProfile.STATE_CONNECTED: return SettingsBtStatus.CONNECTION_STATUS_CONNECTED; - case BluetoothInputDevice.STATE_CONNECTING: + case BluetoothProfile.STATE_CONNECTING: return SettingsBtStatus.CONNECTION_STATUS_CONNECTING; - case BluetoothInputDevice.STATE_DISCONNECTED: + case BluetoothProfile.STATE_DISCONNECTED: return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED; - case BluetoothInputDevice.STATE_DISCONNECTING: + case BluetoothProfile.STATE_DISCONNECTING: return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTING; default: return SettingsBtStatus.CONNECTION_STATUS_UNKNOWN; @@ -670,22 +680,22 @@ abstract class LocalBluetoothProfileManager { @Override public boolean disconnect(BluetoothDevice device) { - return mService.disconnectInputDevice(device); + return mService.disconnect(device); } @Override public List getConnectedDevices() { - return mService.getConnectedInputDevices(); + return mService.getConnectedDevices(); } @Override public int getConnectionStatus(BluetoothDevice device) { - return convertState(mService.getInputDeviceState(device)); + return convertState(mService.getConnectionState(device)); } @Override public int getPreferred(BluetoothDevice device) { - return mService.getInputDevicePriority(device); + return mService.getPriority(device); } @Override @@ -701,7 +711,7 @@ abstract class LocalBluetoothProfileManager { @Override public boolean isPreferred(BluetoothDevice device) { - return mService.getInputDevicePriority(device) > BluetoothInputDevice.PRIORITY_OFF; + return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF; } @Override @@ -712,11 +722,11 @@ abstract class LocalBluetoothProfileManager { @Override public void setPreferred(BluetoothDevice device, boolean preferred) { if (preferred) { - if (mService.getInputDevicePriority(device) < BluetoothInputDevice.PRIORITY_ON) { - mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_ON); + if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) { + mService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } else { - mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_OFF); + mService.setPriority(device, BluetoothProfile.PRIORITY_OFF); } }