From e54887bd1a481f33816ef4dd3ebbe44c74b35574 Mon Sep 17 00:00:00 2001 From: timhypeng Date: Wed, 27 Feb 2019 15:01:31 +0800 Subject: [PATCH] Add getConnectableDevices() to read A2DP & HearingAid devices on all states Bug: 126475101 Test: make -j50 RunSettingsLibRoboTests Change-Id: I2d93330efc7b7d381f46462f6d020dbe35a9a57b --- .../settingslib/bluetooth/A2dpProfile.java | 41 ++++++++++++++++--- .../bluetooth/HearingAidProfile.java | 41 ++++++++++++++++--- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java index bed3030788058..785dd561d1b7a 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java @@ -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 getConnectedDevices() { - if (mService == null) return new ArrayList(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 getConnectableDevices() { + return getDevicesByStates(new int[] { + BluetoothProfile.STATE_DISCONNECTED, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.STATE_CONNECTING, + BluetoothProfile.STATE_DISCONNECTING}); + } + + private List getDevicesByStates(int[] states) { + if (mService == null) { + return new ArrayList(0); + } + return mService.getDevicesMatchingConnectionStates(states); } public boolean connect(BluetoothDevice device) { diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java index 41c1d60ca551e..ebaeb742b1984 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java @@ -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 getConnectedDevices() { - if (mService == null) return new ArrayList(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 getConnectableDevices() { + return getDevicesByStates(new int[] { + BluetoothProfile.STATE_DISCONNECTED, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.STATE_CONNECTING, + BluetoothProfile.STATE_DISCONNECTING}); + } + + private List getDevicesByStates(int[] states) { + if (mService == null) { + return new ArrayList(0); + } + return mService.getDevicesMatchingConnectionStates(states); } public boolean connect(BluetoothDevice device) {