Loading services/core/java/com/android/server/am/UserController.java +47 −30 Original line number Diff line number Diff line Loading @@ -518,6 +518,7 @@ class UserController implements Handler.Callback { } mInjector.installEncryptionUnawareProviders(userId); if (!mInjector.getUserManager().isPreCreated(userId)) { // Dispatch unlocked to external apps final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED); unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); Loading @@ -526,6 +527,7 @@ class UserController implements Handler.Callback { mInjector.broadcastIntent(unlockedIntent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(), Binder.getCallingPid(), userId); } if (getUserInfo(userId).isManagedProfile()) { UserInfo parent = mInjector.getUserManager().getProfileParent(userId); Loading Loading @@ -582,9 +584,12 @@ class UserController implements Handler.Callback { // Remember that we logged in mInjector.getUserManager().onUserLoggedIn(userId); Runnable initializeUser = () -> mInjector.getUserManager().makeInitialized(userInfo.id); if (!userInfo.isInitialized()) { if (userId != UserHandle.USER_SYSTEM) { Slog.d(TAG, "Initializing user #" + userId); if (userInfo.preCreated) { initializeUser.run(); } else if (userId != UserHandle.USER_SYSTEM) { Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); Loading @@ -595,7 +600,7 @@ class UserController implements Handler.Callback { String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { // Note: performReceive is called with mService lock held mInjector.getUserManager().makeInitialized(userInfo.id); initializeUser.run(); } }, 0, null, null, null, AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(), Loading Loading @@ -796,7 +801,15 @@ class UserController implements Handler.Callback { mInjector.getUserManagerInternal().setUserState(userId, uss.state); updateStartedUserArrayLU(); final boolean allowDelayyLockingCopied = allowDelayedLocking; final boolean allowDelayedLockingCopied = allowDelayedLocking; Runnable finishUserStoppingAsync = () -> mHandler.post(() -> finishUserStopping(userId, uss, allowDelayedLockingCopied)); if (mInjector.getUserManager().isPreCreated(userId)) { finishUserStoppingAsync.run(); return; } // Post to handler to obtain amLock mHandler.post(() -> { // We are going to broadcast ACTION_USER_STOPPING and then Loading @@ -811,8 +824,7 @@ class UserController implements Handler.Callback { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { mHandler.post(() -> finishUserStopping(userId, uss, allowDelayyLockingCopied)); finishUserStoppingAsync.run(); } }; Loading @@ -831,22 +843,6 @@ class UserController implements Handler.Callback { void finishUserStopping(final int userId, final UserState uss, final boolean allowDelayedLocking) { Slog.d(TAG, "UserController event: finishUserStopping(" + userId + ")"); // On to the next. final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN); // This is the result receiver for the final shutdown broadcast. final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { mHandler.post(new Runnable() { @Override public void run() { finishUserStopped(uss, allowDelayedLocking); } }); } }; synchronized (mLock) { if (uss.state != UserState.STATE_STOPPING) { // Whoops, we are being started back up. Abort, abort! Loading @@ -861,6 +857,23 @@ class UserController implements Handler.Callback { Integer.toString(userId), userId); mInjector.getSystemServiceManager().stopUser(userId); Runnable finishUserStoppedAsync = () -> mHandler.post(() -> finishUserStopped(uss, allowDelayedLocking)); if (mInjector.getUserManager().isPreCreated(userId)) { finishUserStoppedAsync.run(); return; } // Fire the shutdown intent. final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN); // This is the result receiver for the final shutdown broadcast. final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { finishUserStoppedAsync.run(); } }; mInjector.broadcastIntent(shutdownIntent, null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE, Loading Loading @@ -1020,6 +1033,10 @@ class UserController implements Handler.Callback { private void forceStopUser(@UserIdInt int userId, String reason) { mInjector.activityManagerForceStopPackage(userId, reason); if (mInjector.getUserManager().isPreCreated(userId)) { // Don't fire intent for precreated. return; } Intent intent = new Intent(Intent.ACTION_USER_STOPPED); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); Loading services/core/java/com/android/server/pm/UserManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -3769,6 +3769,19 @@ public class UserManagerService extends IUserManager.Stub { void finishRemoveUser(final @UserIdInt int userId) { if (DBG) Slog.i(LOG_TAG, "finishRemoveUser " + userId); UserInfo user; synchronized (mUsersLock) { user = getUserInfoLU(userId); } if (user != null && user.preCreated) { Slog.i(LOG_TAG, "Removing a precreated user with user id: " + userId); // Don't want to fire ACTION_USER_REMOVED, so cleanup the state and exit early. LocalServices.getService(ActivityTaskManagerInternal.class).onUserStopped(userId); removeUserState(userId); return; } // Let other services shutdown any activity and clean up their state before completely // wiping the user's system directory and removing from the user list long ident = Binder.clearCallingIdentity(); Loading services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -206,11 +206,15 @@ public class UserControllerTest { @Test public void testStartPreCreatedUser_foreground() { assertFalse(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ true)); // Make sure no intents have been fired for pre-created users. assertTrue(mInjector.mSentIntents.isEmpty()); } @Test public void testStartPreCreatedUser_background() throws Exception { assertTrue(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ false)); // Make sure no intents have been fired for pre-created users. assertTrue(mInjector.mSentIntents.isEmpty()); verify(mInjector.getWindowManager(), never()).startFreezingScreen(anyInt(), anyInt()); verify(mInjector.getWindowManager(), never()).setSwitchingUser(anyBoolean()); Loading Loading
services/core/java/com/android/server/am/UserController.java +47 −30 Original line number Diff line number Diff line Loading @@ -518,6 +518,7 @@ class UserController implements Handler.Callback { } mInjector.installEncryptionUnawareProviders(userId); if (!mInjector.getUserManager().isPreCreated(userId)) { // Dispatch unlocked to external apps final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED); unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); Loading @@ -526,6 +527,7 @@ class UserController implements Handler.Callback { mInjector.broadcastIntent(unlockedIntent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(), Binder.getCallingPid(), userId); } if (getUserInfo(userId).isManagedProfile()) { UserInfo parent = mInjector.getUserManager().getProfileParent(userId); Loading Loading @@ -582,9 +584,12 @@ class UserController implements Handler.Callback { // Remember that we logged in mInjector.getUserManager().onUserLoggedIn(userId); Runnable initializeUser = () -> mInjector.getUserManager().makeInitialized(userInfo.id); if (!userInfo.isInitialized()) { if (userId != UserHandle.USER_SYSTEM) { Slog.d(TAG, "Initializing user #" + userId); if (userInfo.preCreated) { initializeUser.run(); } else if (userId != UserHandle.USER_SYSTEM) { Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); Loading @@ -595,7 +600,7 @@ class UserController implements Handler.Callback { String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { // Note: performReceive is called with mService lock held mInjector.getUserManager().makeInitialized(userInfo.id); initializeUser.run(); } }, 0, null, null, null, AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(), Loading Loading @@ -796,7 +801,15 @@ class UserController implements Handler.Callback { mInjector.getUserManagerInternal().setUserState(userId, uss.state); updateStartedUserArrayLU(); final boolean allowDelayyLockingCopied = allowDelayedLocking; final boolean allowDelayedLockingCopied = allowDelayedLocking; Runnable finishUserStoppingAsync = () -> mHandler.post(() -> finishUserStopping(userId, uss, allowDelayedLockingCopied)); if (mInjector.getUserManager().isPreCreated(userId)) { finishUserStoppingAsync.run(); return; } // Post to handler to obtain amLock mHandler.post(() -> { // We are going to broadcast ACTION_USER_STOPPING and then Loading @@ -811,8 +824,7 @@ class UserController implements Handler.Callback { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { mHandler.post(() -> finishUserStopping(userId, uss, allowDelayyLockingCopied)); finishUserStoppingAsync.run(); } }; Loading @@ -831,22 +843,6 @@ class UserController implements Handler.Callback { void finishUserStopping(final int userId, final UserState uss, final boolean allowDelayedLocking) { Slog.d(TAG, "UserController event: finishUserStopping(" + userId + ")"); // On to the next. final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN); // This is the result receiver for the final shutdown broadcast. final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { mHandler.post(new Runnable() { @Override public void run() { finishUserStopped(uss, allowDelayedLocking); } }); } }; synchronized (mLock) { if (uss.state != UserState.STATE_STOPPING) { // Whoops, we are being started back up. Abort, abort! Loading @@ -861,6 +857,23 @@ class UserController implements Handler.Callback { Integer.toString(userId), userId); mInjector.getSystemServiceManager().stopUser(userId); Runnable finishUserStoppedAsync = () -> mHandler.post(() -> finishUserStopped(uss, allowDelayedLocking)); if (mInjector.getUserManager().isPreCreated(userId)) { finishUserStoppedAsync.run(); return; } // Fire the shutdown intent. final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN); // This is the result receiver for the final shutdown broadcast. final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() { @Override public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { finishUserStoppedAsync.run(); } }; mInjector.broadcastIntent(shutdownIntent, null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE, Loading Loading @@ -1020,6 +1033,10 @@ class UserController implements Handler.Callback { private void forceStopUser(@UserIdInt int userId, String reason) { mInjector.activityManagerForceStopPackage(userId, reason); if (mInjector.getUserManager().isPreCreated(userId)) { // Don't fire intent for precreated. return; } Intent intent = new Intent(Intent.ACTION_USER_STOPPED); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); Loading
services/core/java/com/android/server/pm/UserManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -3769,6 +3769,19 @@ public class UserManagerService extends IUserManager.Stub { void finishRemoveUser(final @UserIdInt int userId) { if (DBG) Slog.i(LOG_TAG, "finishRemoveUser " + userId); UserInfo user; synchronized (mUsersLock) { user = getUserInfoLU(userId); } if (user != null && user.preCreated) { Slog.i(LOG_TAG, "Removing a precreated user with user id: " + userId); // Don't want to fire ACTION_USER_REMOVED, so cleanup the state and exit early. LocalServices.getService(ActivityTaskManagerInternal.class).onUserStopped(userId); removeUserState(userId); return; } // Let other services shutdown any activity and clean up their state before completely // wiping the user's system directory and removing from the user list long ident = Binder.clearCallingIdentity(); Loading
services/tests/servicestests/src/com/android/server/am/UserControllerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -206,11 +206,15 @@ public class UserControllerTest { @Test public void testStartPreCreatedUser_foreground() { assertFalse(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ true)); // Make sure no intents have been fired for pre-created users. assertTrue(mInjector.mSentIntents.isEmpty()); } @Test public void testStartPreCreatedUser_background() throws Exception { assertTrue(mUserController.startUser(TEST_PRE_CREATED_USER_ID, /* foreground= */ false)); // Make sure no intents have been fired for pre-created users. assertTrue(mInjector.mSentIntents.isEmpty()); verify(mInjector.getWindowManager(), never()).startFreezingScreen(anyInt(), anyInt()); verify(mInjector.getWindowManager(), never()).setSwitchingUser(anyBoolean()); Loading