Fix PiP disappearance after unlock

KeyguardUpdateMonitor uses WeakReference internally for all the
registered callbacks, therefore an anonymous class may be released and
unable to receive any callback after registration.

Changed also the ConfigurationListener and
KeyguardStateController.Callback in WMShell.

Bug: 241249835
Test: repeatedly lock and unlock device with PiP being present
Change-Id: I1c3ea269ee9955847212bebbebdd0d7130dbdce5
This commit is contained in:
Hongwei Wang
2022-08-04 13:32:57 -07:00
parent 165f760907
commit a2cedf9ce5

View File

@@ -118,6 +118,33 @@ public final class WMShell extends CoreStartable
private final UserInfoController mUserInfoController;
private final Executor mSysUiMainExecutor;
// Listeners and callbacks. Note that we prefer member variable over anonymous class here to
// avoid the situation that some implementations, like KeyguardUpdateMonitor, use WeakReference
// internally and anonymous class could be released after registration.
private final ConfigurationController.ConfigurationListener mConfigurationListener =
new ConfigurationController.ConfigurationListener() {
@Override
public void onConfigChanged(Configuration newConfig) {
mShell.onConfigurationChanged(newConfig);
}
};
private final KeyguardStateController.Callback mKeyguardStateCallback =
new KeyguardStateController.Callback() {
@Override
public void onKeyguardShowingChanged() {
mShell.onKeyguardVisibilityChanged(mKeyguardStateController.isShowing(),
mKeyguardStateController.isOccluded(),
mKeyguardStateController.isAnimatingBetweenKeyguardAndSurfaceBehind());
}
};
private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
new KeyguardUpdateMonitorCallback() {
@Override
public void onKeyguardDismissAnimationFinished() {
mShell.onKeyguardDismissAnimationFinished();
}
};
private boolean mIsSysUiStateValid;
private KeyguardUpdateMonitorCallback mOneHandedKeyguardCallback;
private WakefulnessLifecycle.Observer mWakefulnessObserver;
@@ -159,28 +186,11 @@ public final class WMShell extends CoreStartable
public void start() {
// Notify with the initial configuration and subscribe for new config changes
mShell.onConfigurationChanged(mContext.getResources().getConfiguration());
mConfigurationController.addCallback(new ConfigurationController.ConfigurationListener() {
@Override
public void onConfigChanged(Configuration newConfig) {
mShell.onConfigurationChanged(newConfig);
}
});
mConfigurationController.addCallback(mConfigurationListener);
// Subscribe to keyguard changes
mKeyguardStateController.addCallback(new KeyguardStateController.Callback() {
@Override
public void onKeyguardShowingChanged() {
mShell.onKeyguardVisibilityChanged(mKeyguardStateController.isShowing(),
mKeyguardStateController.isOccluded(),
mKeyguardStateController.isAnimatingBetweenKeyguardAndSurfaceBehind());
}
});
mKeyguardUpdateMonitor.registerCallback(new KeyguardUpdateMonitorCallback() {
@Override
public void onKeyguardDismissAnimationFinished() {
mShell.onKeyguardDismissAnimationFinished();
}
});
mKeyguardStateController.addCallback(mKeyguardStateCallback);
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
// TODO: Consider piping config change and other common calls to a shell component to
// delegate internally