Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
| 19 | import static android.Manifest.permission.INTERACT_ACROSS_USERS; |
| 20 | import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.USER_OP_ERROR_IS_SYSTEM; |
| 22 | import static android.app.ActivityManager.USER_OP_ERROR_RELATED_USERS_CANNOT_STOP; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.USER_OP_IS_CURRENT; |
| 24 | import static android.app.ActivityManager.USER_OP_SUCCESS; |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 25 | import static android.content.Context.KEYGUARD_SERVICE; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 26 | import static android.os.Process.SYSTEM_UID; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 27 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 28 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU; |
| 29 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 30 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 31 | import static com.android.server.am.ActivityManagerService.ALLOW_FULL_ONLY; |
| 32 | import static com.android.server.am.ActivityManagerService.ALLOW_NON_FULL; |
| 33 | import static com.android.server.am.ActivityManagerService.ALLOW_NON_FULL_IN_PROFILE; |
| 34 | import static com.android.server.am.ActivityManagerService.MY_PID; |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 35 | import static com.android.server.am.ActivityManagerService.REPORT_LOCKED_BOOT_COMPLETE_MSG; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 36 | import static com.android.server.am.ActivityManagerService.REPORT_USER_SWITCH_COMPLETE_MSG; |
| 37 | import static com.android.server.am.ActivityManagerService.REPORT_USER_SWITCH_MSG; |
| 38 | import static com.android.server.am.ActivityManagerService.SYSTEM_USER_CURRENT_MSG; |
| 39 | import static com.android.server.am.ActivityManagerService.SYSTEM_USER_START_MSG; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 40 | import static com.android.server.am.ActivityManagerService.SYSTEM_USER_UNLOCK_MSG; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 41 | import static com.android.server.am.ActivityManagerService.USER_SWITCH_TIMEOUT_MSG; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 42 | import static com.android.server.am.UserState.STATE_BOOTING; |
| 43 | import static com.android.server.am.UserState.STATE_RUNNING_LOCKED; |
| 44 | import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKED; |
| 45 | import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKING; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 46 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 47 | import android.annotation.NonNull; |
Tony Mak | 8c536f9 | 2016-03-21 12:20:41 +0000 | [diff] [blame] | 48 | import android.annotation.UserIdInt; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 49 | import android.app.ActivityManager; |
| 50 | import android.app.AppOpsManager; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 51 | import android.app.Dialog; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 52 | import android.app.IStopUserCallback; |
| 53 | import android.app.IUserSwitchObserver; |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 54 | import android.app.KeyguardManager; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 55 | import android.content.Context; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 56 | import android.content.IIntentReceiver; |
| 57 | import android.content.Intent; |
| 58 | import android.content.pm.PackageManager; |
| 59 | import android.content.pm.UserInfo; |
| 60 | import android.os.BatteryStats; |
| 61 | import android.os.Binder; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 62 | import android.os.Build; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 63 | import android.os.Bundle; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 64 | import android.os.Debug; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 65 | import android.os.Handler; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 66 | import android.os.IBinder; |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 67 | import android.os.IProgressListener; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 68 | import android.os.IRemoteCallback; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 69 | import android.os.IUserManager; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 70 | import android.os.Process; |
| 71 | import android.os.RemoteCallbackList; |
| 72 | import android.os.RemoteException; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 73 | import android.os.ServiceManager; |
James Hawkins | 899608a | 2016-05-27 11:15:06 -0700 | [diff] [blame] | 74 | import android.os.SystemClock; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 75 | import android.os.UserHandle; |
| 76 | import android.os.UserManager; |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 77 | import android.os.UserManagerInternal; |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 78 | import android.os.storage.IStorageManager; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 79 | import android.os.storage.StorageManager; |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 80 | import android.util.ArraySet; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 81 | import android.util.IntArray; |
Suprabh Shukla | 4fe508b | 2015-11-20 18:22:57 -0800 | [diff] [blame] | 82 | import android.util.Pair; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 83 | import android.util.Slog; |
| 84 | import android.util.SparseArray; |
| 85 | import android.util.SparseIntArray; |
| 86 | |
| 87 | import com.android.internal.R; |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 88 | import com.android.internal.annotations.GuardedBy; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 89 | import com.android.internal.annotations.VisibleForTesting; |
James Hawkins | 899608a | 2016-05-27 11:15:06 -0700 | [diff] [blame] | 90 | import com.android.internal.logging.MetricsLogger; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 91 | import com.android.internal.util.ArrayUtils; |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 92 | import com.android.internal.util.Preconditions; |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 93 | import com.android.internal.widget.LockPatternUtils; |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 94 | import com.android.server.LocalServices; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 95 | import com.android.server.pm.UserManagerService; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 96 | import com.android.server.wm.WindowManagerService; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 97 | |
| 98 | import java.io.PrintWriter; |
| 99 | import java.util.ArrayList; |
| 100 | import java.util.Arrays; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 101 | import java.util.HashSet; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 102 | import java.util.List; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 103 | import java.util.Objects; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 104 | import java.util.Set; |
Fyodor Kupolov | 3864183 | 2016-06-28 17:37:09 -0700 | [diff] [blame] | 105 | import java.util.concurrent.atomic.AtomicInteger; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Helper class for {@link ActivityManagerService} responsible for multi-user functionality. |
| 109 | */ |
| 110 | final class UserController { |
| 111 | private static final String TAG = TAG_WITH_CLASS_NAME ? "UserController" : TAG_AM; |
Jeff Sharkey | fd24108 | 2016-04-19 15:58:24 -0600 | [diff] [blame] | 112 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 113 | // Maximum number of users we allow to be running at a time. |
| 114 | static final int MAX_RUNNING_USERS = 3; |
| 115 | |
| 116 | // Amount of time we wait for observers to handle a user switch before |
| 117 | // giving up on them and unfreezing the screen. |
Fyodor Kupolov | 0e0986e | 2016-09-22 18:01:36 -0700 | [diff] [blame] | 118 | static final int USER_SWITCH_TIMEOUT = 3 * 1000; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 119 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 120 | private final Object mLock; |
| 121 | private final Injector mInjector; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 122 | private final Handler mHandler; |
| 123 | |
| 124 | // Holds the current foreground user's id |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 125 | @GuardedBy("mLock") |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 126 | private int mCurrentUserId = UserHandle.USER_SYSTEM; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 127 | // Holds the target user's id during a user switch |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 128 | @GuardedBy("mLock") |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 129 | private int mTargetUserId = UserHandle.USER_NULL; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * Which users have been started, so are allowed to run code. |
| 133 | */ |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 134 | @GuardedBy("mLock") |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 135 | private final SparseArray<UserState> mStartedUsers = new SparseArray<>(); |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 136 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 137 | /** |
| 138 | * LRU list of history of current users. Most recently current is at the end. |
| 139 | */ |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 140 | @GuardedBy("mLock") |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 141 | private final ArrayList<Integer> mUserLru = new ArrayList<>(); |
| 142 | |
| 143 | /** |
| 144 | * Constant array of the users that are currently started. |
| 145 | */ |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 146 | @GuardedBy("mLock") |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 147 | private int[] mStartedUserArray = new int[] { 0 }; |
| 148 | |
| 149 | // If there are multiple profiles for the current user, their ids are here |
| 150 | // Currently only the primary user can have managed profiles |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 151 | @GuardedBy("mLock") |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 152 | private int[] mCurrentProfileIds = new int[] {}; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * Mapping from each known user ID to the profile group ID it is associated with. |
| 156 | */ |
| 157 | private final SparseIntArray mUserProfileGroupIdsSelfLocked = new SparseIntArray(); |
| 158 | |
| 159 | /** |
| 160 | * Registered observers of the user switching mechanics. |
| 161 | */ |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 162 | private final RemoteCallbackList<IUserSwitchObserver> mUserSwitchObservers |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 163 | = new RemoteCallbackList<>(); |
| 164 | |
Evan Rosky | 3e0c25b | 2016-08-09 12:43:33 -0700 | [diff] [blame] | 165 | boolean mUserSwitchUiEnabled = true; |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 166 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 167 | /** |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 168 | * Currently active user switch callbacks. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 169 | */ |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 170 | @GuardedBy("mLock") |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 171 | private volatile ArraySet<String> mCurWaitingUserSwitchCallbacks; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 172 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 173 | private volatile UserManagerService mUserManager; |
| 174 | |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 175 | private final LockPatternUtils mLockPatternUtils; |
| 176 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 177 | UserController(ActivityManagerService service) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 178 | this(new Injector(service)); |
| 179 | } |
| 180 | |
| 181 | @VisibleForTesting |
| 182 | UserController(Injector injector) { |
| 183 | mInjector = injector; |
| 184 | mLock = injector.getLock(); |
| 185 | mHandler = injector.getHandler(); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 186 | // User 0 is the first and only user that runs at boot. |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 187 | final UserState uss = new UserState(UserHandle.SYSTEM); |
| 188 | mStartedUsers.put(UserHandle.USER_SYSTEM, uss); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 189 | mUserLru.add(UserHandle.USER_SYSTEM); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 190 | mLockPatternUtils = mInjector.getLockPatternUtils(); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 191 | updateStartedUserArrayLocked(); |
| 192 | } |
| 193 | |
| 194 | void finishUserSwitch(UserState uss) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 195 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 196 | finishUserBoot(uss); |
| 197 | |
| 198 | startProfilesLocked(); |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 199 | stopRunningUsersLocked(MAX_RUNNING_USERS); |
| 200 | } |
| 201 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 202 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 203 | void stopRunningUsersLocked(int maxRunningUsers) { |
| 204 | int num = mUserLru.size(); |
| 205 | int i = 0; |
| 206 | while (num > maxRunningUsers && i < mUserLru.size()) { |
| 207 | Integer oldUserId = mUserLru.get(i); |
| 208 | UserState oldUss = mStartedUsers.get(oldUserId); |
| 209 | if (oldUss == null) { |
| 210 | // Shouldn't happen, but be sane if it does. |
| 211 | mUserLru.remove(i); |
| 212 | num--; |
| 213 | continue; |
| 214 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 215 | if (oldUss.state == UserState.STATE_STOPPING |
| 216 | || oldUss.state == UserState.STATE_SHUTDOWN) { |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 217 | // This user is already stopping, doesn't count. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 218 | num--; |
| 219 | i++; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 220 | continue; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 221 | } |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 222 | if (oldUserId == UserHandle.USER_SYSTEM || oldUserId == mCurrentUserId) { |
| 223 | // Owner/System user and current user can't be stopped. We count it as running |
| 224 | // when it is not a pure system user. |
| 225 | if (UserInfo.isSystemOnly(oldUserId)) { |
| 226 | num--; |
| 227 | } |
| 228 | i++; |
| 229 | continue; |
| 230 | } |
| 231 | // This is a user to be stopped. |
| 232 | if (stopUsersLocked(oldUserId, false, null) != USER_OP_SUCCESS) { |
| 233 | num--; |
| 234 | } |
| 235 | num--; |
| 236 | i++; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Fyodor Kupolov | 2e6acce | 2016-01-28 15:26:52 -0800 | [diff] [blame] | 240 | private void finishUserBoot(UserState uss) { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 241 | finishUserBoot(uss, null); |
| 242 | } |
| 243 | |
Fyodor Kupolov | 2e6acce | 2016-01-28 15:26:52 -0800 | [diff] [blame] | 244 | private void finishUserBoot(UserState uss, IIntentReceiver resultTo) { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 245 | final int userId = uss.mHandle.getIdentifier(); |
Suprabh Shukla | cc30b0e7 | 2016-05-20 14:41:22 -0700 | [diff] [blame] | 246 | |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 247 | Slog.d(TAG, "Finishing user boot " + userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 248 | synchronized (mLock) { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 249 | // Bail if we ended up with a stale user |
| 250 | if (mStartedUsers.get(userId) != uss) return; |
| 251 | |
| 252 | // We always walk through all the user lifecycle states to send |
| 253 | // consistent developer events. We step into RUNNING_LOCKED here, |
| 254 | // but we might immediately step into RUNNING below if the user |
| 255 | // storage is already unlocked. |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 256 | if (uss.setState(STATE_BOOTING, STATE_RUNNING_LOCKED)) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 257 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
James Hawkins | 899608a | 2016-05-27 11:15:06 -0700 | [diff] [blame] | 258 | |
| 259 | int uptimeSeconds = (int)(SystemClock.elapsedRealtime() / 1000); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 260 | MetricsLogger.histogram(mInjector.getContext(), "framework_locked_boot_completed", |
James Hawkins | 899608a | 2016-05-27 11:15:06 -0700 | [diff] [blame] | 261 | uptimeSeconds); |
| 262 | |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 263 | mHandler.sendMessage(mHandler.obtainMessage(REPORT_LOCKED_BOOT_COMPLETE_MSG, |
| 264 | userId, 0)); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 265 | Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 266 | intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
Jeff Sharkey | a242f82 | 2015-12-17 15:38:20 -0700 | [diff] [blame] | 267 | intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT |
| 268 | | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 269 | mInjector.broadcastIntentLocked(intent, null, resultTo, 0, null, null, |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 270 | new String[] { android.Manifest.permission.RECEIVE_BOOT_COMPLETED }, |
| 271 | AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID, userId); |
| 272 | } |
| 273 | |
Jeff Sharkey | 7661a31 | 2016-04-07 12:39:57 -0600 | [diff] [blame] | 274 | // We need to delay unlocking managed profiles until the parent user |
| 275 | // is also unlocked. |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 276 | if (mInjector.getUserManager().isManagedProfile(userId)) { |
| 277 | final UserInfo parent = mInjector.getUserManager().getProfileParent(userId); |
Jeff Sharkey | 7661a31 | 2016-04-07 12:39:57 -0600 | [diff] [blame] | 278 | if (parent != null |
| 279 | && isUserRunningLocked(parent.id, ActivityManager.FLAG_AND_UNLOCKED)) { |
| 280 | Slog.d(TAG, "User " + userId + " (parent " + parent.id |
| 281 | + "): attempting unlock because parent is unlocked"); |
| 282 | maybeUnlockUser(userId); |
| 283 | } else { |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 284 | String parentId = (parent == null) ? "<null>" : String.valueOf(parent.id); |
| 285 | Slog.d(TAG, "User " + userId + " (parent " + parentId |
Jeff Sharkey | 7661a31 | 2016-04-07 12:39:57 -0600 | [diff] [blame] | 286 | + "): delaying unlock because parent is locked"); |
| 287 | } |
Jeff Sharkey | 5dab713 | 2016-04-07 01:20:58 -0600 | [diff] [blame] | 288 | } else { |
| 289 | maybeUnlockUser(userId); |
| 290 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 295 | * Step from {@link UserState#STATE_RUNNING_LOCKED} to |
| 296 | * {@link UserState#STATE_RUNNING_UNLOCKING}. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 297 | */ |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 298 | private void finishUserUnlocking(final UserState uss) { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 299 | final int userId = uss.mHandle.getIdentifier(); |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 300 | boolean proceedWithUnlock = false; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 301 | synchronized (mLock) { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 302 | // Bail if we ended up with a stale user |
| 303 | if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return; |
| 304 | |
| 305 | // Only keep marching forward if user is actually unlocked |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 306 | if (!StorageManager.isUserKeyUnlocked(userId)) return; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 307 | |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 308 | if (uss.setState(STATE_RUNNING_LOCKED, STATE_RUNNING_UNLOCKING)) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 309 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 310 | proceedWithUnlock = true; |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 311 | } |
| 312 | } |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 313 | |
| 314 | if (proceedWithUnlock) { |
| 315 | uss.mUnlockProgress.start(); |
| 316 | |
| 317 | // Prepare app storage before we go any further |
| 318 | uss.mUnlockProgress.setProgress(5, |
Jorim Jaggi | 526694e | 2016-08-03 17:15:23 +0200 | [diff] [blame] | 319 | mInjector.getContext().getString(R.string.android_start_title)); |
| 320 | mInjector.getUserManager().onBeforeUnlockUser(userId); |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 321 | uss.mUnlockProgress.setProgress(20); |
| 322 | |
| 323 | // Dispatch unlocked to system services; when fully dispatched, |
| 324 | // that calls through to the next "unlocked" phase |
| 325 | mHandler.obtainMessage(SYSTEM_USER_UNLOCK_MSG, userId, 0, uss) |
| 326 | .sendToTarget(); |
| 327 | } |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Step from {@link UserState#STATE_RUNNING_UNLOCKING} to |
| 332 | * {@link UserState#STATE_RUNNING_UNLOCKED}. |
| 333 | */ |
| 334 | void finishUserUnlocked(final UserState uss) { |
| 335 | final int userId = uss.mHandle.getIdentifier(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 336 | synchronized (mLock) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 337 | // Bail if we ended up with a stale user |
| 338 | if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return; |
| 339 | |
| 340 | // Only keep marching forward if user is actually unlocked |
| 341 | if (!StorageManager.isUserKeyUnlocked(userId)) return; |
| 342 | |
| 343 | if (uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 344 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 345 | uss.mUnlockProgress.finish(); |
Jeff Sharkey | 083807d | 2016-04-06 14:07:09 -0600 | [diff] [blame] | 346 | |
Jeff Sharkey | 155e5d6 | 2016-04-11 12:13:06 -0600 | [diff] [blame] | 347 | // Dispatch unlocked to external apps |
| 348 | final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED); |
| 349 | unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 350 | unlockedIntent.addFlags( |
| 351 | Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 352 | mInjector.broadcastIntentLocked(unlockedIntent, null, null, 0, null, |
Jeff Sharkey | 155e5d6 | 2016-04-11 12:13:06 -0600 | [diff] [blame] | 353 | null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, |
| 354 | userId); |
| 355 | |
| 356 | if (getUserInfo(userId).isManagedProfile()) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 357 | UserInfo parent = mInjector.getUserManager().getProfileParent(userId); |
Jeff Sharkey | 155e5d6 | 2016-04-11 12:13:06 -0600 | [diff] [blame] | 358 | if (parent != null) { |
| 359 | final Intent profileUnlockedIntent = new Intent( |
| 360 | Intent.ACTION_MANAGED_PROFILE_UNLOCKED); |
| 361 | profileUnlockedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId)); |
| 362 | profileUnlockedIntent.addFlags( |
| 363 | Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 364 | | Intent.FLAG_RECEIVER_FOREGROUND); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 365 | mInjector.broadcastIntentLocked(profileUnlockedIntent, |
Jeff Sharkey | 155e5d6 | 2016-04-11 12:13:06 -0600 | [diff] [blame] | 366 | null, null, 0, null, null, null, AppOpsManager.OP_NONE, |
| 367 | null, false, false, MY_PID, SYSTEM_UID, |
| 368 | parent.id); |
| 369 | } |
| 370 | } |
| 371 | |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 372 | // Send PRE_BOOT broadcasts if user fingerprint changed; we |
| 373 | // purposefully block sending BOOT_COMPLETED until after all |
| 374 | // PRE_BOOT receivers are finished to avoid ANR'ing apps |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 375 | final UserInfo info = getUserInfo(userId); |
| 376 | if (!Objects.equals(info.lastLoggedInFingerprint, Build.FINGERPRINT)) { |
Jeff Sharkey | 24d9491 | 2016-07-07 12:33:48 -0600 | [diff] [blame] | 377 | // Suppress double notifications for managed profiles that |
Jeff Sharkey | ba06657 | 2016-07-18 10:11:36 -0600 | [diff] [blame] | 378 | // were unlocked automatically as part of their parent user |
| 379 | // being unlocked. |
| 380 | final boolean quiet; |
| 381 | if (info.isManagedProfile()) { |
| 382 | quiet = !uss.tokenProvided |
| 383 | || !mLockPatternUtils.isSeparateProfileChallengeEnabled(userId); |
| 384 | } else { |
| 385 | quiet = false; |
| 386 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 387 | mInjector.sendPreBootBroadcast(userId, quiet, |
| 388 | () -> finishUserUnlockedCompleted(uss)); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 389 | } else { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 390 | finishUserUnlockedCompleted(uss); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 396 | private void finishUserUnlockedCompleted(UserState uss) { |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 397 | final int userId = uss.mHandle.getIdentifier(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 398 | synchronized (mLock) { |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 399 | // Bail if we ended up with a stale user |
| 400 | if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return; |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 401 | final UserInfo userInfo = getUserInfo(userId); |
| 402 | if (userInfo == null) { |
| 403 | return; |
| 404 | } |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 405 | |
| 406 | // Only keep marching forward if user is actually unlocked |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 407 | if (!StorageManager.isUserKeyUnlocked(userId)) return; |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 408 | |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 409 | // Remember that we logged in |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 410 | mInjector.getUserManager().onUserLoggedIn(userId); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 411 | |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 412 | if (!userInfo.isInitialized()) { |
| 413 | if (userId != UserHandle.USER_SYSTEM) { |
| 414 | Slog.d(TAG, "Initializing user #" + userId); |
| 415 | Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE); |
| 416 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 417 | mInjector.broadcastIntentLocked(intent, null, |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 418 | new IIntentReceiver.Stub() { |
| 419 | @Override |
| 420 | public void performReceive(Intent intent, int resultCode, |
| 421 | String data, Bundle extras, boolean ordered, |
| 422 | boolean sticky, int sendingUser) { |
| 423 | // Note: performReceive is called with mService lock held |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 424 | mInjector.getUserManager().makeInitialized(userInfo.id); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 425 | } |
| 426 | }, 0, null, null, null, AppOpsManager.OP_NONE, |
| 427 | null, true, false, MY_PID, SYSTEM_UID, userId); |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 428 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 429 | } |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 430 | |
| 431 | Slog.d(TAG, "Sending BOOT_COMPLETE user #" + userId); |
James Hawkins | 899608a | 2016-05-27 11:15:06 -0700 | [diff] [blame] | 432 | int uptimeSeconds = (int)(SystemClock.elapsedRealtime() / 1000); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 433 | MetricsLogger.histogram(mInjector.getContext(), "framework_boot_completed", |
| 434 | uptimeSeconds); |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 435 | final Intent bootIntent = new Intent(Intent.ACTION_BOOT_COMPLETED, null); |
| 436 | bootIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 437 | bootIntent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT |
| 438 | | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 439 | mInjector.broadcastIntentLocked(bootIntent, null, null, 0, null, null, |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 440 | new String[] { android.Manifest.permission.RECEIVE_BOOT_COMPLETED }, |
| 441 | AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID, userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 445 | int restartUser(final int userId, final boolean foreground) { |
| 446 | return stopUser(userId, /* force */ true, new IStopUserCallback.Stub() { |
| 447 | @Override |
| 448 | public void userStopped(final int userId) { |
| 449 | // Post to the same handler that this callback is called from to ensure the user |
| 450 | // cleanup is complete before restarting. |
| 451 | mHandler.post(() -> startUser(userId, foreground)); |
| 452 | } |
| 453 | @Override |
| 454 | public void userStopAborted(final int userId) {} |
| 455 | }); |
| 456 | } |
| 457 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 458 | int stopUser(final int userId, final boolean force, final IStopUserCallback callback) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 459 | if (mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 460 | != PackageManager.PERMISSION_GRANTED) { |
| 461 | String msg = "Permission Denial: switchUser() from pid=" |
| 462 | + Binder.getCallingPid() |
| 463 | + ", uid=" + Binder.getCallingUid() |
| 464 | + " requires " + INTERACT_ACROSS_USERS_FULL; |
| 465 | Slog.w(TAG, msg); |
| 466 | throw new SecurityException(msg); |
| 467 | } |
| 468 | if (userId < 0 || userId == UserHandle.USER_SYSTEM) { |
| 469 | throw new IllegalArgumentException("Can't stop system user " + userId); |
| 470 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 471 | mInjector.enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, userId); |
| 472 | synchronized (mLock) { |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 473 | return stopUsersLocked(userId, force, callback); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 477 | /** |
| 478 | * Stops the user along with its related users. The method calls |
| 479 | * {@link #getUsersToStopLocked(int)} to determine the list of users that should be stopped. |
| 480 | */ |
| 481 | private int stopUsersLocked(final int userId, boolean force, final IStopUserCallback callback) { |
| 482 | if (userId == UserHandle.USER_SYSTEM) { |
| 483 | return USER_OP_ERROR_IS_SYSTEM; |
| 484 | } |
| 485 | if (isCurrentUserLocked(userId)) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 486 | return USER_OP_IS_CURRENT; |
| 487 | } |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 488 | int[] usersToStop = getUsersToStopLocked(userId); |
| 489 | // If one of related users is system or current, no related users should be stopped |
| 490 | for (int i = 0; i < usersToStop.length; i++) { |
| 491 | int relatedUserId = usersToStop[i]; |
| 492 | if ((UserHandle.USER_SYSTEM == relatedUserId) || isCurrentUserLocked(relatedUserId)) { |
| 493 | if (DEBUG_MU) Slog.i(TAG, "stopUsersLocked cannot stop related user " |
| 494 | + relatedUserId); |
| 495 | // We still need to stop the requested user if it's a force stop. |
| 496 | if (force) { |
Fyodor Kupolov | 7b4a8a4 | 2016-01-04 12:47:22 -0800 | [diff] [blame] | 497 | Slog.i(TAG, |
| 498 | "Force stop user " + userId + ". Related users will not be stopped"); |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 499 | stopSingleUserLocked(userId, callback); |
Fyodor Kupolov | 7b4a8a4 | 2016-01-04 12:47:22 -0800 | [diff] [blame] | 500 | return USER_OP_SUCCESS; |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 501 | } |
| 502 | return USER_OP_ERROR_RELATED_USERS_CANNOT_STOP; |
| 503 | } |
| 504 | } |
| 505 | if (DEBUG_MU) Slog.i(TAG, "stopUsersLocked usersToStop=" + Arrays.toString(usersToStop)); |
| 506 | for (int userIdToStop : usersToStop) { |
| 507 | stopSingleUserLocked(userIdToStop, userIdToStop == userId ? callback : null); |
| 508 | } |
| 509 | return USER_OP_SUCCESS; |
| 510 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 511 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 512 | private void stopSingleUserLocked(final int userId, final IStopUserCallback callback) { |
| 513 | if (DEBUG_MU) Slog.i(TAG, "stopSingleUserLocked userId=" + userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 514 | final UserState uss = mStartedUsers.get(userId); |
| 515 | if (uss == null) { |
| 516 | // User is not started, nothing to do... but we do need to |
| 517 | // callback if requested. |
| 518 | if (callback != null) { |
| 519 | mHandler.post(new Runnable() { |
| 520 | @Override |
| 521 | public void run() { |
| 522 | try { |
| 523 | callback.userStopped(userId); |
| 524 | } catch (RemoteException e) { |
| 525 | } |
| 526 | } |
| 527 | }); |
| 528 | } |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 529 | return; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | if (callback != null) { |
| 533 | uss.mStopCallbacks.add(callback); |
| 534 | } |
| 535 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 536 | if (uss.state != UserState.STATE_STOPPING |
| 537 | && uss.state != UserState.STATE_SHUTDOWN) { |
| 538 | uss.setState(UserState.STATE_STOPPING); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 539 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 540 | updateStartedUserArrayLocked(); |
| 541 | |
| 542 | long ident = Binder.clearCallingIdentity(); |
| 543 | try { |
| 544 | // We are going to broadcast ACTION_USER_STOPPING and then |
| 545 | // once that is done send a final ACTION_SHUTDOWN and then |
| 546 | // stop the user. |
| 547 | final Intent stoppingIntent = new Intent(Intent.ACTION_USER_STOPPING); |
| 548 | stoppingIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 549 | stoppingIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 550 | stoppingIntent.putExtra(Intent.EXTRA_SHUTDOWN_USERSPACE_ONLY, true); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 551 | // This is the result receiver for the initial stopping broadcast. |
| 552 | final IIntentReceiver stoppingReceiver = new IIntentReceiver.Stub() { |
| 553 | @Override |
| 554 | public void performReceive(Intent intent, int resultCode, String data, |
| 555 | Bundle extras, boolean ordered, boolean sticky, int sendingUser) { |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 556 | mHandler.post(new Runnable() { |
| 557 | @Override |
| 558 | public void run() { |
| 559 | finishUserStopping(userId, uss); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 560 | } |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 561 | }); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 562 | } |
| 563 | }; |
Amith Yamasani | ad2e4bf | 2016-04-26 14:35:54 -0700 | [diff] [blame] | 564 | // Clear broadcast queue for the user to avoid delivering stale broadcasts |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 565 | mInjector.clearBroadcastQueueForUserLocked(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 566 | // Kick things off. |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 567 | mInjector.broadcastIntentLocked(stoppingIntent, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 568 | null, stoppingReceiver, 0, null, null, |
| 569 | new String[]{INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 570 | null, true, false, MY_PID, SYSTEM_UID, UserHandle.USER_ALL); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 571 | } finally { |
| 572 | Binder.restoreCallingIdentity(ident); |
| 573 | } |
| 574 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 577 | void finishUserStopping(final int userId, final UserState uss) { |
| 578 | // On to the next. |
| 579 | final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN); |
| 580 | // This is the result receiver for the final shutdown broadcast. |
| 581 | final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() { |
| 582 | @Override |
| 583 | public void performReceive(Intent intent, int resultCode, String data, |
| 584 | Bundle extras, boolean ordered, boolean sticky, int sendingUser) { |
| 585 | mHandler.post(new Runnable() { |
| 586 | @Override |
| 587 | public void run() { |
| 588 | finishUserStopped(uss); |
| 589 | } |
| 590 | }); |
| 591 | } |
| 592 | }; |
| 593 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 594 | synchronized (mLock) { |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 595 | if (uss.state != UserState.STATE_STOPPING) { |
| 596 | // Whoops, we are being started back up. Abort, abort! |
| 597 | return; |
| 598 | } |
| 599 | uss.setState(UserState.STATE_SHUTDOWN); |
| 600 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 601 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 602 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 603 | mInjector.batteryStatsServiceNoteEvent( |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 604 | BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH, |
| 605 | Integer.toString(userId), userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 606 | mInjector.systemServiceManagerStopUser(userId); |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 607 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 608 | synchronized (mLock) { |
| 609 | mInjector.broadcastIntentLocked(shutdownIntent, |
Amith Yamasani | 98c0556 | 2016-03-30 13:15:26 -0700 | [diff] [blame] | 610 | null, shutdownReceiver, 0, null, null, null, |
| 611 | AppOpsManager.OP_NONE, |
| 612 | null, true, false, MY_PID, SYSTEM_UID, userId); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | void finishUserStopped(UserState uss) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 617 | final int userId = uss.mHandle.getIdentifier(); |
| 618 | boolean stopped; |
| 619 | ArrayList<IStopUserCallback> callbacks; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 620 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 621 | callbacks = new ArrayList<>(uss.mStopCallbacks); |
| 622 | if (mStartedUsers.get(userId) != uss) { |
| 623 | stopped = false; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 624 | } else if (uss.state != UserState.STATE_SHUTDOWN) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 625 | stopped = false; |
| 626 | } else { |
| 627 | stopped = true; |
| 628 | // User can no longer run. |
| 629 | mStartedUsers.remove(userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 630 | mInjector.getUserManagerInternal().removeUserState(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 631 | mUserLru.remove(Integer.valueOf(userId)); |
| 632 | updateStartedUserArrayLocked(); |
| 633 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 634 | mInjector.activityManagerOnUserStopped(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 635 | // Clean up all state and processes associated with the user. |
| 636 | // Kill all the processes for the user. |
| 637 | forceStopUserLocked(userId, "finish user"); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | for (int i = 0; i < callbacks.size(); i++) { |
| 642 | try { |
| 643 | if (stopped) callbacks.get(i).userStopped(userId); |
| 644 | else callbacks.get(i).userStopAborted(userId); |
| 645 | } catch (RemoteException e) { |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | if (stopped) { |
Andrew Scull | 85a63bc | 2016-10-24 13:47:47 +0100 | [diff] [blame] | 650 | // Evict the user's credential encryption key |
| 651 | try { |
| 652 | getStorageManager().lockUserKey(userId); |
| 653 | } catch (RemoteException re) { |
| 654 | throw re.rethrowAsRuntimeException(); |
| 655 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 656 | mInjector.systemServiceManagerCleanupUser(userId); |
| 657 | synchronized (mLock) { |
| 658 | mInjector.stackSupervisorRemoveUserLocked(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 659 | } |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 660 | // Remove the user if it is ephemeral. |
| 661 | if (getUserInfo(userId).isEphemeral()) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 662 | mInjector.getUserManager().removeUser(userId); |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 663 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 667 | /** |
| 668 | * Determines the list of users that should be stopped together with the specified |
| 669 | * {@code userId}. The returned list includes {@code userId}. |
| 670 | */ |
| 671 | private @NonNull int[] getUsersToStopLocked(int userId) { |
| 672 | int startedUsersSize = mStartedUsers.size(); |
| 673 | IntArray userIds = new IntArray(); |
| 674 | userIds.add(userId); |
| 675 | synchronized (mUserProfileGroupIdsSelfLocked) { |
| 676 | int userGroupId = mUserProfileGroupIdsSelfLocked.get(userId, |
| 677 | UserInfo.NO_PROFILE_GROUP_ID); |
| 678 | for (int i = 0; i < startedUsersSize; i++) { |
| 679 | UserState uss = mStartedUsers.valueAt(i); |
| 680 | int startedUserId = uss.mHandle.getIdentifier(); |
| 681 | // Skip unrelated users (profileGroupId mismatch) |
| 682 | int startedUserGroupId = mUserProfileGroupIdsSelfLocked.get(startedUserId, |
| 683 | UserInfo.NO_PROFILE_GROUP_ID); |
| 684 | boolean sameGroup = (userGroupId != UserInfo.NO_PROFILE_GROUP_ID) |
| 685 | && (userGroupId == startedUserGroupId); |
| 686 | // userId has already been added |
| 687 | boolean sameUserId = startedUserId == userId; |
| 688 | if (!sameGroup || sameUserId) { |
| 689 | continue; |
| 690 | } |
| 691 | userIds.add(startedUserId); |
| 692 | } |
| 693 | } |
| 694 | return userIds.toArray(); |
| 695 | } |
| 696 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 697 | private void forceStopUserLocked(int userId, String reason) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 698 | mInjector.activityManagerForceStopPackageLocked(userId, reason); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 699 | Intent intent = new Intent(Intent.ACTION_USER_STOPPED); |
| 700 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 701 | | Intent.FLAG_RECEIVER_FOREGROUND); |
| 702 | intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 703 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 704 | null, null, 0, null, null, null, AppOpsManager.OP_NONE, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 705 | null, false, false, MY_PID, SYSTEM_UID, UserHandle.USER_ALL); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 708 | /** |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 709 | * Stops the guest or ephemeral user if it has gone to the background. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 710 | */ |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 711 | private void stopGuestOrEphemeralUserIfBackground() { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 712 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 713 | final int num = mUserLru.size(); |
| 714 | for (int i = 0; i < num; i++) { |
| 715 | Integer oldUserId = mUserLru.get(i); |
| 716 | UserState oldUss = mStartedUsers.get(oldUserId); |
| 717 | if (oldUserId == UserHandle.USER_SYSTEM || oldUserId == mCurrentUserId |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 718 | || oldUss.state == UserState.STATE_STOPPING |
| 719 | || oldUss.state == UserState.STATE_SHUTDOWN) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 720 | continue; |
| 721 | } |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 722 | UserInfo userInfo = getUserInfo(oldUserId); |
Lenka Trochtova | 1ddda47 | 2016-02-12 10:42:12 +0100 | [diff] [blame] | 723 | if (userInfo.isEphemeral()) { |
| 724 | LocalServices.getService(UserManagerInternal.class) |
| 725 | .onEphemeralUserStop(oldUserId); |
| 726 | } |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 727 | if (userInfo.isGuest() || userInfo.isEphemeral()) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 728 | // This is a user to be stopped. |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 729 | stopUsersLocked(oldUserId, true, null); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 730 | break; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | void startProfilesLocked() { |
| 737 | if (DEBUG_MU) Slog.i(TAG, "startProfilesLocked"); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 738 | List<UserInfo> profiles = mInjector.getUserManager().getProfiles( |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 739 | mCurrentUserId, false /* enabledOnly */); |
| 740 | List<UserInfo> profilesToStart = new ArrayList<>(profiles.size()); |
| 741 | for (UserInfo user : profiles) { |
| 742 | if ((user.flags & UserInfo.FLAG_INITIALIZED) == UserInfo.FLAG_INITIALIZED |
Rubin Xu | f13c980 | 2016-01-21 18:06:00 +0000 | [diff] [blame] | 743 | && user.id != mCurrentUserId && !user.isQuietModeEnabled()) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 744 | profilesToStart.add(user); |
| 745 | } |
| 746 | } |
| 747 | final int profilesToStartSize = profilesToStart.size(); |
| 748 | int i = 0; |
| 749 | for (; i < profilesToStartSize && i < (MAX_RUNNING_USERS - 1); ++i) { |
| 750 | startUser(profilesToStart.get(i).id, /* foreground= */ false); |
| 751 | } |
| 752 | if (i < profilesToStartSize) { |
| 753 | Slog.w(TAG, "More profiles than MAX_RUNNING_USERS"); |
| 754 | } |
| 755 | } |
| 756 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 757 | private IStorageManager getStorageManager() { |
| 758 | return IStorageManager.Stub.asInterface(ServiceManager.getService("mount")); |
Jeff Sharkey | b9fe537 | 2015-12-03 15:23:08 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 761 | /** |
| 762 | * Start user, if its not already running. |
| 763 | * <p>The user will be brought to the foreground, if {@code foreground} parameter is set. |
| 764 | * When starting the user, multiple intents will be broadcast in the following order:</p> |
| 765 | * <ul> |
| 766 | * <li>{@link Intent#ACTION_USER_STARTED} - sent to registered receivers of the new user |
| 767 | * <li>{@link Intent#ACTION_USER_BACKGROUND} - sent to registered receivers of the outgoing |
| 768 | * user and all profiles of this user. Sent only if {@code foreground} parameter is true |
| 769 | * <li>{@link Intent#ACTION_USER_FOREGROUND} - sent to registered receivers of the new |
| 770 | * user and all profiles of this user. Sent only if {@code foreground} parameter is true |
| 771 | * <li>{@link Intent#ACTION_USER_SWITCHED} - sent to registered receivers of the new user. |
| 772 | * Sent only if {@code foreground} parameter is true |
| 773 | * <li>{@link Intent#ACTION_USER_STARTING} - ordered broadcast sent to registered receivers |
| 774 | * of the new fg user |
| 775 | * <li>{@link Intent#ACTION_LOCKED_BOOT_COMPLETED} - ordered broadcast sent to receivers of |
| 776 | * the new user |
| 777 | * <li>{@link Intent#ACTION_USER_UNLOCKED} - sent to registered receivers of the new user |
| 778 | * <li>{@link Intent#ACTION_PRE_BOOT_COMPLETED} - ordered broadcast sent to receivers of the |
| 779 | * new user. Sent only when the user is booting after a system update. |
| 780 | * <li>{@link Intent#ACTION_USER_INITIALIZE} - ordered broadcast sent to receivers of the |
| 781 | * new user. Sent only the first time a user is starting. |
| 782 | * <li>{@link Intent#ACTION_BOOT_COMPLETED} - ordered broadcast sent to receivers of the new |
| 783 | * user. Indicates that the user has finished booting. |
| 784 | * </ul> |
| 785 | * |
| 786 | * @param userId ID of the user to start |
| 787 | * @param foreground true if user should be brought to the foreground |
| 788 | * @return true if the user has been successfully started |
| 789 | */ |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 790 | boolean startUser(final int userId, final boolean foreground) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 791 | if (mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 792 | != PackageManager.PERMISSION_GRANTED) { |
| 793 | String msg = "Permission Denial: switchUser() from pid=" |
| 794 | + Binder.getCallingPid() |
| 795 | + ", uid=" + Binder.getCallingUid() |
| 796 | + " requires " + INTERACT_ACROSS_USERS_FULL; |
| 797 | Slog.w(TAG, msg); |
| 798 | throw new SecurityException(msg); |
| 799 | } |
| 800 | |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 801 | Slog.i(TAG, "Starting userid:" + userId + " fg:" + foreground); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 802 | |
| 803 | final long ident = Binder.clearCallingIdentity(); |
| 804 | try { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 805 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 806 | final int oldUserId = mCurrentUserId; |
| 807 | if (oldUserId == userId) { |
| 808 | return true; |
| 809 | } |
| 810 | |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 811 | mInjector.stackSupervisorSetLockTaskModeLocked(null, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 812 | ActivityManager.LOCK_TASK_MODE_NONE, "startUser", false); |
| 813 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 814 | final UserInfo userInfo = getUserInfo(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 815 | if (userInfo == null) { |
| 816 | Slog.w(TAG, "No user info for user #" + userId); |
| 817 | return false; |
| 818 | } |
| 819 | if (foreground && userInfo.isManagedProfile()) { |
| 820 | Slog.w(TAG, "Cannot switch to User #" + userId + ": not a full user"); |
| 821 | return false; |
| 822 | } |
| 823 | |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 824 | if (foreground && mUserSwitchUiEnabled) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 825 | mInjector.getWindowManager().startFreezingScreen( |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 826 | R.anim.screen_user_exit, R.anim.screen_user_enter); |
| 827 | } |
| 828 | |
| 829 | boolean needStart = false; |
| 830 | |
| 831 | // If the user we are switching to is not currently started, then |
| 832 | // we need to start it now. |
| 833 | if (mStartedUsers.get(userId) == null) { |
Amith Yamasani | ea1b9d7 | 2016-05-27 15:57:38 +0000 | [diff] [blame] | 834 | UserState userState = new UserState(UserHandle.of(userId)); |
| 835 | mStartedUsers.put(userId, userState); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 836 | mInjector.getUserManagerInternal().setUserState(userId, userState.state); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 837 | updateStartedUserArrayLocked(); |
| 838 | needStart = true; |
| 839 | } |
| 840 | |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 841 | final UserState uss = mStartedUsers.get(userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 842 | final Integer userIdInt = userId; |
| 843 | mUserLru.remove(userIdInt); |
| 844 | mUserLru.add(userIdInt); |
| 845 | |
| 846 | if (foreground) { |
| 847 | mCurrentUserId = userId; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 848 | mInjector.updateUserConfigurationLocked(); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 849 | mTargetUserId = UserHandle.USER_NULL; // reset, mCurrentUserId has caught up |
| 850 | updateCurrentProfileIdsLocked(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 851 | mInjector.getWindowManager().setCurrentUser(userId, mCurrentProfileIds); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 852 | // Once the internal notion of the active user has switched, we lock the device |
| 853 | // with the option to show the user switcher on the keyguard. |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 854 | if (mUserSwitchUiEnabled) { |
| 855 | mInjector.getWindowManager().setSwitchingUser(true); |
| 856 | mInjector.getWindowManager().lockNow(null); |
| 857 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 858 | } else { |
| 859 | final Integer currentUserIdInt = mCurrentUserId; |
| 860 | updateCurrentProfileIdsLocked(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 861 | mInjector.getWindowManager().setCurrentProfileIds(mCurrentProfileIds); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 862 | mUserLru.remove(currentUserIdInt); |
| 863 | mUserLru.add(currentUserIdInt); |
| 864 | } |
| 865 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 866 | // Make sure user is in the started state. If it is currently |
| 867 | // stopping, we need to knock that off. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 868 | if (uss.state == UserState.STATE_STOPPING) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 869 | // If we are stopping, we haven't sent ACTION_SHUTDOWN, |
| 870 | // so we can just fairly silently bring the user back from |
| 871 | // the almost-dead. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 872 | uss.setState(uss.lastState); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 873 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 874 | updateStartedUserArrayLocked(); |
| 875 | needStart = true; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 876 | } else if (uss.state == UserState.STATE_SHUTDOWN) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 877 | // This means ACTION_SHUTDOWN has been sent, so we will |
| 878 | // need to treat this as a new boot of the user. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 879 | uss.setState(UserState.STATE_BOOTING); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 880 | mInjector.getUserManagerInternal().setUserState(userId, uss.state); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 881 | updateStartedUserArrayLocked(); |
| 882 | needStart = true; |
| 883 | } |
| 884 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 885 | if (uss.state == UserState.STATE_BOOTING) { |
Jeff Sharkey | 0e62384c | 2016-01-13 18:52:55 -0700 | [diff] [blame] | 886 | // Give user manager a chance to propagate user restrictions |
| 887 | // to other services and prepare app storage |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 888 | mInjector.getUserManager().onBeforeStartUser(userId); |
Makoto Onuki | 1a2cd74 | 2015-11-16 13:51:27 -0800 | [diff] [blame] | 889 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 890 | // Booting up a new user, need to tell system services about it. |
| 891 | // Note that this is on the same handler as scheduling of broadcasts, |
| 892 | // which is important because it needs to go first. |
| 893 | mHandler.sendMessage(mHandler.obtainMessage(SYSTEM_USER_START_MSG, userId, 0)); |
| 894 | } |
| 895 | |
| 896 | if (foreground) { |
| 897 | mHandler.sendMessage(mHandler.obtainMessage(SYSTEM_USER_CURRENT_MSG, userId, |
| 898 | oldUserId)); |
| 899 | mHandler.removeMessages(REPORT_USER_SWITCH_MSG); |
| 900 | mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG); |
| 901 | mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_MSG, |
| 902 | oldUserId, userId, uss)); |
| 903 | mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_TIMEOUT_MSG, |
| 904 | oldUserId, userId, uss), USER_SWITCH_TIMEOUT); |
| 905 | } |
| 906 | |
| 907 | if (needStart) { |
| 908 | // Send USER_STARTED broadcast |
| 909 | Intent intent = new Intent(Intent.ACTION_USER_STARTED); |
| 910 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 911 | | Intent.FLAG_RECEIVER_FOREGROUND); |
| 912 | intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 913 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 914 | null, null, 0, null, null, null, AppOpsManager.OP_NONE, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 915 | null, false, false, MY_PID, SYSTEM_UID, userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 918 | if (foreground) { |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 919 | moveUserToForegroundLocked(uss, oldUserId, userId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 920 | } else { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 921 | finishUserBoot(uss); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | if (needStart) { |
| 925 | Intent intent = new Intent(Intent.ACTION_USER_STARTING); |
| 926 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 927 | intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 928 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 929 | null, new IIntentReceiver.Stub() { |
| 930 | @Override |
| 931 | public void performReceive(Intent intent, int resultCode, |
| 932 | String data, Bundle extras, boolean ordered, boolean sticky, |
| 933 | int sendingUser) throws RemoteException { |
| 934 | } |
| 935 | }, 0, null, null, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 936 | new String[] {INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE, |
| 937 | null, true, false, MY_PID, SYSTEM_UID, UserHandle.USER_ALL); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | } finally { |
| 941 | Binder.restoreCallingIdentity(ident); |
| 942 | } |
| 943 | |
| 944 | return true; |
| 945 | } |
| 946 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 947 | /** |
| 948 | * Start user, if its not already running, and bring it to foreground. |
| 949 | */ |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 950 | void startUserInForeground(final int targetUserId) { |
| 951 | boolean success = startUser(targetUserId, /* foreground */ true); |
| 952 | if (!success) { |
| 953 | mInjector.getWindowManager().setSwitchingUser(false); |
| 954 | } |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 957 | boolean unlockUser(final int userId, byte[] token, byte[] secret, IProgressListener listener) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 958 | if (mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 959 | != PackageManager.PERMISSION_GRANTED) { |
| 960 | String msg = "Permission Denial: unlockUser() from pid=" |
| 961 | + Binder.getCallingPid() |
| 962 | + ", uid=" + Binder.getCallingUid() |
| 963 | + " requires " + INTERACT_ACROSS_USERS_FULL; |
| 964 | Slog.w(TAG, msg); |
| 965 | throw new SecurityException(msg); |
| 966 | } |
| 967 | |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 968 | final long binderToken = Binder.clearCallingIdentity(); |
| 969 | try { |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 970 | return unlockUserCleared(userId, token, secret, listener); |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 971 | } finally { |
| 972 | Binder.restoreCallingIdentity(binderToken); |
| 973 | } |
| 974 | } |
| 975 | |
Jeff Sharkey | b9fe537 | 2015-12-03 15:23:08 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Attempt to unlock user without a credential token. This typically |
| 978 | * succeeds when the device doesn't have credential-encrypted storage, or |
| 979 | * when the the credential-encrypted storage isn't tied to a user-provided |
| 980 | * PIN or pattern. |
| 981 | */ |
| 982 | boolean maybeUnlockUser(final int userId) { |
| 983 | // Try unlocking storage using empty token |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 984 | return unlockUserCleared(userId, null, null, null); |
| 985 | } |
| 986 | |
| 987 | private static void notifyFinished(int userId, IProgressListener listener) { |
| 988 | if (listener == null) return; |
| 989 | try { |
| 990 | listener.onFinished(userId, null); |
| 991 | } catch (RemoteException ignored) { |
| 992 | } |
Jeff Sharkey | b9fe537 | 2015-12-03 15:23:08 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 995 | boolean unlockUserCleared(final int userId, byte[] token, byte[] secret, |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 996 | IProgressListener listener) { |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 997 | UserState uss; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 998 | synchronized (mLock) { |
Ricky Wai | 4266fee | 2016-05-23 15:33:04 +0100 | [diff] [blame] | 999 | // TODO Move this block outside of synchronized if it causes lock contention |
| 1000 | if (!StorageManager.isUserKeyUnlocked(userId)) { |
| 1001 | final UserInfo userInfo = getUserInfo(userId); |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1002 | final IStorageManager storageManager = getStorageManager(); |
Ricky Wai | 4266fee | 2016-05-23 15:33:04 +0100 | [diff] [blame] | 1003 | try { |
| 1004 | // We always want to unlock user storage, even user is not started yet |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1005 | storageManager.unlockUserKey(userId, userInfo.serialNumber, token, secret); |
Ricky Wai | 4266fee | 2016-05-23 15:33:04 +0100 | [diff] [blame] | 1006 | } catch (RemoteException | RuntimeException e) { |
| 1007 | Slog.w(TAG, "Failed to unlock: " + e.getMessage()); |
| 1008 | } |
| 1009 | } |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 1010 | // Bail if user isn't actually running, otherwise register the given |
| 1011 | // listener to watch for unlock progress |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 1012 | uss = mStartedUsers.get(userId); |
Ricky Wai | f6ef828 | 2016-04-14 10:00:22 +0100 | [diff] [blame] | 1013 | if (uss == null) { |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 1014 | notifyFinished(userId, listener); |
Ricky Wai | f6ef828 | 2016-04-14 10:00:22 +0100 | [diff] [blame] | 1015 | return false; |
Jeff Sharkey | 84a4c97 | 2016-04-18 15:36:39 -0600 | [diff] [blame] | 1016 | } else { |
| 1017 | uss.mUnlockProgress.addListener(listener); |
Jeff Sharkey | 24d9491 | 2016-07-07 12:33:48 -0600 | [diff] [blame] | 1018 | uss.tokenProvided = (token != null); |
Jeff Sharkey | bd91e2f | 2016-03-22 15:32:31 -0600 | [diff] [blame] | 1019 | } |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 1020 | } |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 1021 | |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 1022 | finishUserUnlocking(uss); |
| 1023 | |
| 1024 | final ArraySet<Integer> childProfilesToUnlock = new ArraySet<>(); |
Jorim Jaggi | 526694e | 2016-08-03 17:15:23 +0200 | [diff] [blame] | 1025 | synchronized (mLock) { |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 1026 | |
Jeff Sharkey | 7661a31 | 2016-04-07 12:39:57 -0600 | [diff] [blame] | 1027 | // We just unlocked a user, so let's now attempt to unlock any |
| 1028 | // managed profiles under that user. |
Jeff Sharkey | 5dab713 | 2016-04-07 01:20:58 -0600 | [diff] [blame] | 1029 | for (int i = 0; i < mStartedUsers.size(); i++) { |
| 1030 | final int testUserId = mStartedUsers.keyAt(i); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1031 | final UserInfo parent = mInjector.getUserManager().getProfileParent(testUserId); |
Jeff Sharkey | 5dab713 | 2016-04-07 01:20:58 -0600 | [diff] [blame] | 1032 | if (parent != null && parent.id == userId && testUserId != userId) { |
Jeff Sharkey | 7661a31 | 2016-04-07 12:39:57 -0600 | [diff] [blame] | 1033 | Slog.d(TAG, "User " + testUserId + " (parent " + parent.id |
| 1034 | + "): attempting unlock because parent was just unlocked"); |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 1035 | childProfilesToUnlock.add(testUserId); |
Jeff Sharkey | 5dab713 | 2016-04-07 01:20:58 -0600 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
Jorim Jaggi | 6f4d7b3 | 2016-08-01 14:31:02 +0200 | [diff] [blame] | 1040 | final int size = childProfilesToUnlock.size(); |
| 1041 | for (int i = 0; i < size; i++) { |
| 1042 | maybeUnlockUser(childProfilesToUnlock.valueAt(i)); |
| 1043 | } |
| 1044 | |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 1045 | return true; |
| 1046 | } |
| 1047 | |
Suprabh Shukla | 4fe508b | 2015-11-20 18:22:57 -0800 | [diff] [blame] | 1048 | void showUserSwitchDialog(Pair<UserInfo, UserInfo> fromToUserPair) { |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1049 | // The dialog will show and then initiate the user switch by calling startUserInForeground |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1050 | mInjector.showUserSwitchingDialog(fromToUserPair.first, fromToUserPair.second); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1053 | void dispatchForegroundProfileChanged(int userId) { |
| 1054 | final int observerCount = mUserSwitchObservers.beginBroadcast(); |
| 1055 | for (int i = 0; i < observerCount; i++) { |
| 1056 | try { |
| 1057 | mUserSwitchObservers.getBroadcastItem(i).onForegroundProfileSwitch(userId); |
| 1058 | } catch (RemoteException e) { |
| 1059 | // Ignore |
| 1060 | } |
| 1061 | } |
| 1062 | mUserSwitchObservers.finishBroadcast(); |
| 1063 | } |
| 1064 | |
| 1065 | /** Called on handler thread */ |
| 1066 | void dispatchUserSwitchComplete(int userId) { |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1067 | mInjector.getWindowManager().setSwitchingUser(false); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1068 | final int observerCount = mUserSwitchObservers.beginBroadcast(); |
| 1069 | for (int i = 0; i < observerCount; i++) { |
| 1070 | try { |
| 1071 | mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(userId); |
| 1072 | } catch (RemoteException e) { |
| 1073 | } |
| 1074 | } |
| 1075 | mUserSwitchObservers.finishBroadcast(); |
| 1076 | } |
| 1077 | |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 1078 | void dispatchLockedBootComplete(int userId) { |
| 1079 | final int observerCount = mUserSwitchObservers.beginBroadcast(); |
| 1080 | for (int i = 0; i < observerCount; i++) { |
| 1081 | try { |
| 1082 | mUserSwitchObservers.getBroadcastItem(i).onLockedBootComplete(userId); |
| 1083 | } catch (RemoteException e) { |
| 1084 | // Ignore |
| 1085 | } |
| 1086 | } |
| 1087 | mUserSwitchObservers.finishBroadcast(); |
| 1088 | } |
| 1089 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 1090 | private void stopBackgroundUsersIfEnforced(int oldUserId) { |
| 1091 | // Never stop system user |
| 1092 | if (oldUserId == UserHandle.USER_SYSTEM) { |
| 1093 | return; |
| 1094 | } |
| 1095 | // For now, only check for user restriction. Additional checks can be added here |
| 1096 | boolean disallowRunInBg = hasUserRestriction(UserManager.DISALLOW_RUN_IN_BACKGROUND, |
| 1097 | oldUserId); |
| 1098 | if (!disallowRunInBg) { |
| 1099 | return; |
| 1100 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1101 | synchronized (mLock) { |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 1102 | if (DEBUG_MU) Slog.i(TAG, "stopBackgroundUsersIfEnforced stopping " + oldUserId |
| 1103 | + " and related users"); |
| 1104 | stopUsersLocked(oldUserId, false, null); |
| 1105 | } |
| 1106 | } |
| 1107 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1108 | void timeoutUserSwitch(UserState uss, int oldUserId, int newUserId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1109 | synchronized (mLock) { |
| 1110 | Slog.wtf(TAG, "User switch timeout: from " + oldUserId + " to " + newUserId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1111 | sendContinueUserSwitchLocked(uss, oldUserId, newUserId); |
| 1112 | } |
| 1113 | } |
| 1114 | |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 1115 | void dispatchUserSwitch(final UserState uss, final int oldUserId, final int newUserId) { |
| 1116 | Slog.d(TAG, "Dispatch onUserSwitching oldUser #" + oldUserId + " newUser #" + newUserId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1117 | final int observerCount = mUserSwitchObservers.beginBroadcast(); |
| 1118 | if (observerCount > 0) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1119 | final ArraySet<String> curWaitingUserSwitchCallbacks = new ArraySet<>(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1120 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1121 | uss.switching = true; |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1122 | mCurWaitingUserSwitchCallbacks = curWaitingUserSwitchCallbacks; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1123 | } |
Fyodor Kupolov | 3864183 | 2016-06-28 17:37:09 -0700 | [diff] [blame] | 1124 | final AtomicInteger waitingCallbacksCount = new AtomicInteger(observerCount); |
Fyodor Kupolov | 0e0986e | 2016-09-22 18:01:36 -0700 | [diff] [blame] | 1125 | final long dispatchStartedTime = SystemClock.elapsedRealtime(); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1126 | for (int i = 0; i < observerCount; i++) { |
| 1127 | try { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1128 | // Prepend with unique prefix to guarantee that keys are unique |
| 1129 | final String name = "#" + i + " " + mUserSwitchObservers.getBroadcastCookie(i); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1130 | synchronized (mLock) { |
Fyodor Kupolov | 599d43b | 2016-06-24 13:46:18 -0700 | [diff] [blame] | 1131 | curWaitingUserSwitchCallbacks.add(name); |
| 1132 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1133 | final IRemoteCallback callback = new IRemoteCallback.Stub() { |
| 1134 | @Override |
| 1135 | public void sendResult(Bundle data) throws RemoteException { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1136 | synchronized (mLock) { |
Fyodor Kupolov | 0e0986e | 2016-09-22 18:01:36 -0700 | [diff] [blame] | 1137 | long delay = SystemClock.elapsedRealtime() - dispatchStartedTime; |
| 1138 | if (delay > USER_SWITCH_TIMEOUT) { |
| 1139 | Slog.wtf(TAG, "User switch timeout: observer " + name |
| 1140 | + " sent result after " + delay + " ms"); |
| 1141 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1142 | // Early return if this session is no longer valid |
| 1143 | if (curWaitingUserSwitchCallbacks |
| 1144 | != mCurWaitingUserSwitchCallbacks) { |
| 1145 | return; |
| 1146 | } |
| 1147 | curWaitingUserSwitchCallbacks.remove(name); |
| 1148 | // Continue switching if all callbacks have been notified |
Fyodor Kupolov | 3864183 | 2016-06-28 17:37:09 -0700 | [diff] [blame] | 1149 | if (waitingCallbacksCount.decrementAndGet() == 0) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1150 | sendContinueUserSwitchLocked(uss, oldUserId, newUserId); |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | }; |
| 1155 | mUserSwitchObservers.getBroadcastItem(i).onUserSwitching(newUserId, callback); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1156 | } catch (RemoteException e) { |
| 1157 | } |
| 1158 | } |
| 1159 | } else { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1160 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1161 | sendContinueUserSwitchLocked(uss, oldUserId, newUserId); |
| 1162 | } |
| 1163 | } |
| 1164 | mUserSwitchObservers.finishBroadcast(); |
| 1165 | } |
| 1166 | |
| 1167 | void sendContinueUserSwitchLocked(UserState uss, int oldUserId, int newUserId) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1168 | mCurWaitingUserSwitchCallbacks = null; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1169 | mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG); |
| 1170 | mHandler.sendMessage(mHandler.obtainMessage(ActivityManagerService.CONTINUE_USER_SWITCH_MSG, |
| 1171 | oldUserId, newUserId, uss)); |
| 1172 | } |
| 1173 | |
| 1174 | void continueUserSwitch(UserState uss, int oldUserId, int newUserId) { |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 1175 | Slog.d(TAG, "Continue user switch oldUser #" + oldUserId + ", newUser #" + newUserId); |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 1176 | if (mUserSwitchUiEnabled) { |
| 1177 | synchronized (mLock) { |
| 1178 | mInjector.getWindowManager().stopFreezingScreen(); |
| 1179 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1180 | } |
Fyodor Kupolov | c94c249 | 2016-04-20 17:44:00 -0700 | [diff] [blame] | 1181 | uss.switching = false; |
| 1182 | mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG); |
| 1183 | mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_COMPLETE_MSG, |
| 1184 | newUserId, 0)); |
Lenka Trochtova | b4484ba | 2015-12-16 12:32:31 +0100 | [diff] [blame] | 1185 | stopGuestOrEphemeralUserIfBackground(); |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 1186 | stopBackgroundUsersIfEnforced(oldUserId); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | void moveUserToForegroundLocked(UserState uss, int oldUserId, int newUserId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1190 | boolean homeInFront = mInjector.stackSupervisorSwitchUserLocked(newUserId, uss); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1191 | if (homeInFront) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1192 | mInjector.startHomeActivityLocked(newUserId, "moveUserToForeground"); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1193 | } else { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1194 | mInjector.stackSupervisorResumeFocusedStackTopActivityLocked(); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1195 | } |
| 1196 | EventLogTags.writeAmSwitchUser(newUserId); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1197 | sendUserSwitchBroadcastsLocked(oldUserId, newUserId); |
| 1198 | } |
| 1199 | |
| 1200 | void sendUserSwitchBroadcastsLocked(int oldUserId, int newUserId) { |
| 1201 | long ident = Binder.clearCallingIdentity(); |
| 1202 | try { |
| 1203 | Intent intent; |
| 1204 | if (oldUserId >= 0) { |
| 1205 | // Send USER_BACKGROUND broadcast to all profiles of the outgoing user |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1206 | List<UserInfo> profiles = mInjector.getUserManager().getProfiles(oldUserId, false); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1207 | int count = profiles.size(); |
| 1208 | for (int i = 0; i < count; i++) { |
| 1209 | int profileUserId = profiles.get(i).id; |
| 1210 | intent = new Intent(Intent.ACTION_USER_BACKGROUND); |
| 1211 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 1212 | | Intent.FLAG_RECEIVER_FOREGROUND); |
| 1213 | intent.putExtra(Intent.EXTRA_USER_HANDLE, profileUserId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1214 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1215 | null, null, 0, null, null, null, AppOpsManager.OP_NONE, |
| 1216 | null, false, false, MY_PID, SYSTEM_UID, profileUserId); |
| 1217 | } |
| 1218 | } |
| 1219 | if (newUserId >= 0) { |
| 1220 | // Send USER_FOREGROUND broadcast to all profiles of the incoming user |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1221 | List<UserInfo> profiles = mInjector.getUserManager().getProfiles(newUserId, false); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1222 | int count = profiles.size(); |
| 1223 | for (int i = 0; i < count; i++) { |
| 1224 | int profileUserId = profiles.get(i).id; |
| 1225 | intent = new Intent(Intent.ACTION_USER_FOREGROUND); |
| 1226 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 1227 | | Intent.FLAG_RECEIVER_FOREGROUND); |
| 1228 | intent.putExtra(Intent.EXTRA_USER_HANDLE, profileUserId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1229 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1230 | null, null, 0, null, null, null, AppOpsManager.OP_NONE, |
| 1231 | null, false, false, MY_PID, SYSTEM_UID, profileUserId); |
| 1232 | } |
| 1233 | intent = new Intent(Intent.ACTION_USER_SWITCHED); |
| 1234 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY |
| 1235 | | Intent.FLAG_RECEIVER_FOREGROUND); |
| 1236 | intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1237 | mInjector.broadcastIntentLocked(intent, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1238 | null, null, 0, null, null, |
| 1239 | new String[] {android.Manifest.permission.MANAGE_USERS}, |
| 1240 | AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, |
| 1241 | UserHandle.USER_ALL); |
| 1242 | } |
| 1243 | } finally { |
| 1244 | Binder.restoreCallingIdentity(ident); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | |
| 1249 | int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll, |
| 1250 | int allowMode, String name, String callerPackage) { |
| 1251 | final int callingUserId = UserHandle.getUserId(callingUid); |
| 1252 | if (callingUserId == userId) { |
| 1253 | return userId; |
| 1254 | } |
| 1255 | |
| 1256 | // Note that we may be accessing mCurrentUserId outside of a lock... |
| 1257 | // shouldn't be a big deal, if this is being called outside |
| 1258 | // of a locked context there is intrinsically a race with |
| 1259 | // the value the caller will receive and someone else changing it. |
| 1260 | // We assume that USER_CURRENT_OR_SELF will use the current user; later |
| 1261 | // we will switch to the calling user if access to the current user fails. |
| 1262 | int targetUserId = unsafeConvertIncomingUserLocked(userId); |
| 1263 | |
| 1264 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 1265 | final boolean allow; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1266 | if (mInjector.checkComponentPermission(INTERACT_ACROSS_USERS_FULL, callingPid, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1267 | callingUid, -1, true) == PackageManager.PERMISSION_GRANTED) { |
| 1268 | // If the caller has this permission, they always pass go. And collect $200. |
| 1269 | allow = true; |
| 1270 | } else if (allowMode == ALLOW_FULL_ONLY) { |
| 1271 | // We require full access, sucks to be you. |
| 1272 | allow = false; |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1273 | } else if (mInjector.checkComponentPermission(INTERACT_ACROSS_USERS, callingPid, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1274 | callingUid, -1, true) != PackageManager.PERMISSION_GRANTED) { |
| 1275 | // If the caller does not have either permission, they are always doomed. |
| 1276 | allow = false; |
| 1277 | } else if (allowMode == ALLOW_NON_FULL) { |
| 1278 | // We are blanket allowing non-full access, you lucky caller! |
| 1279 | allow = true; |
| 1280 | } else if (allowMode == ALLOW_NON_FULL_IN_PROFILE) { |
| 1281 | // We may or may not allow this depending on whether the two users are |
| 1282 | // in the same profile. |
| 1283 | allow = isSameProfileGroup(callingUserId, targetUserId); |
| 1284 | } else { |
| 1285 | throw new IllegalArgumentException("Unknown mode: " + allowMode); |
| 1286 | } |
| 1287 | if (!allow) { |
| 1288 | if (userId == UserHandle.USER_CURRENT_OR_SELF) { |
| 1289 | // In this case, they would like to just execute as their |
| 1290 | // owner user instead of failing. |
| 1291 | targetUserId = callingUserId; |
| 1292 | } else { |
| 1293 | StringBuilder builder = new StringBuilder(128); |
| 1294 | builder.append("Permission Denial: "); |
| 1295 | builder.append(name); |
| 1296 | if (callerPackage != null) { |
| 1297 | builder.append(" from "); |
| 1298 | builder.append(callerPackage); |
| 1299 | } |
| 1300 | builder.append(" asks to run as user "); |
| 1301 | builder.append(userId); |
| 1302 | builder.append(" but is calling from user "); |
| 1303 | builder.append(UserHandle.getUserId(callingUid)); |
| 1304 | builder.append("; this requires "); |
| 1305 | builder.append(INTERACT_ACROSS_USERS_FULL); |
| 1306 | if (allowMode != ALLOW_FULL_ONLY) { |
| 1307 | builder.append(" or "); |
| 1308 | builder.append(INTERACT_ACROSS_USERS); |
| 1309 | } |
| 1310 | String msg = builder.toString(); |
| 1311 | Slog.w(TAG, msg); |
| 1312 | throw new SecurityException(msg); |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | if (!allowAll && targetUserId < 0) { |
| 1317 | throw new IllegalArgumentException( |
| 1318 | "Call does not support special user #" + targetUserId); |
| 1319 | } |
| 1320 | // Check shell permission |
| 1321 | if (callingUid == Process.SHELL_UID && targetUserId >= UserHandle.USER_SYSTEM) { |
| 1322 | if (hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, targetUserId)) { |
| 1323 | throw new SecurityException("Shell does not have permission to access user " |
| 1324 | + targetUserId + "\n " + Debug.getCallers(3)); |
| 1325 | } |
| 1326 | } |
| 1327 | return targetUserId; |
| 1328 | } |
| 1329 | |
| 1330 | int unsafeConvertIncomingUserLocked(int userId) { |
| 1331 | return (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) |
| 1332 | ? getCurrentUserIdLocked(): userId; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1335 | void registerUserSwitchObserver(IUserSwitchObserver observer, String name) { |
| 1336 | Preconditions.checkNotNull(name, "Observer name cannot be null"); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1337 | if (mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1338 | != PackageManager.PERMISSION_GRANTED) { |
| 1339 | final String msg = "Permission Denial: registerUserSwitchObserver() from pid=" |
| 1340 | + Binder.getCallingPid() |
| 1341 | + ", uid=" + Binder.getCallingUid() |
| 1342 | + " requires " + INTERACT_ACROSS_USERS_FULL; |
| 1343 | Slog.w(TAG, msg); |
| 1344 | throw new SecurityException(msg); |
| 1345 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1346 | mUserSwitchObservers.register(observer, name); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | void unregisterUserSwitchObserver(IUserSwitchObserver observer) { |
| 1350 | mUserSwitchObservers.unregister(observer); |
| 1351 | } |
| 1352 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1353 | UserState getStartedUserStateLocked(int userId) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1354 | return mStartedUsers.get(userId); |
| 1355 | } |
| 1356 | |
| 1357 | boolean hasStartedUserState(int userId) { |
| 1358 | return mStartedUsers.get(userId) != null; |
| 1359 | } |
| 1360 | |
| 1361 | private void updateStartedUserArrayLocked() { |
| 1362 | int num = 0; |
| 1363 | for (int i = 0; i < mStartedUsers.size(); i++) { |
| 1364 | UserState uss = mStartedUsers.valueAt(i); |
| 1365 | // This list does not include stopping users. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1366 | if (uss.state != UserState.STATE_STOPPING |
| 1367 | && uss.state != UserState.STATE_SHUTDOWN) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1368 | num++; |
| 1369 | } |
| 1370 | } |
| 1371 | mStartedUserArray = new int[num]; |
| 1372 | num = 0; |
| 1373 | for (int i = 0; i < mStartedUsers.size(); i++) { |
| 1374 | UserState uss = mStartedUsers.valueAt(i); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1375 | if (uss.state != UserState.STATE_STOPPING |
| 1376 | && uss.state != UserState.STATE_SHUTDOWN) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1377 | mStartedUserArray[num++] = mStartedUsers.keyAt(i); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | void sendBootCompletedLocked(IIntentReceiver resultTo) { |
| 1383 | for (int i = 0; i < mStartedUsers.size(); i++) { |
| 1384 | UserState uss = mStartedUsers.valueAt(i); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1385 | finishUserBoot(uss, resultTo); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1389 | void onSystemReady() { |
| 1390 | updateCurrentProfileIdsLocked(); |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1393 | /** |
| 1394 | * Refreshes the list of users related to the current user when either a |
| 1395 | * user switch happens or when a new related user is started in the |
| 1396 | * background. |
| 1397 | */ |
Wale Ogunwale | f80170f | 2016-02-04 15:12:29 -0800 | [diff] [blame] | 1398 | private void updateCurrentProfileIdsLocked() { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1399 | final List<UserInfo> profiles = mInjector.getUserManager().getProfiles(mCurrentUserId, |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1400 | false /* enabledOnly */); |
| 1401 | int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null |
| 1402 | for (int i = 0; i < currentProfileIds.length; i++) { |
| 1403 | currentProfileIds[i] = profiles.get(i).id; |
| 1404 | } |
| 1405 | mCurrentProfileIds = currentProfileIds; |
| 1406 | |
| 1407 | synchronized (mUserProfileGroupIdsSelfLocked) { |
| 1408 | mUserProfileGroupIdsSelfLocked.clear(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1409 | final List<UserInfo> users = mInjector.getUserManager().getUsers(false); |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1410 | for (int i = 0; i < users.size(); i++) { |
| 1411 | UserInfo user = users.get(i); |
| 1412 | if (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) { |
| 1413 | mUserProfileGroupIdsSelfLocked.put(user.id, user.profileGroupId); |
| 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | int[] getStartedUserArrayLocked() { |
| 1420 | return mStartedUserArray; |
| 1421 | } |
| 1422 | |
Nicolas Prevot | 1219c92 | 2016-06-20 17:25:12 +0100 | [diff] [blame] | 1423 | boolean isUserStoppingOrShuttingDownLocked(int userId) { |
| 1424 | UserState state = getStartedUserStateLocked(userId); |
| 1425 | if (state == null) { |
| 1426 | return false; |
| 1427 | } |
| 1428 | return state.state == UserState.STATE_STOPPING |
| 1429 | || state.state == UserState.STATE_SHUTDOWN; |
| 1430 | } |
| 1431 | |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 1432 | boolean isUserRunningLocked(int userId, int flags) { |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1433 | UserState state = getStartedUserStateLocked(userId); |
| 1434 | if (state == null) { |
| 1435 | return false; |
| 1436 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 1437 | if ((flags & ActivityManager.FLAG_OR_STOPPED) != 0) { |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1438 | return true; |
| 1439 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1440 | if ((flags & ActivityManager.FLAG_AND_LOCKED) != 0) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1441 | switch (state.state) { |
| 1442 | case UserState.STATE_BOOTING: |
| 1443 | case UserState.STATE_RUNNING_LOCKED: |
| 1444 | return true; |
| 1445 | default: |
| 1446 | return false; |
| 1447 | } |
| 1448 | } |
| 1449 | if ((flags & ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED) != 0) { |
| 1450 | switch (state.state) { |
| 1451 | case UserState.STATE_RUNNING_UNLOCKING: |
| 1452 | case UserState.STATE_RUNNING_UNLOCKED: |
| 1453 | return true; |
| 1454 | default: |
| 1455 | return false; |
| 1456 | } |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 1457 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1458 | if ((flags & ActivityManager.FLAG_AND_UNLOCKED) != 0) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1459 | switch (state.state) { |
| 1460 | case UserState.STATE_RUNNING_UNLOCKED: |
| 1461 | return true; |
| 1462 | default: |
| 1463 | return false; |
| 1464 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | // One way or another, we're running! |
| 1468 | return true; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1471 | UserInfo getCurrentUser() { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1472 | if ((mInjector.checkCallingPermission(INTERACT_ACROSS_USERS) |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1473 | != PackageManager.PERMISSION_GRANTED) && ( |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1474 | mInjector.checkCallingPermission(INTERACT_ACROSS_USERS_FULL) |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1475 | != PackageManager.PERMISSION_GRANTED)) { |
| 1476 | String msg = "Permission Denial: getCurrentUser() from pid=" |
| 1477 | + Binder.getCallingPid() |
| 1478 | + ", uid=" + Binder.getCallingUid() |
| 1479 | + " requires " + INTERACT_ACROSS_USERS; |
| 1480 | Slog.w(TAG, msg); |
| 1481 | throw new SecurityException(msg); |
| 1482 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1483 | synchronized (mLock) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1484 | return getCurrentUserLocked(); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | UserInfo getCurrentUserLocked() { |
| 1489 | int userId = mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1490 | return getUserInfo(userId); |
| 1491 | } |
| 1492 | |
| 1493 | int getCurrentOrTargetUserIdLocked() { |
| 1494 | return mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | int getCurrentUserIdLocked() { |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1498 | return mCurrentUserId; |
| 1499 | } |
| 1500 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 1501 | private boolean isCurrentUserLocked(int userId) { |
Amith Yamasani | 458ac46 | 2015-12-18 11:21:31 -0800 | [diff] [blame] | 1502 | return userId == getCurrentOrTargetUserIdLocked(); |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1505 | int setTargetUserIdLocked(int targetUserId) { |
| 1506 | return mTargetUserId = targetUserId; |
| 1507 | } |
| 1508 | |
| 1509 | int[] getUsers() { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1510 | UserManagerService ums = mInjector.getUserManager(); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1511 | return ums != null ? ums.getUserIds() : new int[] { 0 }; |
| 1512 | } |
| 1513 | |
| 1514 | UserInfo getUserInfo(int userId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1515 | return mInjector.getUserManager().getUserInfo(userId); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | int[] getUserIds() { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1519 | return mInjector.getUserManager().getUserIds(); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | boolean exists(int userId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1523 | return mInjector.getUserManager().exists(userId); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | boolean hasUserRestriction(String restriction, int userId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1527 | return mInjector.getUserManager().hasUserRestriction(restriction, userId); |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | Set<Integer> getProfileIds(int userId) { |
| 1531 | Set<Integer> userIds = new HashSet<>(); |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1532 | final List<UserInfo> profiles = mInjector.getUserManager().getProfiles(userId, |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1533 | false /* enabledOnly */); |
| 1534 | for (UserInfo user : profiles) { |
| 1535 | userIds.add(user.id); |
| 1536 | } |
| 1537 | return userIds; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | boolean isSameProfileGroup(int callingUserId, int targetUserId) { |
Makoto Onuki | 8198dea | 2016-07-28 13:10:42 -0700 | [diff] [blame] | 1541 | if (callingUserId == targetUserId) { |
| 1542 | return true; |
| 1543 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1544 | synchronized (mUserProfileGroupIdsSelfLocked) { |
| 1545 | int callingProfile = mUserProfileGroupIdsSelfLocked.get(callingUserId, |
| 1546 | UserInfo.NO_PROFILE_GROUP_ID); |
| 1547 | int targetProfile = mUserProfileGroupIdsSelfLocked.get(targetUserId, |
| 1548 | UserInfo.NO_PROFILE_GROUP_ID); |
| 1549 | return callingProfile != UserInfo.NO_PROFILE_GROUP_ID |
| 1550 | && callingProfile == targetProfile; |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | boolean isCurrentProfileLocked(int userId) { |
| 1555 | return ArrayUtils.contains(mCurrentProfileIds, userId); |
| 1556 | } |
| 1557 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 1558 | int[] getCurrentProfileIdsLocked() { |
| 1559 | return mCurrentProfileIds; |
| 1560 | } |
| 1561 | |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 1562 | /** |
| 1563 | * Returns whether the given user requires credential entry at this time. This is used to |
| 1564 | * intercept activity launches for work apps when the Work Challenge is present. |
| 1565 | */ |
| 1566 | boolean shouldConfirmCredentials(int userId) { |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1567 | synchronized (mLock) { |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 1568 | if (mStartedUsers.get(userId) == null) { |
| 1569 | return false; |
| 1570 | } |
| 1571 | } |
Clara Bayarri | a177111 | 2015-12-18 16:29:18 +0000 | [diff] [blame] | 1572 | if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) { |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 1573 | return false; |
| 1574 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1575 | final KeyguardManager km = mInjector.getKeyguardManager(); |
Tony Mak | ae13e18 | 2016-05-17 16:36:14 +0100 | [diff] [blame] | 1576 | return km.isDeviceLocked(userId) && km.isDeviceSecure(userId); |
Clara Bayarri | ea9b10e | 2015-12-04 15:36:26 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Tony Mak | 8c536f9 | 2016-03-21 12:20:41 +0000 | [diff] [blame] | 1579 | boolean isLockScreenDisabled(@UserIdInt int userId) { |
| 1580 | return mLockPatternUtils.isLockScreenDisabled(userId); |
| 1581 | } |
| 1582 | |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1583 | void dump(PrintWriter pw, boolean dumpAll) { |
| 1584 | pw.println(" mStartedUsers:"); |
| 1585 | for (int i = 0; i < mStartedUsers.size(); i++) { |
| 1586 | UserState uss = mStartedUsers.valueAt(i); |
| 1587 | pw.print(" User #"); pw.print(uss.mHandle.getIdentifier()); |
| 1588 | pw.print(": "); uss.dump("", pw); |
| 1589 | } |
| 1590 | pw.print(" mStartedUserArray: ["); |
| 1591 | for (int i = 0; i < mStartedUserArray.length; i++) { |
| 1592 | if (i > 0) pw.print(", "); |
| 1593 | pw.print(mStartedUserArray[i]); |
| 1594 | } |
| 1595 | pw.println("]"); |
| 1596 | pw.print(" mUserLru: ["); |
| 1597 | for (int i = 0; i < mUserLru.size(); i++) { |
| 1598 | if (i > 0) pw.print(", "); |
| 1599 | pw.print(mUserLru.get(i)); |
| 1600 | } |
| 1601 | pw.println("]"); |
| 1602 | if (dumpAll) { |
| 1603 | pw.print(" mStartedUserArray: "); pw.println(Arrays.toString(mStartedUserArray)); |
| 1604 | } |
| 1605 | synchronized (mUserProfileGroupIdsSelfLocked) { |
| 1606 | if (mUserProfileGroupIdsSelfLocked.size() > 0) { |
| 1607 | pw.println(" mUserProfileGroupIds:"); |
| 1608 | for (int i=0; i<mUserProfileGroupIdsSelfLocked.size(); i++) { |
| 1609 | pw.print(" User #"); |
| 1610 | pw.print(mUserProfileGroupIdsSelfLocked.keyAt(i)); |
| 1611 | pw.print(" -> profile #"); |
| 1612 | pw.println(mUserProfileGroupIdsSelfLocked.valueAt(i)); |
| 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | } |
Fyodor Kupolov | d6038db | 2016-06-22 16:53:19 -0700 | [diff] [blame] | 1617 | |
| 1618 | @VisibleForTesting |
| 1619 | static class Injector { |
| 1620 | private final ActivityManagerService mService; |
| 1621 | private UserManagerService mUserManager; |
| 1622 | private UserManagerInternal mUserManagerInternal; |
| 1623 | |
| 1624 | Injector(ActivityManagerService service) { |
| 1625 | mService = service; |
| 1626 | } |
| 1627 | |
| 1628 | protected Object getLock() { |
| 1629 | return mService; |
| 1630 | } |
| 1631 | |
| 1632 | protected Handler getHandler() { |
| 1633 | return mService.mHandler; |
| 1634 | } |
| 1635 | |
| 1636 | protected Context getContext() { |
| 1637 | return mService.mContext; |
| 1638 | } |
| 1639 | |
| 1640 | protected LockPatternUtils getLockPatternUtils() { |
| 1641 | return new LockPatternUtils(getContext()); |
| 1642 | } |
| 1643 | |
| 1644 | protected int broadcastIntentLocked(Intent intent, String resolvedType, |
| 1645 | IIntentReceiver resultTo, int resultCode, String resultData, |
| 1646 | Bundle resultExtras, String[] requiredPermissions, int appOp, Bundle bOptions, |
| 1647 | boolean ordered, boolean sticky, int callingPid, int callingUid, int userId) { |
| 1648 | return mService.broadcastIntentLocked(null, null, intent, resolvedType, resultTo, |
| 1649 | resultCode, resultData, resultExtras, requiredPermissions, appOp, bOptions, |
| 1650 | ordered, sticky, callingPid, callingUid, userId); |
| 1651 | } |
| 1652 | |
| 1653 | int checkCallingPermission(String permission) { |
| 1654 | return mService.checkCallingPermission(permission); |
| 1655 | } |
| 1656 | |
| 1657 | WindowManagerService getWindowManager() { |
| 1658 | return mService.mWindowManager; |
| 1659 | } |
| 1660 | void activityManagerOnUserStopped(int userId) { |
| 1661 | mService.onUserStoppedLocked(userId); |
| 1662 | } |
| 1663 | |
| 1664 | void systemServiceManagerCleanupUser(int userId) { |
| 1665 | mService.mSystemServiceManager.cleanupUser(userId); |
| 1666 | } |
| 1667 | |
| 1668 | void stackSupervisorRemoveUserLocked(int userId) { |
| 1669 | mService.mStackSupervisor.removeUserLocked(userId); |
| 1670 | } |
| 1671 | |
| 1672 | protected UserManagerService getUserManager() { |
| 1673 | if (mUserManager == null) { |
| 1674 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 1675 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 1676 | } |
| 1677 | return mUserManager; |
| 1678 | } |
| 1679 | |
| 1680 | UserManagerInternal getUserManagerInternal() { |
| 1681 | if (mUserManagerInternal == null) { |
| 1682 | mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); |
| 1683 | } |
| 1684 | return mUserManagerInternal; |
| 1685 | } |
| 1686 | |
| 1687 | KeyguardManager getKeyguardManager() { |
| 1688 | return mService.mContext.getSystemService(KeyguardManager.class); |
| 1689 | } |
| 1690 | |
| 1691 | void batteryStatsServiceNoteEvent(int code, String name, int uid) { |
| 1692 | mService.mBatteryStatsService.noteEvent(code, name, uid); |
| 1693 | } |
| 1694 | |
| 1695 | void systemServiceManagerStopUser(int userId) { |
| 1696 | mService.mSystemServiceManager.stopUser(userId); |
| 1697 | } |
| 1698 | |
| 1699 | void sendPreBootBroadcast(int userId, boolean quiet, final Runnable onFinish) { |
| 1700 | new PreBootBroadcaster(mService, userId, null, quiet) { |
| 1701 | @Override |
| 1702 | public void onFinished() { |
| 1703 | onFinish.run(); |
| 1704 | } |
| 1705 | }.sendNext(); |
| 1706 | } |
| 1707 | |
| 1708 | void activityManagerForceStopPackageLocked(int userId, String reason) { |
| 1709 | mService.forceStopPackageLocked(null, -1, false, false, true, false, false, |
| 1710 | userId, reason); |
| 1711 | }; |
| 1712 | |
| 1713 | int checkComponentPermission(String permission, int pid, int uid, int owningUid, |
| 1714 | boolean exported) { |
| 1715 | return mService.checkComponentPermission(permission, pid, uid, owningUid, exported); |
| 1716 | } |
| 1717 | |
| 1718 | boolean stackSupervisorSwitchUserLocked(int userId, UserState uss) { |
| 1719 | return mService.mStackSupervisor.switchUserLocked(userId, uss); |
| 1720 | } |
| 1721 | |
| 1722 | void startHomeActivityLocked(int userId, String reason) { |
| 1723 | mService.startHomeActivityLocked(userId, reason); |
| 1724 | } |
| 1725 | |
| 1726 | void stackSupervisorResumeFocusedStackTopActivityLocked() { |
| 1727 | mService.mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 1728 | } |
| 1729 | |
| 1730 | void stackSupervisorSetLockTaskModeLocked(TaskRecord task, int lockTaskModeState, |
| 1731 | String reason, boolean andResume) { |
| 1732 | mService.mStackSupervisor.setLockTaskModeLocked(task, lockTaskModeState, reason, |
| 1733 | andResume); |
| 1734 | } |
| 1735 | |
| 1736 | void updateUserConfigurationLocked() { |
| 1737 | mService.updateUserConfigurationLocked(); |
| 1738 | } |
| 1739 | |
| 1740 | void clearBroadcastQueueForUserLocked(int userId) { |
| 1741 | mService.clearBroadcastQueueForUserLocked(userId); |
| 1742 | } |
| 1743 | |
| 1744 | void enforceShellRestriction(String restriction, int userId) { |
| 1745 | mService.enforceShellRestriction(restriction, userId); |
| 1746 | } |
| 1747 | |
| 1748 | void showUserSwitchingDialog(UserInfo fromUser, UserInfo toUser) { |
| 1749 | Dialog d = new UserSwitchingDialog(mService, mService.mContext, fromUser, toUser, |
| 1750 | true /* above system */); |
| 1751 | d.show(); |
| 1752 | } |
| 1753 | } |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1754 | } |