From beee8633668e9ccfec90bc34d772f270e9290242 Mon Sep 17 00:00:00 2001 From: Curtis Belmonte Date: Fri, 26 Jun 2020 13:49:36 -0700 Subject: [PATCH] Don't call setKeyguardGoingAway on background thread Ensures that KeyguardUpdateMonitor#setKeyguardGoingAway(boolean) is never called on a background thread by dispatching a message to be handled by KeyguardUpdateMonitor on the main thread. Test: Manually on Pixel 4 XL Test: atest com.android.systemui.keyguard Fixes: 159778563 Change-Id: I48512c0dffba6082f62e70d169f1374c36eead8b --- .../keyguard/KeyguardUpdateMonitor.java | 20 ++++++++++++++++++- .../keyguard/KeyguardViewMediator.java | 2 +- .../keyguard/KeyguardViewMediatorTest.java | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index ee31706c0b94a..e4dbb1dbf2167 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -177,6 +177,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private static final int MSG_TIMEZONE_UPDATE = 339; private static final int MSG_USER_STOPPED = 340; private static final int MSG_USER_REMOVED = 341; + private static final int MSG_KEYGUARD_GOING_AWAY = 342; /** Biometric authentication state: Not listening. */ private static final int BIOMETRIC_STATE_STOPPED = 0; @@ -531,7 +532,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } /** - * Updates KeyguardUpdateMonitor's internal state to know if keyguard is goingAway + * Updates KeyguardUpdateMonitor's internal state to know if keyguard is going away. */ public void setKeyguardGoingAway(boolean goingAway) { mKeyguardGoingAway = goingAway; @@ -1521,6 +1522,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mUserTrustIsUsuallyManaged.delete(userId); } + private void handleKeyguardGoingAway(boolean goingAway) { + Assert.isMainThread(); + setKeyguardGoingAway(goingAway); + } + @VisibleForTesting protected void setStrongAuthTracker(@NonNull StrongAuthTracker tracker) { if (mStrongAuthTracker != null) { @@ -1661,6 +1667,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab case MSG_TELEPHONY_CAPABLE: updateTelephonyCapable((boolean) msg.obj); break; + case MSG_KEYGUARD_GOING_AWAY: + handleKeyguardGoingAway((boolean) msg.obj); + break; default: super.handleMessage(msg); break; @@ -2802,6 +2811,15 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mHandler.sendMessage(mHandler.obtainMessage(MSG_DREAMING_STATE_CHANGED, 0, 0)); } + /** + * Sends a message to update the keyguard going away state on the main thread. + * + * @param goingAway Whether the keyguard is going away. + */ + public void dispatchKeyguardGoingAway(boolean goingAway) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_KEYGUARD_GOING_AWAY, goingAway)); + } + public boolean isDeviceInteractive() { return mDeviceInteractive; } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 53251ed4362de..6b5c8807fbd43 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -876,7 +876,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable { // explicitly DO NOT want to call // mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(false) // here, since that will mess with the device lock state. - mUpdateMonitor.setKeyguardGoingAway(false); + mUpdateMonitor.dispatchKeyguardGoingAway(false); // Lock immediately based on setting if secure (user has a pin/pattern/password). // This also "locks" the device when not secure to provide easy access to the diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java index 24b128af9fbd2..90e9ef4e9c561 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java @@ -95,7 +95,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { @Test public void testOnGoingToSleep_UpdatesKeyguardGoingAway() { mViewMediator.onStartedGoingToSleep(OFF_BECAUSE_OF_USER); - verify(mUpdateMonitor).setKeyguardGoingAway(false); + verify(mUpdateMonitor).dispatchKeyguardGoingAway(false); verify(mStatusBarKeyguardViewManager, never()).setKeyguardGoingAwayState(anyBoolean()); }