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
This commit is contained in:
@@ -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
|
||||||
|
@@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user