From 11debff2be2f195f8bdadc8faf3cbdcad046d6e7 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Wed, 5 Feb 2025 15:19:31 +0000 Subject: [PATCH] Hide ambient control when there's no valid control point The preference will be accidentally shown if the device support HAP and VCP. Make sure to hide the preference when the device doesn't have any valid ambient control points. Flag: EXEMPT bugfix Test: manual test with real device Test: atest BluetoothDetailsAmbientVolumePreferenceControllerTest Bug: 388156028 Change-Id: I8162ce8e878baff414e4665c97aaf1c21aa51229 --- ...ailsAmbientVolumePreferenceController.java | 7 ++- ...AmbientVolumePreferenceControllerTest.java | 49 ++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java index defa7e9326d..8dbfedf2f10 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java @@ -129,8 +129,11 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth @Override public boolean isAvailable() { - return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch( - profile -> profile instanceof VolumeControlProfile); + return mCachedDevice.isHearingDevice() + && mCachedDevice.getProfiles().stream().anyMatch( + profile -> profile instanceof VolumeControlProfile) + && mAmbientUiController != null + && mAmbientUiController.isAmbientControlAvailable(); } @Nullable diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java index 4c20a8888bc..a7523efcf96 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java @@ -98,30 +98,44 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends @Test public void isAvailable_notHearingDevice_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(false); + when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); assertThat(mController.isAvailable()).isFalse(); } @Test - public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() { + public void isAvailable_notSupportVcp_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of()); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); assertThat(mController.isAvailable()).isFalse(); } @Test - public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() { + public void isAvailable_noValidAmbientControlPoint_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(false); + + assertThat(mController.isAvailable()).isFalse(); + } + + @Test + public void isAvailable_isHearingDevice_supportVcp_validAmbientControl_returnTrue() { + when(mCachedDevice.isHearingDevice()).thenReturn(true); + when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); assertThat(mController.isAvailable()).isTrue(); } @Test - public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() { - when(mCachedDevice.isHearingDevice()).thenReturn(true); - when(mCachedDevice.getProfiles()).thenReturn(List.of()); + public void refresh_notHearingDevice_verifyUiControllerNotRefresh() { + when(mCachedDevice.isHearingDevice()).thenReturn(false); + when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); mController.refresh(); @@ -129,9 +143,32 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends } @Test - public void refresh_isHearingDeviceAndSupportVcp_verifyUiControllerRefresh() { + public void refresh_notSupportVcp_verifyUiControllerNotRefresh() { + when(mCachedDevice.isHearingDevice()).thenReturn(true); + when(mCachedDevice.getProfiles()).thenReturn(List.of()); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); + + mController.refresh(); + + verify(mUiController, never()).refresh(); + } + + @Test + public void refresh_noValidAmbientControl_verifyUiControllerNotRefresh() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(false); + + mController.refresh(); + + verify(mUiController, never()).refresh(); + } + + @Test + public void refresh_isHearingDevice_supportVcp_validAmbientControl_verifyUiControllerRefresh() { + when(mCachedDevice.isHearingDevice()).thenReturn(true); + when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); + when(mUiController.isAmbientControlAvailable()).thenReturn(true); mController.refresh();