Add getConnectableDevices() to read A2DP & HearingAid devices on all states

Bug: 126475101
Test: make -j50 RunSettingsLibRoboTests
Change-Id: I2d93330efc7b7d381f46462f6d020dbe35a9a57b
This commit is contained in:
timhypeng
2019-02-27 15:01:31 +08:00
parent 367763b99c
commit e54887bd1a
2 changed files with 72 additions and 10 deletions

View File

@@ -108,12 +108,43 @@ public class A2dpProfile implements LocalBluetoothProfile {
return true;
}
/**
* Get A2dp devices matching connection states{
* @code BluetoothProfile.STATE_CONNECTED,
* @code BluetoothProfile.STATE_CONNECTING,
* @code BluetoothProfile.STATE_DISCONNECTING}
*
* @return Matching device list
*/
public List<BluetoothDevice> getConnectedDevices() {
if (mService == null) return new ArrayList<BluetoothDevice>(0);
return mService.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
return getDevicesByStates(new int[] {
BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
}
/**
* Get A2dp devices matching connection states{
* @code BluetoothProfile.STATE_DISCONNECTED,
* @code BluetoothProfile.STATE_CONNECTED,
* @code BluetoothProfile.STATE_CONNECTING,
* @code BluetoothProfile.STATE_DISCONNECTING}
*
* @return Matching device list
*/
public List<BluetoothDevice> getConnectableDevices() {
return getDevicesByStates(new int[] {
BluetoothProfile.STATE_DISCONNECTED,
BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
}
private List<BluetoothDevice> getDevicesByStates(int[] states) {
if (mService == null) {
return new ArrayList<BluetoothDevice>(0);
}
return mService.getDevicesMatchingConnectionStates(states);
}
public boolean connect(BluetoothDevice device) {

View File

@@ -106,12 +106,43 @@ public class HearingAidProfile implements LocalBluetoothProfile {
return true;
}
/**
* Get Hearing Aid devices matching connection states{
* @code BluetoothProfile.STATE_CONNECTED,
* @code BluetoothProfile.STATE_CONNECTING,
* @code BluetoothProfile.STATE_DISCONNECTING}
*
* @return Matching device list
*/
public List<BluetoothDevice> getConnectedDevices() {
if (mService == null) return new ArrayList<BluetoothDevice>(0);
return mService.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
return getDevicesByStates(new int[] {
BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
}
/**
* Get Hearing Aid devices matching connection states{
* @code BluetoothProfile.STATE_DISCONNECTED,
* @code BluetoothProfile.STATE_CONNECTED,
* @code BluetoothProfile.STATE_CONNECTING,
* @code BluetoothProfile.STATE_DISCONNECTING}
*
* @return Matching device list
*/
public List<BluetoothDevice> getConnectableDevices() {
return getDevicesByStates(new int[] {
BluetoothProfile.STATE_DISCONNECTED,
BluetoothProfile.STATE_CONNECTED,
BluetoothProfile.STATE_CONNECTING,
BluetoothProfile.STATE_DISCONNECTING});
}
private List<BluetoothDevice> getDevicesByStates(int[] states) {
if (mService == null) {
return new ArrayList<BluetoothDevice>(0);
}
return mService.getDevicesMatchingConnectionStates(states);
}
public boolean connect(BluetoothDevice device) {