Loading packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +1 −1 Original line number Diff line number Diff line Loading @@ -439,7 +439,7 @@ public abstract class MediaDevice implements Comparable<MediaDevice> { * Check if it is muting expected device * @return {@code true} if it is muting expected device, otherwise return {@code false} */ protected boolean isMutingExpectedDevice() { public boolean isMutingExpectedDevice() { return false; } Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java +39 −12 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { @Override void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) { super.onBind(device, topMargin, bottomMargin, position); boolean isMutingExpectedDeviceExist = mController.hasMutingExpectedDevice(); final boolean currentlyConnected = !mIncludeDynamicGroup && isCurrentlyConnected(device); boolean isCurrentSeekbarInvisible = mSeekBar.getVisibility() == View.GONE; Loading Loading @@ -146,7 +147,19 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { } } else { // Set different layout for each device if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) { if (device.isMutingExpectedDevice() && !mController.isCurrentConnectedDeviceRemote()) { mTitleIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_icon_volume)); mTitleIcon.setColorFilter(mController.getColorItemContent()); mTitleText.setTextColor(mController.getColorItemContent()); setSingleLineLayout(getItemTitle(device), true /* bFocused */, false /* showSeekBar */, false /* showProgressBar */, false /* showStatus */); initMutingExpectedDevice(); mCurrentActivePosition = position; mContainerLayout.setOnClickListener(v -> onItemClick(v, device)); } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) { setUpDeviceIcon(device); mStatusIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_status_failed)); Loading Loading @@ -193,7 +206,15 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { mEndTouchArea.setImportantForAccessibility( View.IMPORTANT_FOR_ACCESSIBILITY_YES); setUpContentDescriptionForView(mEndTouchArea, true, device); } else if (!mController.hasAdjustVolumeUserRestriction() && currentlyConnected) { } else if (!mController.hasAdjustVolumeUserRestriction() && currentlyConnected) { if (isMutingExpectedDeviceExist && !mController.isCurrentConnectedDeviceRemote()) { // mark as disconnected and set special click listener setUpDeviceIcon(device); setSingleLineLayout(getItemTitle(device), false /* bFocused */); mContainerLayout.setOnClickListener(v -> cancelMuteAwaitConnection()); } else { mTitleIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_icon_volume)); mTitleIcon.setColorFilter(mController.getColorItemContent()); Loading @@ -204,6 +225,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { initSeekbar(device, isCurrentSeekbarInvisible); setUpContentDescriptionForView(mContainerLayout, false, device); mCurrentActivePosition = position; } } else if (isDeviceIncluded(mController.getSelectableMediaDevice(), device)) { setUpDeviceIcon(device); mCheckBox.setOnCheckedChangeListener(null); Loading Loading @@ -269,6 +291,11 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { notifyDataSetChanged(); } private void cancelMuteAwaitConnection() { mController.cancelMuteAwaitConnection(); notifyDataSetChanged(); } private void setUpContentDescriptionForView(View view, boolean clickable, MediaDevice device) { view.setClickable(clickable); Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java +11 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,17 @@ public abstract class MediaOutputBaseAdapter extends }); } void initMutingExpectedDevice() { disableSeekBar(); final Drawable backgroundDrawable = mContext.getDrawable( R.drawable.media_output_item_background_active) .mutate(); backgroundDrawable.setColorFilter( new PorterDuffColorFilter(mController.getColorConnectedItemBackground(), PorterDuff.Mode.SRC_IN)); mItemLayout.setBackground(backgroundDrawable); } void initSessionSeekbar() { disableSeekBar(); mSeekBar.setMax(mController.getSessionVolumeMax()); Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt +4 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.media.dialog import android.content.Context import android.media.AudioManager import android.media.session.MediaSessionManager import android.view.View import com.android.internal.logging.UiEventLogger Loading @@ -41,7 +42,8 @@ class MediaOutputBroadcastDialogFactory @Inject constructor( private val notifCollection: CommonNotifCollection, private val uiEventLogger: UiEventLogger, private val dialogLaunchAnimator: DialogLaunchAnimator, private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager> private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager>, private val audioManager: AudioManager ) { var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null Loading @@ -52,7 +54,7 @@ class MediaOutputBroadcastDialogFactory @Inject constructor( val controller = MediaOutputController(context, packageName, mediaSessionManager, lbm, starter, notifCollection, dialogLaunchAnimator, nearbyMediaDevicesManagerOptional) dialogLaunchAnimator, nearbyMediaDevicesManagerOptional, audioManager) val dialog = MediaOutputBroadcastDialog(context, aboveStatusBar, broadcastSender, controller) mediaOutputBroadcastDialog = dialog Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +55 −10 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.media.AudioManager; import android.media.INearbyMediaDevicesUpdateCallback; import android.media.MediaMetadata; import android.media.MediaRoute2Info; Loading Loading @@ -112,6 +113,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, @VisibleForTesting final List<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>(); final List<MediaDevice> mCachedMediaDevices = new CopyOnWriteArrayList<>(); private final AudioManager mAudioManager; private final NearbyMediaDevicesManager mNearbyMediaDevicesManager; private final Map<String, Integer> mNearbyDeviceInfoMap = new ConcurrentHashMap<>(); Loading @@ -122,7 +124,6 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, Callback mCallback; @VisibleForTesting LocalMediaManager mLocalMediaManager; private MediaOutputMetricLogger mMetricLogger; private int mColorItemContent; Loading @@ -145,13 +146,15 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, lbm, ActivityStarter starter, CommonNotifCollection notifCollection, DialogLaunchAnimator dialogLaunchAnimator, Optional<NearbyMediaDevicesManager> nearbyMediaDevicesManagerOptional) { Optional<NearbyMediaDevicesManager> nearbyMediaDevicesManagerOptional, AudioManager audioManager) { mContext = context; mPackageName = packageName; mMediaSessionManager = mediaSessionManager; mLocalBluetoothManager = lbm; mActivityStarter = starter; mNotifCollection = notifCollection; mAudioManager = audioManager; InfoMediaManager imm = new InfoMediaManager(mContext, packageName, null, lbm); mLocalMediaManager = new LocalMediaManager(mContext, lbm, imm, packageName); mMetricLogger = new MediaOutputMetricLogger(mContext, mPackageName); Loading Loading @@ -217,14 +220,14 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, return false; } void setRefreshing(boolean refreshing) { mIsRefreshing = refreshing; } boolean isRefreshing() { return mIsRefreshing; } void setRefreshing(boolean refreshing) { mIsRefreshing = refreshing; } void stop() { if (mMediaController != null) { mMediaController.unregisterCallback(mCb); Loading Loading @@ -275,6 +278,27 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, mMetricLogger.logOutputFailure(new ArrayList<>(mMediaDevices), reason); } /** * Checks if there's any muting expected device exist */ public boolean hasMutingExpectedDevice() { return mAudioManager.getMutingExpectedDevice() != null; } /** * Cancels mute await connection action in follow up request */ public void cancelMuteAwaitConnection() { if (mAudioManager.getMutingExpectedDevice() == null) { return; } try { mAudioManager.cancelMuteAwaitConnection(mAudioManager.getMutingExpectedDevice()); } catch (Exception e) { Log.d(TAG, "Unable to cancel mute await connection"); } } Drawable getAppSourceIcon() { if (mPackageName.isEmpty()) { return null; Loading Loading @@ -471,12 +495,26 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, // For the first time building list, to make sure the top device is the connected // device. if (mMediaDevices.isEmpty()) { final MediaDevice connectedMediaDevice = getCurrentConnectedMediaDevice(); boolean needToHandleMutingExpectedDevice = hasMutingExpectedDevice() && !isCurrentConnectedDeviceRemote(); final MediaDevice connectedMediaDevice = needToHandleMutingExpectedDevice ? null : getCurrentConnectedMediaDevice(); if (connectedMediaDevice == null) { if (DEBUG) { Log.d(TAG, "No connected media device."); Log.d(TAG, "No connected media device or muting expected device exist."); } if (needToHandleMutingExpectedDevice) { for (MediaDevice device : devices) { if (device.isMutingExpectedDevice()) { mMediaDevices.add(0, device); } else { mMediaDevices.add(device); } } } else { mMediaDevices.addAll(devices); } return; } for (MediaDevice device : devices) { Loading Loading @@ -516,6 +554,12 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } boolean isCurrentConnectedDeviceRemote() { MediaDevice currentConnectedMediaDevice = getCurrentConnectedMediaDevice(); return currentConnectedMediaDevice != null && isActiveRemoteDevice( currentConnectedMediaDevice); } List<MediaDevice> getGroupMediaDevices() { final List<MediaDevice> selectedDevices = getSelectedMediaDevice(); final List<MediaDevice> selectableDevices = getSelectableMediaDevice(); Loading Loading @@ -731,7 +775,8 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, void launchMediaOutputBroadcastDialog(View mediaOutputDialog, BroadcastSender broadcastSender) { MediaOutputController controller = new MediaOutputController(mContext, mPackageName, mMediaSessionManager, mLocalBluetoothManager, mActivityStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager)); mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager); MediaOutputBroadcastDialog dialog = new MediaOutputBroadcastDialog(mContext, true, broadcastSender, controller); mDialogLaunchAnimator.showFromView(dialog, mediaOutputDialog); Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +1 −1 Original line number Diff line number Diff line Loading @@ -439,7 +439,7 @@ public abstract class MediaDevice implements Comparable<MediaDevice> { * Check if it is muting expected device * @return {@code true} if it is muting expected device, otherwise return {@code false} */ protected boolean isMutingExpectedDevice() { public boolean isMutingExpectedDevice() { return false; } Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java +39 −12 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { @Override void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) { super.onBind(device, topMargin, bottomMargin, position); boolean isMutingExpectedDeviceExist = mController.hasMutingExpectedDevice(); final boolean currentlyConnected = !mIncludeDynamicGroup && isCurrentlyConnected(device); boolean isCurrentSeekbarInvisible = mSeekBar.getVisibility() == View.GONE; Loading Loading @@ -146,7 +147,19 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { } } else { // Set different layout for each device if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) { if (device.isMutingExpectedDevice() && !mController.isCurrentConnectedDeviceRemote()) { mTitleIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_icon_volume)); mTitleIcon.setColorFilter(mController.getColorItemContent()); mTitleText.setTextColor(mController.getColorItemContent()); setSingleLineLayout(getItemTitle(device), true /* bFocused */, false /* showSeekBar */, false /* showProgressBar */, false /* showStatus */); initMutingExpectedDevice(); mCurrentActivePosition = position; mContainerLayout.setOnClickListener(v -> onItemClick(v, device)); } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) { setUpDeviceIcon(device); mStatusIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_status_failed)); Loading Loading @@ -193,7 +206,15 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { mEndTouchArea.setImportantForAccessibility( View.IMPORTANT_FOR_ACCESSIBILITY_YES); setUpContentDescriptionForView(mEndTouchArea, true, device); } else if (!mController.hasAdjustVolumeUserRestriction() && currentlyConnected) { } else if (!mController.hasAdjustVolumeUserRestriction() && currentlyConnected) { if (isMutingExpectedDeviceExist && !mController.isCurrentConnectedDeviceRemote()) { // mark as disconnected and set special click listener setUpDeviceIcon(device); setSingleLineLayout(getItemTitle(device), false /* bFocused */); mContainerLayout.setOnClickListener(v -> cancelMuteAwaitConnection()); } else { mTitleIcon.setImageDrawable( mContext.getDrawable(R.drawable.media_output_icon_volume)); mTitleIcon.setColorFilter(mController.getColorItemContent()); Loading @@ -204,6 +225,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { initSeekbar(device, isCurrentSeekbarInvisible); setUpContentDescriptionForView(mContainerLayout, false, device); mCurrentActivePosition = position; } } else if (isDeviceIncluded(mController.getSelectableMediaDevice(), device)) { setUpDeviceIcon(device); mCheckBox.setOnCheckedChangeListener(null); Loading Loading @@ -269,6 +291,11 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter { notifyDataSetChanged(); } private void cancelMuteAwaitConnection() { mController.cancelMuteAwaitConnection(); notifyDataSetChanged(); } private void setUpContentDescriptionForView(View view, boolean clickable, MediaDevice device) { view.setClickable(clickable); Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseAdapter.java +11 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,17 @@ public abstract class MediaOutputBaseAdapter extends }); } void initMutingExpectedDevice() { disableSeekBar(); final Drawable backgroundDrawable = mContext.getDrawable( R.drawable.media_output_item_background_active) .mutate(); backgroundDrawable.setColorFilter( new PorterDuffColorFilter(mController.getColorConnectedItemBackground(), PorterDuff.Mode.SRC_IN)); mItemLayout.setBackground(backgroundDrawable); } void initSessionSeekbar() { disableSeekBar(); mSeekBar.setMax(mController.getSessionVolumeMax()); Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogFactory.kt +4 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.media.dialog import android.content.Context import android.media.AudioManager import android.media.session.MediaSessionManager import android.view.View import com.android.internal.logging.UiEventLogger Loading @@ -41,7 +42,8 @@ class MediaOutputBroadcastDialogFactory @Inject constructor( private val notifCollection: CommonNotifCollection, private val uiEventLogger: UiEventLogger, private val dialogLaunchAnimator: DialogLaunchAnimator, private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager> private val nearbyMediaDevicesManagerOptional: Optional<NearbyMediaDevicesManager>, private val audioManager: AudioManager ) { var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null Loading @@ -52,7 +54,7 @@ class MediaOutputBroadcastDialogFactory @Inject constructor( val controller = MediaOutputController(context, packageName, mediaSessionManager, lbm, starter, notifCollection, dialogLaunchAnimator, nearbyMediaDevicesManagerOptional) dialogLaunchAnimator, nearbyMediaDevicesManagerOptional, audioManager) val dialog = MediaOutputBroadcastDialog(context, aboveStatusBar, broadcastSender, controller) mediaOutputBroadcastDialog = dialog Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +55 −10 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.media.AudioManager; import android.media.INearbyMediaDevicesUpdateCallback; import android.media.MediaMetadata; import android.media.MediaRoute2Info; Loading Loading @@ -112,6 +113,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, @VisibleForTesting final List<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>(); final List<MediaDevice> mCachedMediaDevices = new CopyOnWriteArrayList<>(); private final AudioManager mAudioManager; private final NearbyMediaDevicesManager mNearbyMediaDevicesManager; private final Map<String, Integer> mNearbyDeviceInfoMap = new ConcurrentHashMap<>(); Loading @@ -122,7 +124,6 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, Callback mCallback; @VisibleForTesting LocalMediaManager mLocalMediaManager; private MediaOutputMetricLogger mMetricLogger; private int mColorItemContent; Loading @@ -145,13 +146,15 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, lbm, ActivityStarter starter, CommonNotifCollection notifCollection, DialogLaunchAnimator dialogLaunchAnimator, Optional<NearbyMediaDevicesManager> nearbyMediaDevicesManagerOptional) { Optional<NearbyMediaDevicesManager> nearbyMediaDevicesManagerOptional, AudioManager audioManager) { mContext = context; mPackageName = packageName; mMediaSessionManager = mediaSessionManager; mLocalBluetoothManager = lbm; mActivityStarter = starter; mNotifCollection = notifCollection; mAudioManager = audioManager; InfoMediaManager imm = new InfoMediaManager(mContext, packageName, null, lbm); mLocalMediaManager = new LocalMediaManager(mContext, lbm, imm, packageName); mMetricLogger = new MediaOutputMetricLogger(mContext, mPackageName); Loading Loading @@ -217,14 +220,14 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, return false; } void setRefreshing(boolean refreshing) { mIsRefreshing = refreshing; } boolean isRefreshing() { return mIsRefreshing; } void setRefreshing(boolean refreshing) { mIsRefreshing = refreshing; } void stop() { if (mMediaController != null) { mMediaController.unregisterCallback(mCb); Loading Loading @@ -275,6 +278,27 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, mMetricLogger.logOutputFailure(new ArrayList<>(mMediaDevices), reason); } /** * Checks if there's any muting expected device exist */ public boolean hasMutingExpectedDevice() { return mAudioManager.getMutingExpectedDevice() != null; } /** * Cancels mute await connection action in follow up request */ public void cancelMuteAwaitConnection() { if (mAudioManager.getMutingExpectedDevice() == null) { return; } try { mAudioManager.cancelMuteAwaitConnection(mAudioManager.getMutingExpectedDevice()); } catch (Exception e) { Log.d(TAG, "Unable to cancel mute await connection"); } } Drawable getAppSourceIcon() { if (mPackageName.isEmpty()) { return null; Loading Loading @@ -471,12 +495,26 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, // For the first time building list, to make sure the top device is the connected // device. if (mMediaDevices.isEmpty()) { final MediaDevice connectedMediaDevice = getCurrentConnectedMediaDevice(); boolean needToHandleMutingExpectedDevice = hasMutingExpectedDevice() && !isCurrentConnectedDeviceRemote(); final MediaDevice connectedMediaDevice = needToHandleMutingExpectedDevice ? null : getCurrentConnectedMediaDevice(); if (connectedMediaDevice == null) { if (DEBUG) { Log.d(TAG, "No connected media device."); Log.d(TAG, "No connected media device or muting expected device exist."); } if (needToHandleMutingExpectedDevice) { for (MediaDevice device : devices) { if (device.isMutingExpectedDevice()) { mMediaDevices.add(0, device); } else { mMediaDevices.add(device); } } } else { mMediaDevices.addAll(devices); } return; } for (MediaDevice device : devices) { Loading Loading @@ -516,6 +554,12 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, } boolean isCurrentConnectedDeviceRemote() { MediaDevice currentConnectedMediaDevice = getCurrentConnectedMediaDevice(); return currentConnectedMediaDevice != null && isActiveRemoteDevice( currentConnectedMediaDevice); } List<MediaDevice> getGroupMediaDevices() { final List<MediaDevice> selectedDevices = getSelectedMediaDevice(); final List<MediaDevice> selectableDevices = getSelectableMediaDevice(); Loading Loading @@ -731,7 +775,8 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, void launchMediaOutputBroadcastDialog(View mediaOutputDialog, BroadcastSender broadcastSender) { MediaOutputController controller = new MediaOutputController(mContext, mPackageName, mMediaSessionManager, mLocalBluetoothManager, mActivityStarter, mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager)); mNotifCollection, mDialogLaunchAnimator, Optional.of(mNearbyMediaDevicesManager), mAudioManager); MediaOutputBroadcastDialog dialog = new MediaOutputBroadcastDialog(mContext, true, broadcastSender, controller); mDialogLaunchAnimator.showFromView(dialog, mediaOutputDialog); Loading