summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-01-09 09:42:45 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-09 09:42:45 -0800
commit629ca982b457e739c69f81c5ce8f213dd4877e5c (patch)
tree6f673dfad20751589875646d9e801b9cfc79978d
parentb4514b69df0752dfe7e9b0b3239e9f2832649b11 (diff)
parent980154532a0eced21de9a48d366dd3704a925107 (diff)
Merge "Remove calling dismissKeyguard from UserController in switch-user flow." into main
-rw-r--r--services/core/java/com/android/server/am/UserController.java76
-rw-r--r--services/tests/servicestests/src/com/android/server/am/UserControllerTest.java28
2 files changed, 13 insertions, 91 deletions
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index ec74f60539a2..9f302fed626f 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -125,7 +125,6 @@ import android.view.Display;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.ObjectUtils;
@@ -161,7 +160,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
-import java.util.function.Consumer;
/**
* Helper class for {@link ActivityManagerService} responsible for multi-user functionality.
@@ -227,14 +225,6 @@ class UserController implements Handler.Callback {
private static final int USER_SWITCH_CALLBACKS_TIMEOUT_MS = 5 * 1000;
/**
- * Amount of time waited for {@link WindowManagerService#dismissKeyguard} callbacks to be
- * called after dismissing the keyguard.
- * Otherwise, we should move on to dismiss the dialog {@link #dismissUserSwitchDialog()}
- * and report user switch is complete {@link #REPORT_USER_SWITCH_COMPLETE_MSG}.
- */
- private static final int DISMISS_KEYGUARD_TIMEOUT_MS = 2 * 1000;
-
- /**
* Time after last scheduleOnUserCompletedEvent() call at which USER_COMPLETED_EVENT_MSG will be
* scheduled (although it may fire sooner instead).
* When it fires, {@link #reportOnUserCompletedEvent} will be processed.
@@ -2010,7 +2000,7 @@ class UserController implements Handler.Callback {
mInjector.getWindowManager().setSwitchingUser(true);
// Only lock if the user has a secure keyguard PIN/Pattern/Pwd
if (mInjector.getKeyguardManager().isDeviceSecure(userId)) {
- // Make sure the device is locked before moving on with the user switch
+ Slogf.d(TAG, "Locking the device before moving on with the user switch");
mInjector.lockDeviceNowAndWaitForKeyguardShown();
}
}
@@ -2640,7 +2630,7 @@ class UserController implements Handler.Callback {
EventLog.writeEvent(EventLogTags.UC_CONTINUE_USER_SWITCH, oldUserId, newUserId);
- // Do the keyguard dismiss and dismiss the user switching dialog later
+ // Dismiss the user switching dialog and complete the user switch
mHandler.removeMessages(COMPLETE_USER_SWITCH_MSG);
mHandler.sendMessage(mHandler.obtainMessage(
COMPLETE_USER_SWITCH_MSG, oldUserId, newUserId));
@@ -2655,31 +2645,17 @@ class UserController implements Handler.Callback {
@VisibleForTesting
void completeUserSwitch(int oldUserId, int newUserId) {
- final boolean isUserSwitchUiEnabled = isUserSwitchUiEnabled();
- // serialize each conditional step
- await(
- // STEP 1 - If there is no challenge set, dismiss the keyguard right away
- isUserSwitchUiEnabled && !mInjector.getKeyguardManager().isDeviceSecure(newUserId),
- mInjector::dismissKeyguard,
- () -> await(
- // STEP 2 - If user switch ui was enabled, dismiss user switch dialog
- isUserSwitchUiEnabled,
- this::dismissUserSwitchDialog,
- () -> {
- // STEP 3 - Send REPORT_USER_SWITCH_COMPLETE_MSG to broadcast
- // ACTION_USER_SWITCHED & call UserSwitchObservers.onUserSwitchComplete
- mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG);
- mHandler.sendMessage(mHandler.obtainMessage(
- REPORT_USER_SWITCH_COMPLETE_MSG, oldUserId, newUserId));
- }
- ));
- }
-
- private void await(boolean condition, Consumer<Runnable> conditionalStep, Runnable nextStep) {
- if (condition) {
- conditionalStep.accept(nextStep);
+ final Runnable runnable = () -> {
+ // Send REPORT_USER_SWITCH_COMPLETE_MSG to broadcast ACTION_USER_SWITCHED and call
+ // onUserSwitchComplete on UserSwitchObservers.
+ mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG);
+ mHandler.sendMessage(mHandler.obtainMessage(
+ REPORT_USER_SWITCH_COMPLETE_MSG, oldUserId, newUserId));
+ };
+ if (isUserSwitchUiEnabled()) {
+ dismissUserSwitchDialog(runnable);
} else {
- nextStep.run();
+ runnable.run();
}
}
@@ -4127,33 +4103,6 @@ class UserController implements Handler.Callback {
return IStorageManager.Stub.asInterface(ServiceManager.getService("mount"));
}
- protected void dismissKeyguard(Runnable runnable) {
- final AtomicBoolean isFirst = new AtomicBoolean(true);
- final Runnable runOnce = () -> {
- if (isFirst.getAndSet(false)) {
- runnable.run();
- }
- };
-
- mHandler.postDelayed(runOnce, DISMISS_KEYGUARD_TIMEOUT_MS);
- getWindowManager().dismissKeyguard(new IKeyguardDismissCallback.Stub() {
- @Override
- public void onDismissError() throws RemoteException {
- mHandler.post(runOnce);
- }
-
- @Override
- public void onDismissSucceeded() throws RemoteException {
- mHandler.post(runOnce);
- }
-
- @Override
- public void onDismissCancelled() throws RemoteException {
- mHandler.post(runOnce);
- }
- }, /* message= */ null);
- }
-
boolean isHeadlessSystemUserMode() {
return UserManager.isHeadlessSystemUserMode();
}
@@ -4178,6 +4127,7 @@ class UserController implements Handler.Callback {
void lockDeviceNowAndWaitForKeyguardShown() {
if (getWindowManager().isKeyguardLocked()) {
+ Slogf.w(TAG, "Not locking the device since the keyguard is already locked");
return;
}
diff --git a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
index 6411463fe0d9..06958b81d846 100644
--- a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
@@ -490,29 +490,6 @@ public class UserControllerTest {
mInjector.mHandler.clearAllRecordedMessages();
// Verify that continueUserSwitch worked as expected
continueAndCompleteUserSwitch(userState, oldUserId, newUserId);
- verify(mInjector, times(0)).dismissKeyguard(any());
- verify(mInjector, times(1)).dismissUserSwitchingDialog(any());
- continueUserSwitchAssertions(oldUserId, TEST_USER_ID, false, false);
- verifySystemUserVisibilityChangesNeverNotified();
- }
-
- @Test
- public void testContinueUserSwitchDismissKeyguard() {
- when(mInjector.mKeyguardManagerMock.isDeviceSecure(anyInt())).thenReturn(false);
- mUserController.setInitialConfig(/* userSwitchUiEnabled= */ true,
- /* maxRunningUsers= */ 3, /* delayUserDataLocking= */ false,
- /* backgroundUserScheduledStopTimeSecs= */ -1);
- // Start user -- this will update state of mUserController
- mUserController.startUser(TEST_USER_ID, USER_START_MODE_FOREGROUND);
- Message reportMsg = mInjector.mHandler.getMessageForCode(REPORT_USER_SWITCH_MSG);
- assertNotNull(reportMsg);
- UserState userState = (UserState) reportMsg.obj;
- int oldUserId = reportMsg.arg1;
- int newUserId = reportMsg.arg2;
- mInjector.mHandler.clearAllRecordedMessages();
- // Verify that continueUserSwitch worked as expected
- continueAndCompleteUserSwitch(userState, oldUserId, newUserId);
- verify(mInjector, times(1)).dismissKeyguard(any());
verify(mInjector, times(1)).dismissUserSwitchingDialog(any());
continueUserSwitchAssertions(oldUserId, TEST_USER_ID, false, false);
verifySystemUserVisibilityChangesNeverNotified();
@@ -1923,11 +1900,6 @@ public class UserControllerTest {
}
@Override
- protected void dismissKeyguard(Runnable runnable) {
- runnable.run();
- }
-
- @Override
void showUserSwitchingDialog(UserInfo fromUser, UserInfo toUser,
String switchingFromSystemUserMessage, String switchingToSystemUserMessage,
Runnable onShown) {