From 2bf731033cb00f3cb6868d7ffbf05b59e7589d09 Mon Sep 17 00:00:00 2001 From: jasonwshsu Date: Wed, 20 Mar 2024 13:31:26 +0800 Subject: Implement Hearing Devices Quick Settings Tile (4/n) This patch provides * Show the ordered hearing device list * Handle hearing device item click callback Bug: 291423171 Bug: 319197158 Test: atest com.android.settingslib.bluetoth.BluetoothUtilsTest Test: atest HearingDevicesDialogDelegateTest HearingDevicesListAdapterTest Flag: ACONFIG com.android.systemui.hearing_aids_qs_tile_dialog DEVELOPMENT Change-Id: Ic6b72055f73a7f3eafb6f6ec44fc7ea74dc7e2b3 --- .../settingslib/bluetooth/BluetoothUtils.java | 19 +++ .../settingslib/bluetooth/BluetoothUtilsTest.java | 10 ++ .../res/layout/hearing_devices_tile_dialog.xml | 10 +- .../hearingaid/HearingDevicesDialogDelegate.java | 146 ++++++++++++++++++++- .../hearingaid/HearingDevicesListAdapter.java | 137 +++++++++++++++++++ .../qs/tiles/dialog/bluetooth/DeviceItemFactory.kt | 50 ++++++- .../tiles/dialog/bluetooth/DeviceItemInteractor.kt | 1 - .../HearingDevicesDialogDelegateTest.java | 88 ++++++++++++- .../hearingaid/HearingDevicesListAdapterTest.java | 82 ++++++++++++ 9 files changed, 535 insertions(+), 8 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/accessibility/hearingaid/HearingDevicesListAdapter.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/accessibility/hearingaid/HearingDevicesListAdapterTest.java diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index 09b1eafe4d78..57fcc7462a65 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -541,6 +541,25 @@ public class BluetoothUtils { return isFilterMatched; } + /** + * Checks if the Bluetooth device is an available hearing device, which means: + * 1) currently connected + * 2) is Hearing Aid + * 3) connected profile match hearing aid related profiles (e.g. ASHA, HAP) + * + * @param cachedDevice the CachedBluetoothDevice + * @return if the device is Available hearing device + */ + @WorkerThread + public static boolean isAvailableHearingDevice(CachedBluetoothDevice cachedDevice) { + if (isDeviceConnected(cachedDevice) && cachedDevice.isConnectedHearingAidDevice()) { + Log.d(TAG, "isFilterMatched() device : " + + cachedDevice.getName() + ", the profile is connected."); + return true; + } + return false; + } + /** * Check if the Bluetooth device is a ConnectedBluetoothDevice, which means: * 1) currently connected diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java index 475a6d65a845..1246fd85ee16 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java @@ -430,4 +430,14 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isExclusivelyManagedBluetoothDevice(mContext, mBluetoothDevice)).isEqualTo(true); } + + @Test + public void isAvailableHearingDevice_isConnectedHearingAid_returnTure() { + when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); + when(mBluetoothDevice.isConnected()).thenReturn(true); + + assertThat(BluetoothUtils.isAvailableHearingDevice(mCachedBluetoothDevice)).isEqualTo(true); + } } diff --git a/packages/SystemUI/res/layout/hearing_devices_tile_dialog.xml b/packages/SystemUI/res/layout/hearing_devices_tile_dialog.xml index 8ceda9851314..a5cdaeb2f925 100644 --- a/packages/SystemUI/res/layout/hearing_devices_tile_dialog.xml +++ b/packages/SystemUI/res/layout/hearing_devices_tile_dialog.xml @@ -22,6 +22,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> + +