Merge "NotificationMediaManager is bad signal for resumption" into rvc-dev am: 59f73711b5

Change-Id: Ie5d882f7a891af3ce5ddf4138584403462e753df
This commit is contained in:
Robert Snoeberger
2020-04-17 18:43:40 +00:00
committed by Automerger Merge Worker
6 changed files with 22 additions and 37 deletions

View File

@@ -55,8 +55,6 @@ import com.android.settingslib.widget.AdaptiveIcon;
import com.android.systemui.Dependency; import com.android.systemui.Dependency;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.NotificationMediaManager.MediaListener;
import com.android.systemui.util.Assert; import com.android.systemui.util.Assert;
import java.util.List; import java.util.List;
@@ -67,7 +65,6 @@ import java.util.concurrent.Executor;
*/ */
public class MediaControlPanel { public class MediaControlPanel {
private static final String TAG = "MediaControlPanel"; private static final String TAG = "MediaControlPanel";
private final NotificationMediaManager mMediaManager;
@Nullable private final LocalMediaManager mLocalMediaManager; @Nullable private final LocalMediaManager mLocalMediaManager;
private final Executor mForegroundExecutor; private final Executor mForegroundExecutor;
private final Executor mBackgroundExecutor; private final Executor mBackgroundExecutor;
@@ -103,12 +100,15 @@ public class MediaControlPanel {
clearControls(); clearControls();
makeInactive(); makeInactive();
} }
};
private final MediaListener mMediaListener = new MediaListener() {
@Override @Override
public void onMetadataOrStateChanged(MediaMetadata metadata, int state) { public void onPlaybackStateChanged(PlaybackState state) {
if (state == PlaybackState.STATE_NONE) { final int s = state != null ? state.getState() : PlaybackState.STATE_NONE;
// When the playback state is NONE or CONNECTING, transition the player to the
// resumption state. State CONNECTING needs to be considered for Cast sessions. Ending
// a cast session in YT results in the CONNECTING state, which makes sense if you
// thinking of the session as waiting to connect to another cast device.
if (s == PlaybackState.STATE_NONE || s == PlaybackState.STATE_CONNECTING) {
Log.d(TAG, "playback state change will trigger resumption, state=" + state);
clearControls(); clearControls();
makeInactive(); makeInactive();
} }
@@ -161,7 +161,7 @@ public class MediaControlPanel {
* @param foregroundExecutor foreground executor * @param foregroundExecutor foreground executor
* @param backgroundExecutor background executor, used for processing artwork * @param backgroundExecutor background executor, used for processing artwork
*/ */
public MediaControlPanel(Context context, ViewGroup parent, NotificationMediaManager manager, public MediaControlPanel(Context context, ViewGroup parent,
@Nullable LocalMediaManager routeManager, @LayoutRes int layoutId, int[] actionIds, @Nullable LocalMediaManager routeManager, @LayoutRes int layoutId, int[] actionIds,
Executor foregroundExecutor, Executor backgroundExecutor) { Executor foregroundExecutor, Executor backgroundExecutor) {
mContext = context; mContext = context;
@@ -173,7 +173,6 @@ public class MediaControlPanel {
// attach/detach of views instead of inflating them in the constructor, which would allow // attach/detach of views instead of inflating them in the constructor, which would allow
// mStateListener to be unregistered in detach. // mStateListener to be unregistered in detach.
mMediaNotifView.addOnAttachStateChangeListener(mStateListener); mMediaNotifView.addOnAttachStateChangeListener(mStateListener);
mMediaManager = manager;
mLocalMediaManager = routeManager; mLocalMediaManager = routeManager;
mActionIds = actionIds; mActionIds = actionIds;
mForegroundExecutor = foregroundExecutor; mForegroundExecutor = foregroundExecutor;
@@ -453,6 +452,7 @@ public class MediaControlPanel {
* Put controls into a resumption state * Put controls into a resumption state
*/ */
public void clearControls() { public void clearControls() {
Log.d(TAG, "clearControls to resumption state package=" + getMediaPlayerPackage());
// Hide all the old buttons // Hide all the old buttons
for (int i = 0; i < mActionIds.length; i++) { for (int i = 0; i < mActionIds.length; i++) {
ImageButton thisBtn = mMediaNotifView.findViewById(mActionIds[i]); ImageButton thisBtn = mMediaNotifView.findViewById(mActionIds[i]);
@@ -495,7 +495,6 @@ public class MediaControlPanel {
private void makeActive() { private void makeActive() {
Assert.isMainThread(); Assert.isMainThread();
if (!mIsRegistered) { if (!mIsRegistered) {
mMediaManager.addCallback(mMediaListener);
if (mLocalMediaManager != null) { if (mLocalMediaManager != null) {
mLocalMediaManager.registerCallback(mDeviceCallback); mLocalMediaManager.registerCallback(mDeviceCallback);
mLocalMediaManager.startScan(); mLocalMediaManager.startScan();
@@ -511,7 +510,6 @@ public class MediaControlPanel {
mLocalMediaManager.stopScan(); mLocalMediaManager.stopScan();
mLocalMediaManager.unregisterCallback(mDeviceCallback); mLocalMediaManager.unregisterCallback(mDeviceCallback);
} }
mMediaManager.removeCallback(mMediaListener);
mIsRegistered = false; mIsRegistered = false;
} }
} }

View File

@@ -39,7 +39,6 @@ import com.android.systemui.R;
import com.android.systemui.media.MediaControlPanel; import com.android.systemui.media.MediaControlPanel;
import com.android.systemui.media.SeekBarObserver; import com.android.systemui.media.SeekBarObserver;
import com.android.systemui.media.SeekBarViewModel; import com.android.systemui.media.SeekBarViewModel;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.DelayableExecutor;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -69,14 +68,13 @@ public class QSMediaPlayer extends MediaControlPanel {
* Initialize quick shade version of player * Initialize quick shade version of player
* @param context * @param context
* @param parent * @param parent
* @param manager * @param routeManager Provides information about device
* @param foregroundExecutor * @param foregroundExecutor
* @param backgroundExecutor * @param backgroundExecutor
*/ */
public QSMediaPlayer(Context context, ViewGroup parent, NotificationMediaManager manager, public QSMediaPlayer(Context context, ViewGroup parent, LocalMediaManager routeManager,
LocalMediaManager routeManager, Executor foregroundExecutor, Executor foregroundExecutor, DelayableExecutor backgroundExecutor) {
DelayableExecutor backgroundExecutor) { super(context, parent, routeManager, R.layout.qs_media_panel, QS_ACTION_IDS,
super(context, parent, manager, routeManager, R.layout.qs_media_panel, QS_ACTION_IDS,
foregroundExecutor, backgroundExecutor); foregroundExecutor, backgroundExecutor);
mParent = (QSPanel) parent; mParent = (QSPanel) parent;
mBackgroundExecutor = backgroundExecutor; mBackgroundExecutor = backgroundExecutor;

View File

@@ -63,7 +63,6 @@ import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.settings.BrightnessController; import com.android.systemui.settings.BrightnessController;
import com.android.systemui.settings.ToggleSliderView; import com.android.systemui.settings.ToggleSliderView;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.statusbar.policy.BrightnessMirrorController; import com.android.systemui.statusbar.policy.BrightnessMirrorController;
import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener; import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener;
import com.android.systemui.tuner.TunerService; import com.android.systemui.tuner.TunerService;
@@ -99,7 +98,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
private final LinearLayout mMediaCarousel; private final LinearLayout mMediaCarousel;
private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>(); private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>();
private final NotificationMediaManager mNotificationMediaManager;
private final LocalBluetoothManager mLocalBluetoothManager; private final LocalBluetoothManager mLocalBluetoothManager;
private final Executor mForegroundExecutor; private final Executor mForegroundExecutor;
private final DelayableExecutor mBackgroundExecutor; private final DelayableExecutor mBackgroundExecutor;
@@ -133,7 +131,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
DumpManager dumpManager, DumpManager dumpManager,
BroadcastDispatcher broadcastDispatcher, BroadcastDispatcher broadcastDispatcher,
QSLogger qsLogger, QSLogger qsLogger,
NotificationMediaManager notificationMediaManager,
@Main Executor foregroundExecutor, @Main Executor foregroundExecutor,
@Background DelayableExecutor backgroundExecutor, @Background DelayableExecutor backgroundExecutor,
@Nullable LocalBluetoothManager localBluetoothManager @Nullable LocalBluetoothManager localBluetoothManager
@@ -142,7 +139,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
mContext = context; mContext = context;
mQSLogger = qsLogger; mQSLogger = qsLogger;
mDumpManager = dumpManager; mDumpManager = dumpManager;
mNotificationMediaManager = notificationMediaManager;
mForegroundExecutor = foregroundExecutor; mForegroundExecutor = foregroundExecutor;
mBackgroundExecutor = backgroundExecutor; mBackgroundExecutor = backgroundExecutor;
mLocalBluetoothManager = localBluetoothManager; mLocalBluetoothManager = localBluetoothManager;
@@ -252,8 +248,8 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
LocalMediaManager routeManager = new LocalMediaManager(mContext, mLocalBluetoothManager, LocalMediaManager routeManager = new LocalMediaManager(mContext, mLocalBluetoothManager,
imm, notif.getPackageName()); imm, notif.getPackageName());
player = new QSMediaPlayer(mContext, this, mNotificationMediaManager, routeManager, player = new QSMediaPlayer(mContext, this, routeManager, mForegroundExecutor,
mForegroundExecutor, mBackgroundExecutor); mBackgroundExecutor);
player.setListening(mListening); player.setListening(mListening);
if (player.isPlaying()) { if (player.isPlaying()) {
mMediaCarousel.addView(player.getView(), 0, lp); // add in front mMediaCarousel.addView(player.getView(), 0, lp); // add in front

View File

@@ -29,7 +29,6 @@ import android.widget.LinearLayout;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.media.MediaControlPanel; import com.android.systemui.media.MediaControlPanel;
import com.android.systemui.statusbar.NotificationMediaManager;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -47,13 +46,12 @@ public class QuickQSMediaPlayer extends MediaControlPanel {
* Initialize mini media player for QQS * Initialize mini media player for QQS
* @param context * @param context
* @param parent * @param parent
* @param manager
* @param foregroundExecutor * @param foregroundExecutor
* @param backgroundExecutor * @param backgroundExecutor
*/ */
public QuickQSMediaPlayer(Context context, ViewGroup parent, NotificationMediaManager manager, public QuickQSMediaPlayer(Context context, ViewGroup parent, Executor foregroundExecutor,
Executor foregroundExecutor, Executor backgroundExecutor) { Executor backgroundExecutor) {
super(context, parent, manager, null, R.layout.qqs_media_panel, QQS_ACTION_IDS, super(context, parent, null, R.layout.qqs_media_panel, QQS_ACTION_IDS,
foregroundExecutor, backgroundExecutor); foregroundExecutor, backgroundExecutor);
} }

View File

@@ -39,7 +39,6 @@ import com.android.systemui.plugins.qs.QSTile.SignalState;
import com.android.systemui.plugins.qs.QSTile.State; import com.android.systemui.plugins.qs.QSTile.State;
import com.android.systemui.qs.customize.QSCustomizer; import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.tuner.TunerService; import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable; import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.util.Utils; import com.android.systemui.util.Utils;
@@ -83,12 +82,11 @@ public class QuickQSPanel extends QSPanel {
DumpManager dumpManager, DumpManager dumpManager,
BroadcastDispatcher broadcastDispatcher, BroadcastDispatcher broadcastDispatcher,
QSLogger qsLogger, QSLogger qsLogger,
NotificationMediaManager notificationMediaManager,
@Main Executor foregroundExecutor, @Main Executor foregroundExecutor,
@Background DelayableExecutor backgroundExecutor, @Background DelayableExecutor backgroundExecutor,
@Nullable LocalBluetoothManager localBluetoothManager @Nullable LocalBluetoothManager localBluetoothManager
) { ) {
super(context, attrs, dumpManager, broadcastDispatcher, qsLogger, notificationMediaManager, super(context, attrs, dumpManager, broadcastDispatcher, qsLogger,
foregroundExecutor, backgroundExecutor, localBluetoothManager); foregroundExecutor, backgroundExecutor, localBluetoothManager);
if (mFooter != null) { if (mFooter != null) {
removeView(mFooter.getView()); removeView(mFooter.getView());
@@ -109,7 +107,7 @@ public class QuickQSPanel extends QSPanel {
int marginSize = (int) mContext.getResources().getDimension(R.dimen.qqs_media_spacing); int marginSize = (int) mContext.getResources().getDimension(R.dimen.qqs_media_spacing);
mMediaPlayer = new QuickQSMediaPlayer(mContext, mHorizontalLinearLayout, mMediaPlayer = new QuickQSMediaPlayer(mContext, mHorizontalLinearLayout,
notificationMediaManager, foregroundExecutor, backgroundExecutor); foregroundExecutor, backgroundExecutor);
LayoutParams lp2 = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1); LayoutParams lp2 = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
lp2.setMarginEnd(marginSize); lp2.setMarginEnd(marginSize);
lp2.setMarginStart(0); lp2.setMarginStart(0);

View File

@@ -43,7 +43,6 @@ import com.android.systemui.plugins.qs.QSTileView;
import com.android.systemui.qs.customize.QSCustomizer; import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.qs.logging.QSLogger; import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.NotificationMediaManager;
import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.DelayableExecutor;
import org.junit.Before; import org.junit.Before;
@@ -84,8 +83,6 @@ public class QSPanelTest extends SysuiTestCase {
@Mock @Mock
private QSTileView mQSTileView; private QSTileView mQSTileView;
@Mock @Mock
private NotificationMediaManager mNotificationMediaManager;
@Mock
private Executor mForegroundExecutor; private Executor mForegroundExecutor;
@Mock @Mock
private DelayableExecutor mBackgroundExecutor; private DelayableExecutor mBackgroundExecutor;
@@ -100,7 +97,7 @@ public class QSPanelTest extends SysuiTestCase {
mTestableLooper.runWithLooper(() -> { mTestableLooper.runWithLooper(() -> {
mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class); mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
mQsPanel = new QSPanel(mContext, null, mDumpManager, mBroadcastDispatcher, mQsPanel = new QSPanel(mContext, null, mDumpManager, mBroadcastDispatcher,
mQSLogger, mNotificationMediaManager, mForegroundExecutor, mBackgroundExecutor, mQSLogger, mForegroundExecutor, mBackgroundExecutor,
mLocalBluetoothManager); mLocalBluetoothManager);
// Provides a parent with non-zero size for QSPanel // Provides a parent with non-zero size for QSPanel
mParentView = new FrameLayout(mContext); mParentView = new FrameLayout(mContext);