Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/AmbientVolumeUiController.java +13 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ public class AmbientVolumeUiController implements private final Set<Integer> mRangeInitializedSliderSides = new ArraySet<>(); private CachedBluetoothDevice mCachedDevice; private boolean mShowUiWhenLocalDataExist = true; private boolean mStarted = false; public AmbientVolumeUiController(@NonNull Context context, @NonNull LocalBluetoothManager bluetoothManager, Loading @@ -82,7 +83,6 @@ public class AmbientVolumeUiController implements mLocalDataManager = new HearingDeviceLocalDataManager(context); mLocalDataManager.setOnDeviceLocalDataChangeListener(this, ThreadUtils.getBackgroundExecutor()); mLocalDataManager.start(); } @VisibleForTesting Loading Loading @@ -278,6 +278,10 @@ public class AmbientVolumeUiController implements * events. */ public void start() { if (mStarted) { return; } mStarted = true; mEventManager.registerCallback(this); mLocalDataManager.start(); mCachedDevices.forEach(device -> { Loading @@ -285,6 +289,7 @@ public class AmbientVolumeUiController implements mVolumeController.registerCallback(ThreadUtils.getBackgroundExecutor(), device.getDevice()); }); postOnMainThread(this::refresh); } /** Loading @@ -292,6 +297,10 @@ public class AmbientVolumeUiController implements * events. */ public void stop() { if (!mStarted) { return; } mStarted = false; mEventManager.unregisterCallback(this); mLocalDataManager.stop(); mCachedDevices.forEach(device -> { Loading Loading @@ -337,8 +346,10 @@ public class AmbientVolumeUiController implements mAmbientLayout.setControlExpandable(mSideToDeviceMap.size() > 1); mAmbientLayout.setupSliders(mSideToDeviceMap); if (mStarted) { refresh(); } } /** Refreshes the ambient volume UI. */ public void refresh() { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/AmbientVolumeUiControllerTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -157,21 +157,23 @@ public class AmbientVolumeUiControllerTest { } @Test public void loadDevice_ambientControlNotAvailable_ambientLayoutGone() { public void refresh_ambientControlNotAvailable_ambientLayoutGone() { when(mVolumeController.isAmbientControlAvailable(mDevice)).thenReturn(false); when(mVolumeController.isAmbientControlAvailable(mMemberDevice)).thenReturn(false); mController.loadDevice(mCachedDevice); mController.refresh(); verify(mAmbientLayout).setVisible(false); } @Test public void loadDevice_supportVcpAndAmbientControlAvailable_ambientLayoutVisible() { public void refresh_supportVcpAndAmbientControlAvailable_ambientLayoutVisible() { when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); when(mVolumeController.isAmbientControlAvailable(mDevice)).thenReturn(true); mController.loadDevice(mCachedDevice); mController.refresh(); verify(mAmbientLayout).setVisible(true); } Loading @@ -188,10 +190,12 @@ public class AmbientVolumeUiControllerTest { any(CachedBluetoothDevice.Callback.class)); verify(mCachedMemberDevice).registerCallback(any(Executor.class), any(CachedBluetoothDevice.Callback.class)); verify(mController).refresh(); } @Test public void stop_callbackUnregistered() { mController.start(); mController.stop(); verify(mEventManager).unregisterCallback(mController); Loading packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/hearingaid/HearingDevicesDialogDelegateTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -158,9 +158,11 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { private SystemUIDialog mDialog; private SystemUIDialog.Factory mDialogFactory; private HearingDevicesDialogDelegate mDialogDelegate; private TestableLooper mTestableLooper; @Before public void setUp() { mTestableLooper = TestableLooper.get(this); when(mLocalBluetoothManager.getBluetoothAdapter()).thenReturn(mLocalBluetoothAdapter); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager); when(mProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile); Loading Loading @@ -195,8 +197,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { @Test public void clickPairNewDeviceButton_intentActionMatch() { setUpDeviceDialogWithPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); getPairNewDeviceButton(mDialog).performClick(); Loading Loading @@ -244,8 +245,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { R.array.config_quickSettingsHearingDevicesRelatedToolName, new String[]{}); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(0); } Loading @@ -259,8 +259,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { R.array.config_quickSettingsHearingDevicesRelatedToolName, new String[]{}); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(1); } Loading @@ -281,8 +280,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mDrawable.mutate()).thenReturn(mDrawable); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(2); } Loading @@ -293,8 +291,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(PRESET_INDEX_UNAVAILABLE); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup presetLayout = getPresetLayout(mDialog); assertThat(presetLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -307,8 +304,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup presetLayout = getPresetLayout(mDialog); assertThat(presetLayout.getVisibility()).isEqualTo(View.VISIBLE); Loading @@ -322,8 +318,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mCachedDevice.getProfiles()).thenReturn(List.of()); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -335,8 +330,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mVolumeControlProfile.getAudioInputControlServices(mDevice)).thenReturn(List.of()); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -352,8 +346,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mVolumeControlProfile.getConnectionStatus(mDevice)).thenReturn(STATE_CONNECTED); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.VISIBLE); Loading @@ -362,8 +355,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { @Test public void onActiveDeviceChanged_presetExist_presetSelected() { setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); BluetoothHapPresetInfo info = getTestPresetInfo(); when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info)); when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX); Loading Loading @@ -473,6 +465,12 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { return audioInputControl; } private void showDialogAndProcessAllTasks() { mDialog.show(); mExecutor.runAllReady(); mTestableLooper.processAllMessages(); } @After public void reset() { if (mDialogDelegate != null) { Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/AmbientVolumeUiController.java +13 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ public class AmbientVolumeUiController implements private final Set<Integer> mRangeInitializedSliderSides = new ArraySet<>(); private CachedBluetoothDevice mCachedDevice; private boolean mShowUiWhenLocalDataExist = true; private boolean mStarted = false; public AmbientVolumeUiController(@NonNull Context context, @NonNull LocalBluetoothManager bluetoothManager, Loading @@ -82,7 +83,6 @@ public class AmbientVolumeUiController implements mLocalDataManager = new HearingDeviceLocalDataManager(context); mLocalDataManager.setOnDeviceLocalDataChangeListener(this, ThreadUtils.getBackgroundExecutor()); mLocalDataManager.start(); } @VisibleForTesting Loading Loading @@ -278,6 +278,10 @@ public class AmbientVolumeUiController implements * events. */ public void start() { if (mStarted) { return; } mStarted = true; mEventManager.registerCallback(this); mLocalDataManager.start(); mCachedDevices.forEach(device -> { Loading @@ -285,6 +289,7 @@ public class AmbientVolumeUiController implements mVolumeController.registerCallback(ThreadUtils.getBackgroundExecutor(), device.getDevice()); }); postOnMainThread(this::refresh); } /** Loading @@ -292,6 +297,10 @@ public class AmbientVolumeUiController implements * events. */ public void stop() { if (!mStarted) { return; } mStarted = false; mEventManager.unregisterCallback(this); mLocalDataManager.stop(); mCachedDevices.forEach(device -> { Loading Loading @@ -337,8 +346,10 @@ public class AmbientVolumeUiController implements mAmbientLayout.setControlExpandable(mSideToDeviceMap.size() > 1); mAmbientLayout.setupSliders(mSideToDeviceMap); if (mStarted) { refresh(); } } /** Refreshes the ambient volume UI. */ public void refresh() { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/AmbientVolumeUiControllerTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -157,21 +157,23 @@ public class AmbientVolumeUiControllerTest { } @Test public void loadDevice_ambientControlNotAvailable_ambientLayoutGone() { public void refresh_ambientControlNotAvailable_ambientLayoutGone() { when(mVolumeController.isAmbientControlAvailable(mDevice)).thenReturn(false); when(mVolumeController.isAmbientControlAvailable(mMemberDevice)).thenReturn(false); mController.loadDevice(mCachedDevice); mController.refresh(); verify(mAmbientLayout).setVisible(false); } @Test public void loadDevice_supportVcpAndAmbientControlAvailable_ambientLayoutVisible() { public void refresh_supportVcpAndAmbientControlAvailable_ambientLayoutVisible() { when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile)); when(mVolumeController.isAmbientControlAvailable(mDevice)).thenReturn(true); mController.loadDevice(mCachedDevice); mController.refresh(); verify(mAmbientLayout).setVisible(true); } Loading @@ -188,10 +190,12 @@ public class AmbientVolumeUiControllerTest { any(CachedBluetoothDevice.Callback.class)); verify(mCachedMemberDevice).registerCallback(any(Executor.class), any(CachedBluetoothDevice.Callback.class)); verify(mController).refresh(); } @Test public void stop_callbackUnregistered() { mController.start(); mController.stop(); verify(mEventManager).unregisterCallback(mController); Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/hearingaid/HearingDevicesDialogDelegateTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -158,9 +158,11 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { private SystemUIDialog mDialog; private SystemUIDialog.Factory mDialogFactory; private HearingDevicesDialogDelegate mDialogDelegate; private TestableLooper mTestableLooper; @Before public void setUp() { mTestableLooper = TestableLooper.get(this); when(mLocalBluetoothManager.getBluetoothAdapter()).thenReturn(mLocalBluetoothAdapter); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager); when(mProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile); Loading Loading @@ -195,8 +197,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { @Test public void clickPairNewDeviceButton_intentActionMatch() { setUpDeviceDialogWithPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); getPairNewDeviceButton(mDialog).performClick(); Loading Loading @@ -244,8 +245,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { R.array.config_quickSettingsHearingDevicesRelatedToolName, new String[]{}); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(0); } Loading @@ -259,8 +259,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { R.array.config_quickSettingsHearingDevicesRelatedToolName, new String[]{}); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(1); } Loading @@ -281,8 +280,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mDrawable.mutate()).thenReturn(mDrawable); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); assertToolsUi(2); } Loading @@ -293,8 +291,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(PRESET_INDEX_UNAVAILABLE); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup presetLayout = getPresetLayout(mDialog); assertThat(presetLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -307,8 +304,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup presetLayout = getPresetLayout(mDialog); assertThat(presetLayout.getVisibility()).isEqualTo(View.VISIBLE); Loading @@ -322,8 +318,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mCachedDevice.getProfiles()).thenReturn(List.of()); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -335,8 +330,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mVolumeControlProfile.getAudioInputControlServices(mDevice)).thenReturn(List.of()); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.GONE); Loading @@ -352,8 +346,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { when(mVolumeControlProfile.getConnectionStatus(mDevice)).thenReturn(STATE_CONNECTED); setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); ViewGroup ambientLayout = getAmbientLayout(mDialog); assertThat(ambientLayout.getVisibility()).isEqualTo(View.VISIBLE); Loading @@ -362,8 +355,7 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { @Test public void onActiveDeviceChanged_presetExist_presetSelected() { setUpDeviceDialogWithoutPairNewDeviceButton(); mDialog.show(); mExecutor.runAllReady(); showDialogAndProcessAllTasks(); BluetoothHapPresetInfo info = getTestPresetInfo(); when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info)); when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX); Loading Loading @@ -473,6 +465,12 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase { return audioInputControl; } private void showDialogAndProcessAllTasks() { mDialog.show(); mExecutor.runAllReady(); mTestableLooper.processAllMessages(); } @After public void reset() { if (mDialogDelegate != null) { Loading