diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index aaeaa7e78477e..f08810a57e9a0 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -3029,8 +3029,9 @@ public final class ActivityStackSupervisor implements DisplayListener { /** Checks whether the activity should be shown for current user. */ boolean okToShowLocked(ActivityRecord r) { - return r != null && (isCurrentProfileLocked(r.userId) - || (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); + return r != null && ((r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0 + || (isCurrentProfileLocked(r.userId) + && !mService.mUserController.isUserStoppingOrShuttingDownLocked(r.userId))); } final ArrayList processStoppingActivitiesLocked(boolean remove) { diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index 2375d7addb7f6..597b49924d7df 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -1336,6 +1336,15 @@ final class UserController { return mStartedUserArray; } + boolean isUserStoppingOrShuttingDownLocked(int userId) { + UserState state = getStartedUserStateLocked(userId); + if (state == null) { + return false; + } + return state.state == UserState.STATE_STOPPING + || state.state == UserState.STATE_SHUTDOWN; + } + boolean isUserRunningLocked(int userId, int flags) { UserState state = getStartedUserStateLocked(userId); if (state == null) { diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index ced44fa9b2f52..627cdd0161154 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -737,9 +737,9 @@ public class UserManagerService extends IUserManager.Stub { long identity = Binder.clearCallingIdentity(); try { if (enableQuietMode) { + ActivityManagerNative.getDefault().stopUser(userHandle, /* force */true, null); LocalServices.getService(ActivityManagerInternal.class) .killForegroundAppsForUser(userHandle); - ActivityManagerNative.getDefault().stopUser(userHandle, /* force */true, null); } else { ActivityManagerNative.getDefault().startUserInBackground(userHandle); }