From a3420c7f707b07e33bdb9f5aba65f3b8f9d72911 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Mon, 13 May 2019 17:54:25 -0700 Subject: [PATCH] Remove lousy synchronization An @AnyThread method was being used for syncrhonizing user switching states without having a synchronization block. We were also relying on callbacks that might be unordered, especially during user switching. Fixes: 131914931 Test: switch between users that have different dark mode settings Change-Id: Ie85c2a2a087edcd35c825caf8193aeabb990ea6c --- .../keyguard/KeyguardUpdateMonitor.java | 20 ++++++++++------ .../phone/StatusBarNotificationPresenter.java | 23 ++----------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index dd6ccb2b3a88b..6402884fcc0f3 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1608,23 +1608,31 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } private boolean shouldListenForFingerprint() { + final boolean switchingUsers; + synchronized (this) { + switchingUsers = mSwitchingUser; + } // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware. final boolean shouldListen = (mKeyguardIsVisible || !mDeviceInteractive || (mBouncer && !mKeyguardGoingAway) || mGoingToSleep || shouldListenForFingerprintAssistant() || (mKeyguardOccluded && mIsDreaming)) - && !mSwitchingUser && !isFingerprintDisabled(getCurrentUser()) + && !switchingUsers && !isFingerprintDisabled(getCurrentUser()) && (!mKeyguardGoingAway || !mDeviceInteractive) && mIsPrimaryUser; return shouldListen; } private boolean shouldListenForFace() { + final boolean switchingUsers; + synchronized (this) { + switchingUsers = mSwitchingUser; + } final boolean awakeKeyguard = mKeyguardIsVisible && mDeviceInteractive && !mGoingToSleep; final int user = getCurrentUser(); // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware. return (mBouncer || mAuthInterruptActive || awakeKeyguard || shouldListenForFaceAssistant()) - && !mSwitchingUser && !getUserCanSkipBouncer(user) && !isFaceDisabled(user) + && !switchingUsers && !getUserCanSkipBouncer(user) && !isFaceDisabled(user) && !mKeyguardGoingAway && mFaceSettingEnabledForUser && mUserManager.isUserUnlocked(user) && mIsPrimaryUser; } @@ -2180,13 +2188,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { sendUpdates(callback); } - public boolean isSwitchingUser() { - return mSwitchingUser; - } - @AnyThread public void setSwitchingUser(boolean switching) { - mSwitchingUser = switching; + synchronized (this) { + mSwitchingUser = switching; + } // Since this comes in on a binder thread, we need to post if first mHandler.post(mUpdateBiometricListeningState); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java index 6fe89645ef198..b6f95b83cf44e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java @@ -41,7 +41,6 @@ import com.android.internal.statusbar.IStatusBarService; import com.android.internal.statusbar.NotificationVisibility; import com.android.internal.widget.MessagingGroup; import com.android.internal.widget.MessagingMessage; -import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.Dependency; import com.android.systemui.ForegroundServiceNotificationListener; import com.android.systemui.InitController; @@ -122,8 +121,6 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; private final int mMaxAllowedKeyguardNotifications; private final IStatusBarService mBarService; - private boolean mReinflateNotificationsOnUserSwitched; - private boolean mDispatchUiModeChangeOnUserSwitched; private final UnlockMethodCache mUnlockMethodCache; private TextView mNotificationPanelDebugText; @@ -242,20 +239,12 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, public void onDensityOrFontScaleChanged() { MessagingMessage.dropCache(); MessagingGroup.dropCache(); - if (!KeyguardUpdateMonitor.getInstance(mContext).isSwitchingUser()) { - updateNotificationsOnDensityOrFontScaleChanged(); - } else { - mReinflateNotificationsOnUserSwitched = true; - } + updateNotificationsOnDensityOrFontScaleChanged(); } @Override public void onUiModeChanged() { - if (!KeyguardUpdateMonitor.getInstance(mContext).isSwitchingUser()) { - updateNotificationOnUiModeChanged(); - } else { - mDispatchUiModeChangeOnUserSwitched = true; - } + updateNotificationOnUiModeChanged(); } @Override @@ -385,14 +374,6 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, // End old BaseStatusBar.userSwitched if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId); mCommandQueue.animateCollapsePanels(); - if (mReinflateNotificationsOnUserSwitched) { - updateNotificationsOnDensityOrFontScaleChanged(); - mReinflateNotificationsOnUserSwitched = false; - } - if (mDispatchUiModeChangeOnUserSwitched) { - updateNotificationOnUiModeChanged(); - mDispatchUiModeChangeOnUserSwitched = false; - } updateNotificationViews(); mMediaManager.clearCurrentMediaNotification(); mShadeController.setLockscreenUser(newUserId);