Wait for the user to fully stop before starting

When starting the user, if the previous state is SHUTDOWN,
we need for the user to fully stop to avoid various race conditions like
old processes not being killed etc.

Test: manual - adb shell am start-user/stop-user N
Bug: 78533470
Change-Id: I1a188cc7c7f1f3df5c5448e67e811aba7d9d3b8e
This commit is contained in:
Fyodor Kupolov
2018-04-30 18:49:34 -07:00
parent 8f5b3f19b4
commit 3d4b5c9852

View File

@@ -64,6 +64,7 @@ import android.os.IBinder;
import android.os.IProgressListener;
import android.os.IRemoteCallback;
import android.os.IUserManager;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.os.RemoteCallbackList;
@@ -962,6 +963,11 @@ class UserController implements Handler.Callback {
updateStartedUserArrayLU();
needStart = true;
updateUmState = true;
} else if (uss.state == UserState.STATE_SHUTDOWN && !isCallingOnHandlerThread()) {
Slog.i(TAG, "User #" + userId
+ " is shutting down - will start after full stop");
mHandler.post(() -> startUser(userId, foreground, unlockListener));
return true;
}
final Integer userIdInt = userId;
mUserLru.remove(userIdInt);
@@ -1086,6 +1092,10 @@ class UserController implements Handler.Callback {
return true;
}
private boolean isCallingOnHandlerThread() {
return Looper.myLooper() == mHandler.getLooper();
}
/**
* Start user, if its not already running, and bring it to foreground.
*/