Add timeout fallback to UserController dismissKeyguard on user switch.

After a user switch, keyguard is dismissed if there is no password
for the target user. Then after the dismissal of the keyguard,
unfreezing the screen and calling UserSwitchObservers
onUserSwitchComplete is done. In case dismissKeyguard's callbacks
are not called, user switch can not be complete. This CL makes sure
user switch flow moves on even when the keyguard dismissal fails.

Bug: 256576977
Test: atest FrameworksServicesTests:UserControllerTest
Change-Id: I608a43de4d379a26ef66737c1bece7508d476b2e
This commit is contained in:
Yasin Kilicdere
2022-11-03 15:46:00 +00:00
parent e59a2e4c34
commit f2f7a74fee

View File

@@ -134,6 +134,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -199,6 +200,14 @@ 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 unfreeze the screen {@link #unfreezeScreen}
* 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).
@@ -3653,20 +3662,28 @@ class UserController implements Handler.Callback {
}
protected void dismissKeyguard(Runnable runnable, String reason) {
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(runnable);
mHandler.post(runOnce);
}
@Override
public void onDismissSucceeded() throws RemoteException {
mHandler.post(runnable);
mHandler.post(runOnce);
}
@Override
public void onDismissCancelled() throws RemoteException {
mHandler.post(runnable);
mHandler.post(runOnce);
}
}, reason);
}