Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchControllerExt.kt 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.media.dialog import com.android.settingslib.media.MediaDevice import com.android.systemui.kairos.awaitClose import com.android.systemui.qs.flags.QsDetailedView import com.android.systemui.util.kotlin.getOrNull import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onStart val MediaSwitchingController.currentInputDevice: Flow<MediaDevice?> get() = conflatedCallbackFlow { if (!QsDetailedView.isEnabled) { return@conflatedCallbackFlow } val callback = object : MediaSwitchingController.Callback { override fun onMediaChanged() {} override fun onMediaStoppedOrPaused() {} override fun onRouteChanged() {} override fun onDeviceListChanged() { trySend(mCurrentInputDevice.getOrNull()) } override fun dismissDialog() {} override fun onQuickAccessButtonsChanged() {} } start(callback) awaitClose { stop() } } .onStart { emit(null) } packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java +5 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; Loading Loading @@ -177,6 +178,8 @@ public class MediaSwitchingController private boolean mInAudioSharing = false; @Nullable private Job mAudioShareJob = null; protected Optional<MediaDevice> mCurrentInputDevice; @VisibleForTesting final InputRouteManager.InputDeviceCallback mInputDeviceCallback = new InputRouteManager.InputDeviceCallback() { Loading @@ -184,6 +187,8 @@ public class MediaSwitchingController public void onInputDeviceListUpdated(@NonNull List<MediaDevice> devices) { synchronized (mInputMediaDevicesLock) { buildInputMediaItems(devices); mCurrentInputDevice = devices.stream().filter(MediaDevice::isSelected).findFirst(); mCallback.onDeviceListChanged(); } } Loading packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -713,6 +713,44 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mCb, atLeastOnce()).onDeviceListChanged(); } @Test public void onInputDeviceListUpdate_verifyCurrentInputDevice() { mMediaSwitchingController.start(mCb); assertThat(mMediaSwitchingController.mCurrentInputDevice).isNull(); final MediaDevice mediaDevice3 = InputMediaDevice.create( mContext, TEST_DEVICE_3_ID, "", AudioDeviceInfo.TYPE_BUILTIN_MIC, MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ true, PRODUCT_NAME_BUILTIN_MIC); final MediaDevice mediaDevice4 = InputMediaDevice.create( mContext, TEST_DEVICE_4_ID, "", AudioDeviceInfo.TYPE_WIRED_HEADSET, MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_WIRED_HEADSET); final List<MediaDevice> inputDevices = new ArrayList<>(); inputDevices.add(mediaDevice3); inputDevices.add(mediaDevice4); // Input devices have changed. mMediaSwitchingController.mInputDeviceCallback.onInputDeviceListUpdated(inputDevices); assertThat(mMediaSwitchingController.mCurrentInputDevice.get()).isEqualTo(mediaDevice3); } @Test public void advanced_categorizeMediaItems_withSuggestedDevice_verifyDeviceListSize() { when(mMediaDevice1.isSuggestedDevice()).thenReturn(true); Loading Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchControllerExt.kt 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.media.dialog import com.android.settingslib.media.MediaDevice import com.android.systemui.kairos.awaitClose import com.android.systemui.qs.flags.QsDetailedView import com.android.systemui.util.kotlin.getOrNull import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onStart val MediaSwitchingController.currentInputDevice: Flow<MediaDevice?> get() = conflatedCallbackFlow { if (!QsDetailedView.isEnabled) { return@conflatedCallbackFlow } val callback = object : MediaSwitchingController.Callback { override fun onMediaChanged() {} override fun onMediaStoppedOrPaused() {} override fun onRouteChanged() {} override fun onDeviceListChanged() { trySend(mCurrentInputDevice.getOrNull()) } override fun dismissDialog() {} override fun onQuickAccessButtonsChanged() {} } start(callback) awaitClose { stop() } } .onStart { emit(null) }
packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java +5 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; Loading Loading @@ -177,6 +178,8 @@ public class MediaSwitchingController private boolean mInAudioSharing = false; @Nullable private Job mAudioShareJob = null; protected Optional<MediaDevice> mCurrentInputDevice; @VisibleForTesting final InputRouteManager.InputDeviceCallback mInputDeviceCallback = new InputRouteManager.InputDeviceCallback() { Loading @@ -184,6 +187,8 @@ public class MediaSwitchingController public void onInputDeviceListUpdated(@NonNull List<MediaDevice> devices) { synchronized (mInputMediaDevicesLock) { buildInputMediaItems(devices); mCurrentInputDevice = devices.stream().filter(MediaDevice::isSelected).findFirst(); mCallback.onDeviceListChanged(); } } Loading
packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaSwitchingControllerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -713,6 +713,44 @@ public class MediaSwitchingControllerTest extends SysuiTestCase { verify(mCb, atLeastOnce()).onDeviceListChanged(); } @Test public void onInputDeviceListUpdate_verifyCurrentInputDevice() { mMediaSwitchingController.start(mCb); assertThat(mMediaSwitchingController.mCurrentInputDevice).isNull(); final MediaDevice mediaDevice3 = InputMediaDevice.create( mContext, TEST_DEVICE_3_ID, "", AudioDeviceInfo.TYPE_BUILTIN_MIC, MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ true, PRODUCT_NAME_BUILTIN_MIC); final MediaDevice mediaDevice4 = InputMediaDevice.create( mContext, TEST_DEVICE_4_ID, "", AudioDeviceInfo.TYPE_WIRED_HEADSET, MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_WIRED_HEADSET); final List<MediaDevice> inputDevices = new ArrayList<>(); inputDevices.add(mediaDevice3); inputDevices.add(mediaDevice4); // Input devices have changed. mMediaSwitchingController.mInputDeviceCallback.onInputDeviceListUpdated(inputDevices); assertThat(mMediaSwitchingController.mCurrentInputDevice.get()).isEqualTo(mediaDevice3); } @Test public void advanced_categorizeMediaItems_withSuggestedDevice_verifyDeviceListSize() { when(mMediaDevice1.isSuggestedDevice()).thenReturn(true); Loading