Merge "Update when media controls get cleared" into rvc-dev am: fccec793d3 am: 73ffa0e9a2 am: c1c1bc750b

Change-Id: I78c046b53f48d6237bc2ec90e0e852c1358b56be
This commit is contained in:
Beth Thibodeau
2020-04-29 18:50:45 +00:00
committed by Automerger Merge Worker
5 changed files with 51 additions and 10 deletions

View File

@@ -126,11 +126,7 @@ public class MediaControlPanel {
@Override @Override
public void onPlaybackStateChanged(PlaybackState state) { public void onPlaybackStateChanged(PlaybackState state) {
final int s = state != null ? state.getState() : 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 if (s == PlaybackState.STATE_NONE) {
// 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); Log.d(TAG, "playback state change will trigger resumption, state=" + state);
clearControls(); clearControls();
makeInactive(); makeInactive();

View File

@@ -82,7 +82,7 @@ public class QSMediaBrowser {
public void onChildrenLoaded(String parentId, public void onChildrenLoaded(String parentId,
List<MediaBrowser.MediaItem> children) { List<MediaBrowser.MediaItem> children) {
if (children.size() == 0) { if (children.size() == 0) {
Log.e(TAG, "No children found"); Log.e(TAG, "No children found for " + mComponentName);
return; return;
} }
// We ask apps to return a playable item as the first child when sending // We ask apps to return a playable item as the first child when sending

View File

@@ -53,6 +53,7 @@ import android.widget.LinearLayout;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.media.InfoMediaManager; import com.android.settingslib.media.InfoMediaManager;
@@ -75,6 +76,9 @@ 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.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
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;
@@ -116,6 +120,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
private final DelayableExecutor mBackgroundExecutor; private final DelayableExecutor mBackgroundExecutor;
private boolean mUpdateCarousel = false; private boolean mUpdateCarousel = false;
private ActivityStarter mActivityStarter; private ActivityStarter mActivityStarter;
private NotificationEntryManager mNotificationEntryManager;
protected boolean mExpanded; protected boolean mExpanded;
protected boolean mListening; protected boolean mListening;
@@ -151,6 +156,15 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
} }
}; };
private final NotificationEntryListener mNotificationEntryListener =
new NotificationEntryListener() {
@Override
public void onEntryRemoved(NotificationEntry entry, NotificationVisibility visibility,
boolean removedByUser, int reason) {
checkToRemoveMediaNotification(entry);
}
};
@Inject @Inject
public QSPanel( public QSPanel(
@Named(VIEW_CONTEXT) Context context, @Named(VIEW_CONTEXT) Context context,
@@ -161,7 +175,8 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
@Main Executor foregroundExecutor, @Main Executor foregroundExecutor,
@Background DelayableExecutor backgroundExecutor, @Background DelayableExecutor backgroundExecutor,
@Nullable LocalBluetoothManager localBluetoothManager, @Nullable LocalBluetoothManager localBluetoothManager,
ActivityStarter activityStarter ActivityStarter activityStarter,
NotificationEntryManager entryManager
) { ) {
super(context, attrs); super(context, attrs);
mContext = context; mContext = context;
@@ -172,6 +187,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
mLocalBluetoothManager = localBluetoothManager; mLocalBluetoothManager = localBluetoothManager;
mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher;
mActivityStarter = activityStarter; mActivityStarter = activityStarter;
mNotificationEntryManager = entryManager;
setOrientation(VERTICAL); setOrientation(VERTICAL);
@@ -407,6 +423,27 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
mHasLoadedMediaControls = true; mHasLoadedMediaControls = true;
} }
private void checkToRemoveMediaNotification(NotificationEntry entry) {
if (!useQsMediaPlayer(mContext)) {
return;
}
if (!entry.isMediaNotification()) {
return;
}
// If this entry corresponds to an existing set of controls, clear the controls
// This will handle apps that use an action to clear their notification
for (QSMediaPlayer p : mMediaPlayers) {
if (p.getKey() != null && p.getKey().equals(entry.getKey())) {
Log.d(TAG, "Clearing controls since notification removed " + entry.getKey());
p.clearControls();
return;
}
}
Log.d(TAG, "Media notification removed but no player found " + entry.getKey());
}
protected void addDivider() { protected void addDivider() {
mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false); mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false);
mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(), mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(),
@@ -473,6 +510,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
loadMediaResumptionControls(); loadMediaResumptionControls();
} }
} }
mNotificationEntryManager.addNotificationEntryListener(mNotificationEntryListener);
} }
@Override @Override
@@ -489,6 +527,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
} }
mDumpManager.unregisterDumpable(getDumpableTag()); mDumpManager.unregisterDumpable(getDumpableTag());
mBroadcastDispatcher.unregisterReceiver(mUserChangeReceiver); mBroadcastDispatcher.unregisterReceiver(mUserChangeReceiver);
mNotificationEntryManager.removeNotificationEntryListener(mNotificationEntryListener);
super.onDetachedFromWindow(); super.onDetachedFromWindow();
} }

View File

@@ -40,6 +40,7 @@ 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.notification.NotificationEntryManager;
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;
@@ -86,10 +87,12 @@ public class QuickQSPanel extends QSPanel {
@Main Executor foregroundExecutor, @Main Executor foregroundExecutor,
@Background DelayableExecutor backgroundExecutor, @Background DelayableExecutor backgroundExecutor,
@Nullable LocalBluetoothManager localBluetoothManager, @Nullable LocalBluetoothManager localBluetoothManager,
ActivityStarter activityStarter ActivityStarter activityStarter,
NotificationEntryManager entryManager
) { ) {
super(context, attrs, dumpManager, broadcastDispatcher, qsLogger, super(context, attrs, dumpManager, broadcastDispatcher, qsLogger,
foregroundExecutor, backgroundExecutor, localBluetoothManager, activityStarter); foregroundExecutor, backgroundExecutor, localBluetoothManager, activityStarter,
entryManager);
if (mFooter != null) { if (mFooter != null) {
removeView(mFooter.getView()); removeView(mFooter.getView());
} }

View File

@@ -44,6 +44,7 @@ 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.notification.NotificationEntryManager;
import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.DelayableExecutor;
import org.junit.Before; import org.junit.Before;
@@ -91,6 +92,8 @@ public class QSPanelTest extends SysuiTestCase {
private LocalBluetoothManager mLocalBluetoothManager; private LocalBluetoothManager mLocalBluetoothManager;
@Mock @Mock
private ActivityStarter mActivityStarter; private ActivityStarter mActivityStarter;
@Mock
private NotificationEntryManager mEntryManager;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
@@ -101,7 +104,7 @@ public class QSPanelTest extends SysuiTestCase {
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, mForegroundExecutor, mBackgroundExecutor, mQSLogger, mForegroundExecutor, mBackgroundExecutor,
mLocalBluetoothManager, mActivityStarter); mLocalBluetoothManager, mActivityStarter, mEntryManager);
// 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);
mParentView.addView(mQsPanel); mParentView.addView(mQsPanel);