Merge "Hide ambient control when there's no valid control point" into main

This commit is contained in:
Angela Wang
2025-02-06 09:17:37 -08:00
committed by Android (Google) Code Review
2 changed files with 48 additions and 8 deletions

View File

@@ -129,8 +129,11 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch( return mCachedDevice.isHearingDevice()
profile -> profile instanceof VolumeControlProfile); && mCachedDevice.getProfiles().stream().anyMatch(
profile -> profile instanceof VolumeControlProfile)
&& mAmbientUiController != null
&& mAmbientUiController.isAmbientControlAvailable();
} }
@Nullable @Nullable

View File

@@ -98,30 +98,44 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
@Test @Test
public void isAvailable_notHearingDevice_returnFalse() { public void isAvailable_notHearingDevice_returnFalse() {
when(mCachedDevice.isHearingDevice()).thenReturn(false); when(mCachedDevice.isHearingDevice()).thenReturn(false);
when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));
when(mUiController.isAmbientControlAvailable()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() { public void isAvailable_notSupportVcp_returnFalse() {
when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.isHearingDevice()).thenReturn(true);
when(mCachedDevice.getProfiles()).thenReturn(List.of()); when(mCachedDevice.getProfiles()).thenReturn(List.of());
when(mUiController.isAmbientControlAvailable()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() { public void isAvailable_noValidAmbientControlPoint_returnFalse() {
when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.isHearingDevice()).thenReturn(true);
when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); 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(); assertThat(mController.isAvailable()).isTrue();
} }
@Test @Test
public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() { public void refresh_notHearingDevice_verifyUiControllerNotRefresh() {
when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.isHearingDevice()).thenReturn(false);
when(mCachedDevice.getProfiles()).thenReturn(List.of()); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));
when(mUiController.isAmbientControlAvailable()).thenReturn(true);
mController.refresh(); mController.refresh();
@@ -129,9 +143,32 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
} }
@Test @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.isHearingDevice()).thenReturn(true);
when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); 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(); mController.refresh();