Stop relying on the local cache in KeyguardUpdateMonitor to determine whether user storage is locked.
SystemUI expects a broadcast with ACTION_USER_UNLOCKED intent action to update the state in the local cache.
From the recent bug reports it seems like SystemUI never receives the broadcast or misses it or something else is causing the cache to remain stale.
This CL changes the method to use UserManager#isUserUnlocked directly instead of relying on the cache. `UserManager` has an IPC data cache that would avoid repeated IPCs, making this change behind a flag to identify any performance regressions.
Flag: com.android.systemui.user_encrypted_source
Bug: 333656491
Test: verified manually, reboot device, see the `Unlock for all features and data` message on lock screen.
Change-Id: If15b8603aad4ec01fbcbdc3df105451d9e5802b4
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index 0938167..cb43fcf 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -26,6 +26,16 @@
}
flag {
+ name: "user_encrypted_source"
+ namespace: "systemui"
+ description: "Get rid of the local cache and rely on UserManager.isUserUnlocked directly to determine whether user CE storage is encrypted."
+ bug: "333656491"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
name: "modes_ui_dialog_paging"
namespace: "systemui"
description: "Add pagination to the Modes dialog in quick settings."
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
index 8b59370..eda07cf 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -121,6 +121,7 @@
import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.systemui.CoreStartable;
import com.android.systemui.Dumpable;
+import com.android.systemui.Flags;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProvider;
import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor;
@@ -473,6 +474,7 @@
}
}
+ @Deprecated
private final SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray();
private final SparseBooleanArray mUserHasTrust = new SparseBooleanArray();
private final SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray();
@@ -2688,7 +2690,13 @@
* @see Intent#ACTION_USER_UNLOCKED
*/
public boolean isUserUnlocked(int userId) {
- return mUserIsUnlocked.get(userId);
+ if (Flags.userEncryptedSource()) {
+ boolean userStorageUnlocked = mUserManager.isUserUnlocked(userId);
+ mLogger.logUserStorageUnlocked(userId, userStorageUnlocked);
+ return userStorageUnlocked;
+ } else {
+ return mUserIsUnlocked.get(userId);
+ }
}
/**
@@ -4213,7 +4221,7 @@
pw.println(" strongAuthFlags=" + Integer.toHexString(strongAuthFlags));
pw.println("ActiveUnlockRunning="
+ mTrustManager.isActiveUnlockRunning(mSelectedUserInteractor.getSelectedUserId()));
- pw.println("userUnlockedCache[userid=" + userId + "]=" + isUserUnlocked(userId));
+ pw.println("userUnlockedCache[userid=" + userId + "]=" + mUserIsUnlocked.get(userId));
pw.println("actualUserUnlocked[userid=" + userId + "]="
+ mUserManager.isUserUnlocked(userId));
new DumpsysTableLogger(
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
index bebfd85..cd19aaac 100644
--- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
+++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardLogger.kt
@@ -116,7 +116,7 @@
fun logUpdateLockScreenUserLockedMsg(
userId: Int,
- userUnlocked: Boolean,
+ userStorageUnlocked: Boolean,
encryptedOrLockdown: Boolean,
) {
buffer.log(
@@ -124,12 +124,12 @@
LogLevel.DEBUG,
{
int1 = userId
- bool1 = userUnlocked
+ bool1 = userStorageUnlocked
bool2 = encryptedOrLockdown
},
{
"updateLockScreenUserLockedMsg userId=$int1 " +
- "userUnlocked:$bool1 encryptedOrLockdown:$bool2"
+ "userStorageUnlocked:$bool1 encryptedOrLockdown:$bool2"
}
)
}
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
index 12fc3c2..b3ddde3 100644
--- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
+++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardUpdateMonitorLogger.kt
@@ -582,6 +582,18 @@
logBuffer.log(TAG, DEBUG, { int1 = userId }, { "userUnlocked userId: $int1" })
}
+ fun logUserStorageUnlocked(userId: Int, result: Boolean) {
+ logBuffer.log(
+ TAG,
+ DEBUG,
+ {
+ int1 = userId
+ bool1 = result
+ },
+ { "Invoked UserManager#isUserUnlocked $int1, result: $bool1" },
+ )
+ }
+
fun logUserStopped(userId: Int, isUnlocked: Boolean) {
logBuffer.log(
TAG,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
index 520cbf9..8c5a711 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
@@ -619,10 +619,11 @@
}
private void updateLockScreenUserLockedMsg(int userId) {
- boolean userUnlocked = mKeyguardUpdateMonitor.isUserUnlocked(userId);
+ boolean userStorageUnlocked = mKeyguardUpdateMonitor.isUserUnlocked(userId);
boolean encryptedOrLockdown = mKeyguardUpdateMonitor.isEncryptedOrLockdown(userId);
- mKeyguardLogger.logUpdateLockScreenUserLockedMsg(userId, userUnlocked, encryptedOrLockdown);
- if (!userUnlocked || encryptedOrLockdown) {
+ mKeyguardLogger.logUpdateLockScreenUserLockedMsg(userId, userStorageUnlocked,
+ encryptedOrLockdown);
+ if (!userStorageUnlocked || encryptedOrLockdown) {
mRotateTextViewController.updateIndication(
INDICATION_TYPE_USER_LOCKED,
new KeyguardIndication.Builder()