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();