Merge "Fix issue where media would not expire" into rvc-dev

This commit is contained in:
Lucas Dupin
2020-05-26 02:50:38 +00:00
committed by Android (Google) Code Review

View File

@@ -36,6 +36,7 @@ import android.media.session.MediaSession;
import android.media.session.MediaSessionManager; import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState; import android.media.session.PlaybackState;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.SystemProperties;
import android.os.Trace; import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
@@ -90,7 +91,8 @@ import dagger.Lazy;
public class NotificationMediaManager implements Dumpable { public class NotificationMediaManager implements Dumpable {
private static final String TAG = "NotificationMediaManager"; private static final String TAG = "NotificationMediaManager";
public static final boolean DEBUG_MEDIA = false; public static final boolean DEBUG_MEDIA = false;
private static final long PAUSED_MEDIA_TIMEOUT = TimeUnit.MINUTES.toMillis(10); private static final long PAUSED_MEDIA_TIMEOUT = SystemProperties
.getLong("debug.sysui.media_timeout", TimeUnit.MINUTES.toMillis(10));
private final StatusBarStateController mStatusBarStateController private final StatusBarStateController mStatusBarStateController
= Dependency.get(StatusBarStateController.class); = Dependency.get(StatusBarStateController.class);
@@ -163,6 +165,9 @@ public class NotificationMediaManager implements Dumpable {
Log.v(TAG, "DEBUG_MEDIA: onPlaybackStateChanged: " + state); Log.v(TAG, "DEBUG_MEDIA: onPlaybackStateChanged: " + state);
} }
if (mMediaTimeoutCancellation != null) { if (mMediaTimeoutCancellation != null) {
if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: media timeout cancelled");
}
mMediaTimeoutCancellation.run(); mMediaTimeoutCancellation.run();
mMediaTimeoutCancellation = null; mMediaTimeoutCancellation = null;
} }
@@ -182,8 +187,16 @@ public class NotificationMediaManager implements Dumpable {
} }
if (entry != null) { if (entry != null) {
if (!isPlayingState(state.getState())) { if (!isPlayingState(state.getState())) {
if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: schedule timeout for "
+ mMediaNotificationKey);
}
mMediaTimeoutCancellation = mMainExecutor.executeDelayed(() -> { mMediaTimeoutCancellation = mMainExecutor.executeDelayed(() -> {
synchronized (mEntryManager) { synchronized (mEntryManager) {
if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: execute timeout for "
+ mMediaNotificationKey);
}
if (mMediaNotificationKey == null) { if (mMediaNotificationKey == null) {
return; return;
} }
@@ -375,21 +388,18 @@ public class NotificationMediaManager implements Dumpable {
UserHandle.USER_ALL); UserHandle.USER_ALL);
for (MediaController aController : sessions) { for (MediaController aController : sessions) {
if (PlaybackState.STATE_PLAYING == // now to see if we have one like this
getMediaControllerPlaybackState(aController)) { final String pkg = aController.getPackageName();
// now to see if we have one like this
final String pkg = aController.getPackageName();
for (NotificationEntry entry : allNotifications) { for (NotificationEntry entry : allNotifications) {
if (entry.getSbn().getPackageName().equals(pkg)) { if (entry.getSbn().getPackageName().equals(pkg)) {
if (DEBUG_MEDIA) { if (DEBUG_MEDIA) {
Log.v(TAG, "DEBUG_MEDIA: found controller matching " Log.v(TAG, "DEBUG_MEDIA: found controller matching "
+ entry.getSbn().getKey()); + entry.getSbn().getKey());
}
controller = aController;
mediaNotification = entry;
break;
} }
controller = aController;
mediaNotification = entry;
break;
} }
} }
} }