diff options
| author | 2023-09-12 13:01:59 +0000 | |
|---|---|---|
| committer | 2023-09-12 13:01:59 +0000 | |
| commit | 77fd96d9e61bd2fc27ca967a8e9f1d96dd37caeb (patch) | |
| tree | 83c07fd00e76869b0dfcaa1e2360410dfed129e3 | |
| parent | 90806496f8cdd59228716cd64c24c45d55f3a049 (diff) | |
| parent | ef6c2b15ee41e7c6a46f777d59c6e7d6af8bc663 (diff) | |
Merge "Add adjustments to allow for TvMediaOutputDialog." into main
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java | 62 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt | 6 |
2 files changed, 38 insertions, 30 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index bb0e9d182579..7011ad992a91 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -127,7 +127,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, private final ActivityStarter mActivityStarter; private final DialogLaunchAnimator mDialogLaunchAnimator; private final CommonNotifCollection mNotifCollection; - private final Object mMediaDevicesLock = new Object(); + protected final Object mMediaDevicesLock = new Object(); @VisibleForTesting final List<MediaDevice> mGroupMediaDevices = new CopyOnWriteArrayList<>(); final List<MediaDevice> mCachedMediaDevices = new CopyOnWriteArrayList<>(); @@ -222,7 +222,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, R.dimen.media_output_dialog_selectable_margin_end); } - void start(@NonNull Callback cb) { + protected void start(@NonNull Callback cb) { synchronized (mMediaDevicesLock) { mCachedMediaDevices.clear(); mMediaItemList.clear(); @@ -256,15 +256,15 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, return false; } - boolean isRefreshing() { + public boolean isRefreshing() { return mIsRefreshing; } - void setRefreshing(boolean refreshing) { + public void setRefreshing(boolean refreshing) { mIsRefreshing = refreshing; } - void stop() { + protected void stop() { if (mMediaController != null) { mMediaController.unregisterCallback(mCb); } @@ -551,7 +551,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } } - void refreshDataSetIfNeeded() { + public void refreshDataSetIfNeeded() { if (mNeedRefresh) { buildMediaItems(mCachedMediaDevices); mCallback.onDeviceListChanged(); @@ -605,6 +605,15 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, private void buildMediaItems(List<MediaDevice> devices) { synchronized (mMediaDevicesLock) { + List<MediaItem> updatedMediaItems = buildMediaItems(mMediaItemList, devices); + mMediaItemList.clear(); + mMediaItemList.addAll(updatedMediaItems); + } + } + + protected List<MediaItem> buildMediaItems(List<MediaItem> oldMediaItems, + List<MediaDevice> devices) { + synchronized (mMediaDevicesLock) { if (!mLocalMediaManager.isPreferenceRouteListingExist()) { attachRangeInfo(devices); Collections.sort(devices, Comparator.naturalOrder()); @@ -616,22 +625,20 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, final MediaDevice connectedMediaDevice = needToHandleMutingExpectedDevice ? null : getCurrentConnectedMediaDevice(); - if (mMediaItemList.isEmpty()) { + if (oldMediaItems.isEmpty()) { if (connectedMediaDevice == null) { if (DEBUG) { Log.d(TAG, "No connected media device or muting expected device exist."); } - categorizeMediaItems(null, devices, needToHandleMutingExpectedDevice); - return; + return categorizeMediaItems(null, devices, needToHandleMutingExpectedDevice); } // selected device exist - categorizeMediaItems(connectedMediaDevice, devices, false); - return; + return categorizeMediaItems(connectedMediaDevice, devices, false); } // To keep the same list order final List<MediaDevice> targetMediaDevices = new ArrayList<>(); final Map<Integer, MediaItem> dividerItems = new HashMap<>(); - for (MediaItem originalMediaItem : mMediaItemList) { + for (MediaItem originalMediaItem : oldMediaItems) { for (MediaDevice newDevice : devices) { if (originalMediaItem.getMediaDevice().isPresent() && TextUtils.equals(originalMediaItem.getMediaDevice().get().getId(), @@ -642,7 +649,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } if (originalMediaItem.getMediaItemType() == MediaItem.MediaItemType.TYPE_GROUP_DIVIDER) { - dividerItems.put(mMediaItemList.indexOf(originalMediaItem), originalMediaItem); + dividerItems.put(oldMediaItems.indexOf(originalMediaItem), originalMediaItem); } } if (targetMediaDevices.size() != devices.size()) { @@ -651,16 +658,18 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } List<MediaItem> finalMediaItems = targetMediaDevices.stream().map( MediaItem::new).collect(Collectors.toList()); - dividerItems.forEach((key, item) -> { - finalMediaItems.add(key, item); - }); + dividerItems.forEach(finalMediaItems::add); attachConnectNewDeviceItemIfNeeded(finalMediaItems); - mMediaItemList.clear(); - mMediaItemList.addAll(finalMediaItems); + return finalMediaItems; } } - private void categorizeMediaItems(MediaDevice connectedMediaDevice, List<MediaDevice> devices, + /** + * Initial categorization of current devices, will not be called for updates to the devices + * list. + */ + private List<MediaItem> categorizeMediaItems(MediaDevice connectedMediaDevice, + List<MediaDevice> devices, boolean needToHandleMutingExpectedDevice) { synchronized (mMediaDevicesLock) { List<MediaItem> finalMediaItems = new ArrayList<>(); @@ -691,8 +700,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } } attachConnectNewDeviceItemIfNeeded(finalMediaItems); - mMediaItemList.clear(); - mMediaItemList.addAll(finalMediaItems); + return finalMediaItems; } } @@ -765,7 +773,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, mGroupMediaDevices.clear(); } - void connectDevice(MediaDevice device) { + protected void connectDevice(MediaDevice device) { mMetricLogger.updateOutputEndPoints(getCurrentConnectedMediaDevice(), device); ThreadUtils.postOnBackgroundThread(() -> { @@ -777,7 +785,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, return mMediaItemList; } - MediaDevice getCurrentConnectedMediaDevice() { + public MediaDevice getCurrentConnectedMediaDevice() { return mLocalMediaManager.getCurrentConnectedDevice(); } @@ -794,7 +802,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, return mLocalMediaManager.getSelectableMediaDevice(); } - List<MediaDevice> getSelectedMediaDevice() { + public List<MediaDevice> getSelectedMediaDevice() { return mLocalMediaManager.getSelectedMediaDevice(); } @@ -859,7 +867,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, UserHandle.of(UserHandle.myUserId())); } - boolean isAnyDeviceTransferring() { + public boolean isAnyDeviceTransferring() { synchronized (mMediaDevicesLock) { for (MediaItem mediaItem : mMediaItemList) { if (mediaItem.getMediaDevice().isPresent() @@ -976,7 +984,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, broadcast.setBroadcastCode(broadcastCode.getBytes(StandardCharsets.UTF_8)); } - void setTemporaryAllowListExceptionIfNeeded(MediaDevice targetDevice) { + protected void setTemporaryAllowListExceptionIfNeeded(MediaDevice targetDevice) { if (mPowerExemptionManager == null || mPackageName == null) { Log.w(TAG, "powerExemptionManager or package name is null"); return; @@ -1221,7 +1229,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } }; - interface Callback { + public interface Callback { /** * Override to handle the media content updating. */ diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt index af659378e8f7..2b38edb3c47e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogFactory.kt @@ -38,7 +38,7 @@ import javax.inject.Inject /** * Factory to create [MediaOutputDialog] objects. */ -class MediaOutputDialogFactory @Inject constructor( +open class MediaOutputDialogFactory @Inject constructor( private val context: Context, private val mediaSessionManager: MediaSessionManager, private val lbm: LocalBluetoothManager?, @@ -60,7 +60,7 @@ class MediaOutputDialogFactory @Inject constructor( } /** Creates a [MediaOutputDialog] for the given package. */ - fun create(packageName: String, aboveStatusBar: Boolean, view: View? = null) { + open fun create(packageName: String, aboveStatusBar: Boolean, view: View? = null) { // Dismiss the previous dialog, if any. mediaOutputDialog?.dismiss() @@ -89,7 +89,7 @@ class MediaOutputDialogFactory @Inject constructor( } /** dismiss [MediaOutputDialog] if exist. */ - fun dismiss() { + open fun dismiss() { mediaOutputDialog?.dismiss() mediaOutputDialog = null } |