Update code for making BluetoothInputProfile implement BluetoothProfile.

Change-Id: Ib04abc590429eaa40c0ea1bd24fa728d41306fe8
This commit is contained in:
Jaikumar Ganesh
2011-02-18 14:51:23 -08:00
parent 0ba170c979
commit 77bcd7e807
2 changed files with 32 additions and 24 deletions

View File

@@ -128,13 +128,11 @@ class BluetoothEventRedirector {
mManager.getCachedDeviceManager().onProfileStateChanged(device, mManager.getCachedDeviceManager().onProfileStateChanged(device,
Profile.A2DP, newState); Profile.A2DP, newState);
} else if (action.equals(BluetoothInputDevice.ACTION_INPUT_DEVICE_STATE_CHANGED)) { } else if (action.equals(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED)) {
final int newState = intent.getIntExtra( final int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0);
BluetoothInputDevice.EXTRA_INPUT_DEVICE_STATE, 0); final int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
final int oldState = intent.getIntExtra( if (newState == BluetoothProfile.STATE_DISCONNECTED &&
BluetoothInputDevice.EXTRA_PREVIOUS_INPUT_DEVICE_STATE, 0); oldState == BluetoothProfile.STATE_CONNECTING) {
if (newState == BluetoothInputDevice.STATE_DISCONNECTED &&
oldState == BluetoothInputDevice.STATE_CONNECTING) {
Log.i(TAG, "Failed to connect BT HID"); Log.i(TAG, "Failed to connect BT HID");
} }
@@ -202,7 +200,7 @@ class BluetoothEventRedirector {
// Fine-grained state broadcasts // Fine-grained state broadcasts
filter.addAction(BluetoothPan.ACTION_PAN_STATE_CHANGED); 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(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_CLASS_CHANGED); filter.addAction(BluetoothDevice.ACTION_CLASS_CHANGED);

View File

@@ -639,29 +639,39 @@ abstract class LocalBluetoothProfileManager {
} }
} }
private static class HidProfileManager extends LocalBluetoothProfileManager { private static class HidProfileManager extends LocalBluetoothProfileManager
private final BluetoothInputDevice mService; implements BluetoothProfile.ServiceListener {
private BluetoothInputDevice mService;
public HidProfileManager(LocalBluetoothManager localManager) { public HidProfileManager(LocalBluetoothManager localManager) {
super(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 @Override
public boolean connect(BluetoothDevice device) { public boolean connect(BluetoothDevice device) {
return mService.connectInputDevice(device); return mService.connect(device);
} }
@Override @Override
public int convertState(int hidState) { public int convertState(int hidState) {
switch (hidState) { switch (hidState) {
case BluetoothInputDevice.STATE_CONNECTED: case BluetoothProfile.STATE_CONNECTED:
return SettingsBtStatus.CONNECTION_STATUS_CONNECTED; return SettingsBtStatus.CONNECTION_STATUS_CONNECTED;
case BluetoothInputDevice.STATE_CONNECTING: case BluetoothProfile.STATE_CONNECTING:
return SettingsBtStatus.CONNECTION_STATUS_CONNECTING; return SettingsBtStatus.CONNECTION_STATUS_CONNECTING;
case BluetoothInputDevice.STATE_DISCONNECTED: case BluetoothProfile.STATE_DISCONNECTED:
return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED; return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED;
case BluetoothInputDevice.STATE_DISCONNECTING: case BluetoothProfile.STATE_DISCONNECTING:
return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTING; return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTING;
default: default:
return SettingsBtStatus.CONNECTION_STATUS_UNKNOWN; return SettingsBtStatus.CONNECTION_STATUS_UNKNOWN;
@@ -670,22 +680,22 @@ abstract class LocalBluetoothProfileManager {
@Override @Override
public boolean disconnect(BluetoothDevice device) { public boolean disconnect(BluetoothDevice device) {
return mService.disconnectInputDevice(device); return mService.disconnect(device);
} }
@Override @Override
public List<BluetoothDevice> getConnectedDevices() { public List<BluetoothDevice> getConnectedDevices() {
return mService.getConnectedInputDevices(); return mService.getConnectedDevices();
} }
@Override @Override
public int getConnectionStatus(BluetoothDevice device) { public int getConnectionStatus(BluetoothDevice device) {
return convertState(mService.getInputDeviceState(device)); return convertState(mService.getConnectionState(device));
} }
@Override @Override
public int getPreferred(BluetoothDevice device) { public int getPreferred(BluetoothDevice device) {
return mService.getInputDevicePriority(device); return mService.getPriority(device);
} }
@Override @Override
@@ -701,7 +711,7 @@ abstract class LocalBluetoothProfileManager {
@Override @Override
public boolean isPreferred(BluetoothDevice device) { public boolean isPreferred(BluetoothDevice device) {
return mService.getInputDevicePriority(device) > BluetoothInputDevice.PRIORITY_OFF; return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
} }
@Override @Override
@@ -712,11 +722,11 @@ abstract class LocalBluetoothProfileManager {
@Override @Override
public void setPreferred(BluetoothDevice device, boolean preferred) { public void setPreferred(BluetoothDevice device, boolean preferred) {
if (preferred) { if (preferred) {
if (mService.getInputDevicePriority(device) < BluetoothInputDevice.PRIORITY_ON) { if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_ON); mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
} }
} else { } else {
mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_OFF); mService.setPriority(device, BluetoothProfile.PRIORITY_OFF);
} }
} }