Merge "Use unique Handler for media, and synchronize it" into qt-qpr1-dev
am: fd6f170e31
Change-Id: I794799d85e407cdd110f9a72a061b1250443ce09
This commit is contained in:
@@ -49,6 +49,7 @@ import androidx.slice.builders.SliceAction;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||||
|
import com.android.systemui.Dependency;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||||
import com.android.systemui.statusbar.NotificationMediaManager;
|
import com.android.systemui.statusbar.NotificationMediaManager;
|
||||||
@@ -58,7 +59,6 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
|||||||
import com.android.systemui.statusbar.policy.NextAlarmController;
|
import com.android.systemui.statusbar.policy.NextAlarmController;
|
||||||
import com.android.systemui.statusbar.policy.NextAlarmControllerImpl;
|
import com.android.systemui.statusbar.policy.NextAlarmControllerImpl;
|
||||||
import com.android.systemui.statusbar.policy.ZenModeController;
|
import com.android.systemui.statusbar.policy.ZenModeController;
|
||||||
import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
|
|
||||||
import com.android.systemui.util.wakelock.SettableWakeLock;
|
import com.android.systemui.util.wakelock.SettableWakeLock;
|
||||||
import com.android.systemui.util.wakelock.WakeLock;
|
import com.android.systemui.util.wakelock.WakeLock;
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
|
|||||||
protected final Uri mMediaUri;
|
protected final Uri mMediaUri;
|
||||||
private final Date mCurrentTime = new Date();
|
private final Date mCurrentTime = new Date();
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
private final Handler mMediaHandler;
|
||||||
private final AlarmManager.OnAlarmListener mUpdateNextAlarm = this::updateNextAlarm;
|
private final AlarmManager.OnAlarmListener mUpdateNextAlarm = this::updateNextAlarm;
|
||||||
private final Object mMediaToken = new Object();
|
|
||||||
private DozeParameters mDozeParameters;
|
private DozeParameters mDozeParameters;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected SettableWakeLock mMediaWakeLock;
|
protected SettableWakeLock mMediaWakeLock;
|
||||||
@@ -169,17 +169,13 @@ public class KeyguardSliceProvider extends SliceProvider implements
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public KeyguardSliceProvider() {
|
|
||||||
this(new Handler());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeyguardSliceProvider getAttachedInstance() {
|
public static KeyguardSliceProvider getAttachedInstance() {
|
||||||
return KeyguardSliceProvider.sInstance;
|
return KeyguardSliceProvider.sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
public KeyguardSliceProvider() {
|
||||||
KeyguardSliceProvider(Handler handler) {
|
mHandler = new Handler();
|
||||||
mHandler = handler;
|
mMediaHandler = new Handler();
|
||||||
mSliceUri = Uri.parse(KEYGUARD_SLICE_URI);
|
mSliceUri = Uri.parse(KEYGUARD_SLICE_URI);
|
||||||
mHeaderUri = Uri.parse(KEYGUARD_HEADER_URI);
|
mHeaderUri = Uri.parse(KEYGUARD_HEADER_URI);
|
||||||
mDateUri = Uri.parse(KEYGUARD_DATE_URI);
|
mDateUri = Uri.parse(KEYGUARD_DATE_URI);
|
||||||
@@ -320,7 +316,7 @@ public class KeyguardSliceProvider extends SliceProvider implements
|
|||||||
mContentResolver = getContext().getContentResolver();
|
mContentResolver = getContext().getContentResolver();
|
||||||
mNextAlarmController = new NextAlarmControllerImpl(getContext());
|
mNextAlarmController = new NextAlarmControllerImpl(getContext());
|
||||||
mNextAlarmController.addCallback(this);
|
mNextAlarmController.addCallback(this);
|
||||||
mZenModeController = new ZenModeControllerImpl(getContext(), mHandler);
|
mZenModeController = Dependency.get(ZenModeController.class);
|
||||||
mZenModeController.addCallback(this);
|
mZenModeController.addCallback(this);
|
||||||
mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
|
mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
|
||||||
mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
|
mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
|
||||||
@@ -462,16 +458,18 @@ public class KeyguardSliceProvider extends SliceProvider implements
|
|||||||
public void onMetadataOrStateChanged(MediaMetadata metadata, @PlaybackState.State int state) {
|
public void onMetadataOrStateChanged(MediaMetadata metadata, @PlaybackState.State int state) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
boolean nextVisible = NotificationMediaManager.isPlayingState(state);
|
boolean nextVisible = NotificationMediaManager.isPlayingState(state);
|
||||||
mHandler.removeCallbacksAndMessages(mMediaToken);
|
mMediaHandler.removeCallbacksAndMessages(null);
|
||||||
if (mMediaIsVisible && !nextVisible && mStatusBarState != StatusBarState.SHADE) {
|
if (mMediaIsVisible && !nextVisible && mStatusBarState != StatusBarState.SHADE) {
|
||||||
// We need to delay this event for a few millis when stopping to avoid jank in the
|
// We need to delay this event for a few millis when stopping to avoid jank in the
|
||||||
// animation. The media app might not send its update when buffering, and the slice
|
// animation. The media app might not send its update when buffering, and the slice
|
||||||
// would end up without a header for 0.5 second.
|
// would end up without a header for 0.5 second.
|
||||||
mMediaWakeLock.setAcquired(true);
|
mMediaWakeLock.setAcquired(true);
|
||||||
mHandler.postDelayed(() -> {
|
mMediaHandler.postDelayed(() -> {
|
||||||
|
synchronized (this) {
|
||||||
updateMediaStateLocked(metadata, state);
|
updateMediaStateLocked(metadata, state);
|
||||||
mMediaWakeLock.setAcquired(false);
|
mMediaWakeLock.setAcquired(false);
|
||||||
}, mMediaToken, 2000);
|
}
|
||||||
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
mMediaWakeLock.setAcquired(false);
|
mMediaWakeLock.setAcquired(false);
|
||||||
updateMediaStateLocked(metadata, state);
|
updateMediaStateLocked(metadata, state);
|
||||||
|
|||||||
Reference in New Issue
Block a user