Loading packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +50 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.keyguard; import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; import static android.content.Intent.ACTION_USER_REMOVED; import static android.content.Intent.ACTION_USER_STOPPED; import static android.content.Intent.ACTION_USER_UNLOCKED; import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; import static android.os.BatteryManager.BATTERY_STATUS_FULL; Loading Loading @@ -162,6 +164,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private static final int MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED = 337; private static final int MSG_TELEPHONY_CAPABLE = 338; private static final int MSG_TIMEZONE_UPDATE = 339; private static final int MSG_USER_STOPPED = 340; private static final int MSG_USER_REMOVED = 341; /** Biometric authentication state: Not listening. */ private static final int BIOMETRIC_STATE_STOPPED = 0; Loading Loading @@ -375,7 +379,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { handleDreamingStateChanged(msg.arg1); break; case MSG_USER_UNLOCKED: handleUserUnlocked(); handleUserUnlocked(msg.arg1); break; case MSG_USER_STOPPED: handleUserStopped(msg.arg1); break; case MSG_USER_REMOVED: handleUserRemoved(msg.arg1); break; case MSG_ASSISTANT_STACK_CHANGED: setAssistantVisible((boolean) msg.obj); Loading Loading @@ -427,6 +437,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } }; private SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray(); private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); Loading Loading @@ -1207,7 +1218,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { .equals(action)) { mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); } else if (ACTION_USER_UNLOCKED.equals(action)) { mHandler.sendEmptyMessage(MSG_USER_UNLOCKED); mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_UNLOCKED, getSendingUserId(), 0)); } else if (ACTION_USER_STOPPED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_STOPPED, intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); } else if (ACTION_USER_REMOVED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED, intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); } } }; Loading Loading @@ -1558,8 +1576,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } private void handleUserUnlocked() { private void handleUserUnlocked(int userId) { checkIsHandlerThread(); mUserIsUnlocked.put(userId, true); mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); Loading @@ -1569,6 +1588,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } private void handleUserStopped(int userId) { checkIsHandlerThread(); mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId)); } private void handleUserRemoved(int userId) { checkIsHandlerThread(); mUserIsUnlocked.delete(userId); } @VisibleForTesting protected KeyguardUpdateMonitor(Context context) { mContext = context; Loading Loading @@ -1612,6 +1641,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); allUserFilter.addAction(ACTION_USER_UNLOCKED); allUserFilter.addAction(ACTION_USER_STOPPED); allUserFilter.addAction(ACTION_USER_REMOVED); context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, null, mHandler); Loading Loading @@ -1666,6 +1697,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); mUserManager = context.getSystemService(UserManager.class); mIsPrimaryUser = mUserManager.isPrimaryUser(); int user = ActivityManager.getCurrentUser(); mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user)); mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled(); updateAirplaneModeState(); Loading Loading @@ -1708,6 +1741,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } /** * If a user is encrypted or not. * This is NOT related to the lock screen being visible or not. * * @param userId The user. * @return {@code true} when encrypted. * @see UserManager#isUserUnlocked() * @see Intent#ACTION_USER_UNLOCKED */ public boolean isUserUnlocked(int userId) { return mUserIsUnlocked.get(userId); } /** * Called whenever passive authentication is requested or aborted by a sensor. * Loading Loading @@ -2297,7 +2343,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } private boolean resolveNeedsSlowUnlockTransition() { if (mUserManager.isUserUnlocked(getCurrentUser())) { if (isUserUnlocked(getCurrentUser())) { return false; } Intent homeIntent = new Intent(Intent.ACTION_MAIN) Loading packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +8 −2 Original line number Diff line number Diff line Loading @@ -384,8 +384,7 @@ public class KeyguardIndicationController implements StateListener, int userId = KeyguardUpdateMonitor.getCurrentUser(); String trustGrantedIndication = getTrustGrantedIndication(); String trustManagedIndication = getTrustManagedIndication(); // TODO(b/140053632) if (!whitelistIpcs(() -> mUserManager.isUserUnlocked(userId))) { if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mTransientIndication)) { Loading Loading @@ -756,6 +755,13 @@ public class KeyguardIndicationController implements StateListener, mHandler.sendEmptyMessage(MSG_HIDE_TRANSIENT); } @Override public void onUserSwitchComplete(int userId) { if (mVisible) { updateIndication(false); } } @Override public void onUserUnlocked() { if (mVisible) { Loading packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -477,6 +477,16 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { assertThat(listToVerify.get(0)).isEqualTo(TEST_SUBSCRIPTION_2); } @Test public void testIsUserUnlocked() { // mUserManager will report the user as unlocked on @Before assertThat(mKeyguardUpdateMonitor.isUserUnlocked(KeyguardUpdateMonitor.getCurrentUser())) .isTrue(); // Invalid user should not be unlocked. int randomUser = 99; assertThat(mKeyguardUpdateMonitor.isUserUnlocked(randomUser)).isFalse(); } private Intent putPhoneInfo(Intent intent, Bundle data, Boolean simInited) { int subscription = simInited ? 1/* mock subid=1 */ : SubscriptionManager.DUMMY_SUBSCRIPTION_ID_BASE; Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -268,12 +268,18 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { public void unlockMethodCache_listenerUpdatesIndication() { createController(); String restingIndication = "Resting indication"; mController.setVisible(true); assertThat(mTextView.getText()).isEqualTo( mContext.getString(com.android.internal.R.string.lockscreen_storage_locked)); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); mController.setRestingIndication(restingIndication); mController.setVisible(true); assertThat(mTextView.getText()).isEqualTo(mController.getTrustGrantedIndication()); reset(mKeyguardUpdateMonitor); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false); mController.onUnlockMethodStateChanged(); assertThat(mTextView.getText()).isEqualTo(restingIndication); Loading Loading
packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +50 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.keyguard; import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; import static android.content.Intent.ACTION_USER_REMOVED; import static android.content.Intent.ACTION_USER_STOPPED; import static android.content.Intent.ACTION_USER_UNLOCKED; import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN; import static android.os.BatteryManager.BATTERY_STATUS_FULL; Loading Loading @@ -162,6 +164,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private static final int MSG_DEVICE_POLICY_MANAGER_STATE_CHANGED = 337; private static final int MSG_TELEPHONY_CAPABLE = 338; private static final int MSG_TIMEZONE_UPDATE = 339; private static final int MSG_USER_STOPPED = 340; private static final int MSG_USER_REMOVED = 341; /** Biometric authentication state: Not listening. */ private static final int BIOMETRIC_STATE_STOPPED = 0; Loading Loading @@ -375,7 +379,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { handleDreamingStateChanged(msg.arg1); break; case MSG_USER_UNLOCKED: handleUserUnlocked(); handleUserUnlocked(msg.arg1); break; case MSG_USER_STOPPED: handleUserStopped(msg.arg1); break; case MSG_USER_REMOVED: handleUserRemoved(msg.arg1); break; case MSG_ASSISTANT_STACK_CHANGED: setAssistantVisible((boolean) msg.obj); Loading Loading @@ -427,6 +437,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } }; private SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray(); private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray(); Loading Loading @@ -1207,7 +1218,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { .equals(action)) { mHandler.sendEmptyMessage(MSG_DPM_STATE_CHANGED); } else if (ACTION_USER_UNLOCKED.equals(action)) { mHandler.sendEmptyMessage(MSG_USER_UNLOCKED); mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_UNLOCKED, getSendingUserId(), 0)); } else if (ACTION_USER_STOPPED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_STOPPED, intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); } else if (ACTION_USER_REMOVED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED, intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1), 0)); } } }; Loading Loading @@ -1558,8 +1576,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } private void handleUserUnlocked() { private void handleUserUnlocked(int userId) { checkIsHandlerThread(); mUserIsUnlocked.put(userId, true); mNeedsSlowUnlockTransition = resolveNeedsSlowUnlockTransition(); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); Loading @@ -1569,6 +1588,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } private void handleUserStopped(int userId) { checkIsHandlerThread(); mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId)); } private void handleUserRemoved(int userId) { checkIsHandlerThread(); mUserIsUnlocked.delete(userId); } @VisibleForTesting protected KeyguardUpdateMonitor(Context context) { mContext = context; Loading Loading @@ -1612,6 +1641,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { allUserFilter.addAction(ACTION_FACE_UNLOCK_STOPPED); allUserFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); allUserFilter.addAction(ACTION_USER_UNLOCKED); allUserFilter.addAction(ACTION_USER_STOPPED); allUserFilter.addAction(ACTION_USER_REMOVED); context.registerReceiverAsUser(mBroadcastAllReceiver, UserHandle.ALL, allUserFilter, null, mHandler); Loading Loading @@ -1666,6 +1697,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); mUserManager = context.getSystemService(UserManager.class); mIsPrimaryUser = mUserManager.isPrimaryUser(); int user = ActivityManager.getCurrentUser(); mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user)); mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled(); updateAirplaneModeState(); Loading Loading @@ -1708,6 +1741,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } /** * If a user is encrypted or not. * This is NOT related to the lock screen being visible or not. * * @param userId The user. * @return {@code true} when encrypted. * @see UserManager#isUserUnlocked() * @see Intent#ACTION_USER_UNLOCKED */ public boolean isUserUnlocked(int userId) { return mUserIsUnlocked.get(userId); } /** * Called whenever passive authentication is requested or aborted by a sensor. * Loading Loading @@ -2297,7 +2343,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } private boolean resolveNeedsSlowUnlockTransition() { if (mUserManager.isUserUnlocked(getCurrentUser())) { if (isUserUnlocked(getCurrentUser())) { return false; } Intent homeIntent = new Intent(Intent.ACTION_MAIN) Loading
packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +8 −2 Original line number Diff line number Diff line Loading @@ -384,8 +384,7 @@ public class KeyguardIndicationController implements StateListener, int userId = KeyguardUpdateMonitor.getCurrentUser(); String trustGrantedIndication = getTrustGrantedIndication(); String trustManagedIndication = getTrustManagedIndication(); // TODO(b/140053632) if (!whitelistIpcs(() -> mUserManager.isUserUnlocked(userId))) { if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mTransientIndication)) { Loading Loading @@ -756,6 +755,13 @@ public class KeyguardIndicationController implements StateListener, mHandler.sendEmptyMessage(MSG_HIDE_TRANSIENT); } @Override public void onUserSwitchComplete(int userId) { if (mVisible) { updateIndication(false); } } @Override public void onUserUnlocked() { if (mVisible) { Loading
packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -477,6 +477,16 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { assertThat(listToVerify.get(0)).isEqualTo(TEST_SUBSCRIPTION_2); } @Test public void testIsUserUnlocked() { // mUserManager will report the user as unlocked on @Before assertThat(mKeyguardUpdateMonitor.isUserUnlocked(KeyguardUpdateMonitor.getCurrentUser())) .isTrue(); // Invalid user should not be unlocked. int randomUser = 99; assertThat(mKeyguardUpdateMonitor.isUserUnlocked(randomUser)).isFalse(); } private Intent putPhoneInfo(Intent intent, Bundle data, Boolean simInited) { int subscription = simInited ? 1/* mock subid=1 */ : SubscriptionManager.DUMMY_SUBSCRIPTION_ID_BASE; Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -268,12 +268,18 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { public void unlockMethodCache_listenerUpdatesIndication() { createController(); String restingIndication = "Resting indication"; mController.setVisible(true); assertThat(mTextView.getText()).isEqualTo( mContext.getString(com.android.internal.R.string.lockscreen_storage_locked)); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); mController.setRestingIndication(restingIndication); mController.setVisible(true); assertThat(mTextView.getText()).isEqualTo(mController.getTrustGrantedIndication()); reset(mKeyguardUpdateMonitor); when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false); mController.onUnlockMethodStateChanged(); assertThat(mTextView.getText()).isEqualTo(restingIndication); Loading