From a2cedf9ce53e9aaa098c955b3e349b1c5c68650d Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 4 Aug 2022 13:32:57 -0700 Subject: [PATCH] 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 --- .../com/android/systemui/wmshell/WMShell.java | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index 12597e0896b1a..eba2795876294 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -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