Loading src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth @Override public boolean isAvailable() { return mCachedDevice.getProfiles().stream().anyMatch( return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch( profile -> profile instanceof VolumeControlProfile); } Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java +27 −15 Original line number Diff line number Diff line Loading @@ -21,15 +21,11 @@ import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceContro import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.os.Handler; import androidx.preference.PreferenceCategory; import com.android.settings.testutils.shadow.ShadowThreadUtils; Loading Loading @@ -70,8 +66,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends @Mock private VolumeControlProfile mVolumeControlProfile; @Mock private Handler mTestHandler; @Mock private AmbientVolumeUiController mUiController; private BluetoothDetailsAmbientVolumePreferenceController mController; Loading @@ -91,13 +85,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends PreferenceCategory deviceControls = new PreferenceCategory(mContext); deviceControls.setKey(KEY_HEARING_DEVICE_GROUP); mScreen.addPreference(deviceControls); when(mContext.getMainThreadHandler()).thenReturn(mTestHandler); when(mTestHandler.postDelayed(any(Runnable.class), anyLong())).thenAnswer( invocationOnMock -> { invocationOnMock.getArgument(0, Runnable.class).run(); return null; }); } @Test Loading @@ -109,7 +96,31 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends } @Test public void refresh_deviceNotSupportVcp_verifyUiControllerNoRefresh() { public void isAvailable_notHearingDevice_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of()); assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); assertThat(mController.isAvailable()).isTrue(); } @Test public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of()); mController.refresh(); Loading @@ -118,7 +129,8 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends } @Test public void refresh_deviceSupportVcp_verifyUiControllerRefresh() { public void refresh_isHearingDeviceAndSupportVcp_verifyUiControllerRefresh() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); mController.refresh(); Loading Loading
src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth @Override public boolean isAvailable() { return mCachedDevice.getProfiles().stream().anyMatch( return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch( profile -> profile instanceof VolumeControlProfile); } Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAmbientVolumePreferenceControllerTest.java +27 −15 Original line number Diff line number Diff line Loading @@ -21,15 +21,11 @@ import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceContro import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.os.Handler; import androidx.preference.PreferenceCategory; import com.android.settings.testutils.shadow.ShadowThreadUtils; Loading Loading @@ -70,8 +66,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends @Mock private VolumeControlProfile mVolumeControlProfile; @Mock private Handler mTestHandler; @Mock private AmbientVolumeUiController mUiController; private BluetoothDetailsAmbientVolumePreferenceController mController; Loading @@ -91,13 +85,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends PreferenceCategory deviceControls = new PreferenceCategory(mContext); deviceControls.setKey(KEY_HEARING_DEVICE_GROUP); mScreen.addPreference(deviceControls); when(mContext.getMainThreadHandler()).thenReturn(mTestHandler); when(mTestHandler.postDelayed(any(Runnable.class), anyLong())).thenAnswer( invocationOnMock -> { invocationOnMock.getArgument(0, Runnable.class).run(); return null; }); } @Test Loading @@ -109,7 +96,31 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends } @Test public void refresh_deviceNotSupportVcp_verifyUiControllerNoRefresh() { public void isAvailable_notHearingDevice_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of()); assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); assertThat(mController.isAvailable()).isTrue(); } @Test public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of()); mController.refresh(); Loading @@ -118,7 +129,8 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends } @Test public void refresh_deviceSupportVcp_verifyUiControllerRefresh() { public void refresh_isHearingDeviceAndSupportVcp_verifyUiControllerRefresh() { when(mCachedDevice.isHearingDevice()).thenReturn(true); when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); mController.refresh(); Loading