summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Shenqiu Zhang <shenqiuz@google.com> 2025-03-06 17:11:31 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-06 17:11:31 -0800
commit992914b9675e169d1b9810f8be74b83351ba7f97 (patch)
treed9dda8843b5b6ae759f5844fa6ee2df19f3ed1c3
parentaddf0e8fb0eea308f0263f2a43bb4f92044038e1 (diff)
parentf38da776a282e4f74c54727c5621071732bc9c6d (diff)
Merge "Refactor the OutputMediaItemList to a proxy class" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java65
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/dialog/OutputMediaItemListProxy.java55
2 files changed, 95 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java
index 9e6fa48d6f98..f79693138e24 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java
@@ -145,7 +145,7 @@ public class MediaSwitchingController
@VisibleForTesting
final List<MediaDevice> mGroupMediaDevices = new CopyOnWriteArrayList<>();
final List<MediaDevice> mCachedMediaDevices = new CopyOnWriteArrayList<>();
- private final List<MediaItem> mOutputMediaItemList = new CopyOnWriteArrayList<>();
+ private final OutputMediaItemListProxy mOutputMediaItemListProxy;
private final List<MediaItem> mInputMediaItemList = new CopyOnWriteArrayList<>();
private final AudioManager mAudioManager;
private final PowerExemptionManager mPowerExemptionManager;
@@ -226,6 +226,7 @@ public class MediaSwitchingController
InfoMediaManager.createInstance(mContext, packageName, userHandle, lbm, token);
mLocalMediaManager = new LocalMediaManager(mContext, lbm, imm, packageName);
mMetricLogger = new MediaOutputMetricLogger(mContext, mPackageName);
+ mOutputMediaItemListProxy = new OutputMediaItemListProxy();
mDialogTransitionAnimator = dialogTransitionAnimator;
mNearbyMediaDevicesManager = nearbyMediaDevicesManager;
mMediaOutputColorSchemeLegacy = MediaOutputColorSchemeLegacy.fromSystemColors(mContext);
@@ -245,7 +246,7 @@ public class MediaSwitchingController
protected void start(@NonNull Callback cb) {
synchronized (mMediaDevicesLock) {
mCachedMediaDevices.clear();
- mOutputMediaItemList.clear();
+ mOutputMediaItemListProxy.clear();
}
mNearbyDeviceInfoMap.clear();
if (mNearbyMediaDevicesManager != null) {
@@ -291,7 +292,7 @@ public class MediaSwitchingController
mLocalMediaManager.stopScan();
synchronized (mMediaDevicesLock) {
mCachedMediaDevices.clear();
- mOutputMediaItemList.clear();
+ mOutputMediaItemListProxy.clear();
}
if (mNearbyMediaDevicesManager != null) {
mNearbyMediaDevicesManager.unregisterNearbyDevicesCallback(this);
@@ -333,7 +334,7 @@ public class MediaSwitchingController
@Override
public void onDeviceListUpdate(List<MediaDevice> devices) {
- boolean isListEmpty = mOutputMediaItemList.isEmpty();
+ boolean isListEmpty = mOutputMediaItemListProxy.isEmpty();
if (isListEmpty || !mIsRefreshing) {
buildMediaItems(devices);
mCallback.onDeviceListChanged();
@@ -347,11 +348,12 @@ public class MediaSwitchingController
}
@Override
- public void onSelectedDeviceStateChanged(MediaDevice device,
- @LocalMediaManager.MediaDeviceState int state) {
+ public void onSelectedDeviceStateChanged(
+ MediaDevice device, @LocalMediaManager.MediaDeviceState int state) {
mCallback.onRouteChanged();
mMetricLogger.logOutputItemSuccess(
- device.toString(), new ArrayList<>(mOutputMediaItemList));
+ device.toString(),
+ new ArrayList<>(mOutputMediaItemListProxy.getOutputMediaItemList()));
}
@Override
@@ -362,7 +364,8 @@ public class MediaSwitchingController
@Override
public void onRequestFailed(int reason) {
mCallback.onRouteChanged();
- mMetricLogger.logOutputItemFailure(new ArrayList<>(mOutputMediaItemList), reason);
+ mMetricLogger.logOutputItemFailure(
+ new ArrayList<>(mOutputMediaItemListProxy.getOutputMediaItemList()), reason);
}
/**
@@ -381,7 +384,7 @@ public class MediaSwitchingController
}
try {
synchronized (mMediaDevicesLock) {
- mOutputMediaItemList.removeIf((MediaItem::isMutingExpectedDevice));
+ mOutputMediaItemListProxy.removeMutingExpectedDevices();
}
mAudioManager.cancelMuteAwaitConnection(mAudioManager.getMutingExpectedDevice());
} catch (Exception e) {
@@ -574,14 +577,14 @@ public class MediaSwitchingController
private void buildMediaItems(List<MediaDevice> devices) {
synchronized (mMediaDevicesLock) {
- List<MediaItem> updatedMediaItems = buildMediaItems(mOutputMediaItemList, devices);
- mOutputMediaItemList.clear();
- mOutputMediaItemList.addAll(updatedMediaItems);
+ List<MediaItem> updatedMediaItems =
+ buildMediaItems(mOutputMediaItemListProxy.getOutputMediaItemList(), devices);
+ mOutputMediaItemListProxy.clearAndAddAll(updatedMediaItems);
}
}
- protected List<MediaItem> buildMediaItems(List<MediaItem> oldMediaItems,
- List<MediaDevice> devices) {
+ protected List<MediaItem> buildMediaItems(
+ List<MediaItem> oldMediaItems, List<MediaDevice> devices) {
synchronized (mMediaDevicesLock) {
if (!mLocalMediaManager.isPreferenceRouteListingExist()) {
attachRangeInfo(devices);
@@ -689,7 +692,8 @@ public class MediaSwitchingController
* list.
*/
@GuardedBy("mMediaDevicesLock")
- private List<MediaItem> categorizeMediaItemsLocked(MediaDevice connectedMediaDevice,
+ private List<MediaItem> categorizeMediaItemsLocked(
+ MediaDevice connectedMediaDevice,
List<MediaDevice> devices,
boolean needToHandleMutingExpectedDevice) {
List<MediaItem> finalMediaItems = new ArrayList<>();
@@ -748,6 +752,14 @@ public class MediaSwitchingController
}
private void attachConnectNewDeviceItemIfNeeded(List<MediaItem> mediaItems) {
+ MediaItem connectNewDeviceItem = getConnectNewDeviceItem();
+ if (connectNewDeviceItem != null) {
+ mediaItems.add(connectNewDeviceItem);
+ }
+ }
+
+ @Nullable
+ private MediaItem getConnectNewDeviceItem() {
boolean isSelectedDeviceNotAGroup = getSelectedMediaDevice().size() == 1;
if (enableInputRouting()) {
// When input routing is enabled, there are expected to be at least 2 total selected
@@ -756,9 +768,9 @@ public class MediaSwitchingController
}
// Attach "Connect a device" item only when current output is not remote and not a group
- if (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup) {
- mediaItems.add(MediaItem.createPairNewDeviceMediaItem());
- }
+ return (!isCurrentConnectedDeviceRemote() && isSelectedDeviceNotAGroup)
+ ? MediaItem.createPairNewDeviceMediaItem()
+ : null;
}
private void attachRangeInfo(List<MediaDevice> devices) {
@@ -847,13 +859,13 @@ public class MediaSwitchingController
mediaItems.add(
MediaItem.createGroupDividerMediaItem(
mContext.getString(R.string.media_output_group_title)));
- mediaItems.addAll(mOutputMediaItemList);
+ mediaItems.addAll(mOutputMediaItemListProxy.getOutputMediaItemList());
}
public List<MediaItem> getMediaItemList() {
// If input routing is not enabled, only return output media items.
if (!enableInputRouting()) {
- return mOutputMediaItemList;
+ return mOutputMediaItemListProxy.getOutputMediaItemList();
}
// If input routing is enabled, return both output and input media items.
@@ -959,7 +971,7 @@ public class MediaSwitchingController
public boolean isAnyDeviceTransferring() {
synchronized (mMediaDevicesLock) {
- for (MediaItem mediaItem : mOutputMediaItemList) {
+ for (MediaItem mediaItem : mOutputMediaItemListProxy.getOutputMediaItemList()) {
if (mediaItem.getMediaDevice().isPresent()
&& mediaItem.getMediaDevice().get().getState()
== LocalMediaManager.MediaDeviceState.STATE_CONNECTING) {
@@ -999,8 +1011,11 @@ public class MediaSwitchingController
startActivity(launchIntent, controller);
}
- void launchLeBroadcastNotifyDialog(View mediaOutputDialog, BroadcastSender broadcastSender,
- BroadcastNotifyDialog action, final DialogInterface.OnClickListener listener) {
+ void launchLeBroadcastNotifyDialog(
+ View mediaOutputDialog,
+ BroadcastSender broadcastSender,
+ BroadcastNotifyDialog action,
+ final DialogInterface.OnClickListener listener) {
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
switch (action) {
case ACTION_FIRST_LAUNCH:
@@ -1230,8 +1245,8 @@ public class MediaSwitchingController
return !sourceList.isEmpty();
}
- boolean addSourceIntoSinkDeviceWithBluetoothLeAssistant(BluetoothDevice sink,
- BluetoothLeBroadcastMetadata metadata, boolean isGroupOp) {
+ boolean addSourceIntoSinkDeviceWithBluetoothLeAssistant(
+ BluetoothDevice sink, BluetoothLeBroadcastMetadata metadata, boolean isGroupOp) {
LocalBluetoothLeBroadcastAssistant assistant =
mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
if (assistant == null) {
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/OutputMediaItemListProxy.java b/packages/SystemUI/src/com/android/systemui/media/dialog/OutputMediaItemListProxy.java
new file mode 100644
index 000000000000..1c9c0b102cb7
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/OutputMediaItemListProxy.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2020 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 java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/** A proxy of holding the list of Output Switcher's output media items. */
+public class OutputMediaItemListProxy {
+ private final List<MediaItem> mOutputMediaItemList;
+
+ public OutputMediaItemListProxy() {
+ mOutputMediaItemList = new CopyOnWriteArrayList<>();
+ }
+
+ /** Returns the list of output media items. */
+ public List<MediaItem> getOutputMediaItemList() {
+ return mOutputMediaItemList;
+ }
+
+ /** Updates the list of output media items with the given list. */
+ public void clearAndAddAll(List<MediaItem> updatedMediaItems) {
+ mOutputMediaItemList.clear();
+ mOutputMediaItemList.addAll(updatedMediaItems);
+ }
+
+ /** Removes the media items with muting expected devices. */
+ public void removeMutingExpectedDevices() {
+ mOutputMediaItemList.removeIf((MediaItem::isMutingExpectedDevice));
+ }
+
+ /** Clears the output media item list. */
+ public void clear() {
+ mOutputMediaItemList.clear();
+ }
+
+ /** Returns whether the output media item list is empty. */
+ public boolean isEmpty() {
+ return mOutputMediaItemList.isEmpty();
+ }
+}