From c509a65541bf0140b5da92ea1b1358f843ba0b89 Mon Sep 17 00:00:00 2001 From: timhypeng Date: Fri, 25 May 2018 14:23:44 +0800 Subject: [PATCH] Add isConnectedHearingAidDevice function to check if it supports Hearing Aid profile Bug: 79553082 Test: make -j50 RunSettingsLibRoboTests Change-Id: I2950f63c4a95d692b77cfffeacc9d1d319243e0d --- .../bluetooth/CachedBluetoothDevice.java | 8 ++++++++ .../bluetooth/CachedBluetoothDeviceTest.java | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 1faca0cb540a0..b80badb155097 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -1205,4 +1205,12 @@ public class CachedBluetoothDevice implements Comparable return mProfileManager.getHeadsetProfile().getConnectionStatus(mDevice) == BluetoothProfile.STATE_CONNECTED; } + + /** + * @return {@code true} if {@code cachedBluetoothDevice} is Hearing Aid device + */ + public boolean isConnectedHearingAidDevice() { + return mProfileManager.getHearingAidProfile().getConnectionStatus(mDevice) == + BluetoothProfile.STATE_CONNECTED; + } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index 927a94f6b0179..9bc47eb210c19 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -572,4 +572,22 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.isHfpDevice()).isFalse(); } + + @Test + public void isConnectedHearingAidDevice_connected_returnTrue() { + when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); + when(mHearingAidProfile.getConnectionStatus(mDevice)). + thenReturn(BluetoothProfile.STATE_CONNECTED); + + assertThat(mCachedDevice.isConnectedHearingAidDevice()).isTrue(); + } + + @Test + public void isConnectedHearingAidDevice_disconnected_returnFalse() { + when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); + when(mHearingAidProfile.getConnectionStatus(mDevice)). + thenReturn(BluetoothProfile.STATE_DISCONNECTED); + + assertThat(mCachedDevice.isConnectedHearingAidDevice()).isFalse(); + } }