Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.pm; |
| 18 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 21 | import android.app.ActivityManagerNative; |
| 22 | import android.app.IStopUserCallback; |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 28 | import android.content.pm.PackageManager.NameNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 29 | import android.content.pm.UserInfo; |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 30 | import android.graphics.Bitmap; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 31 | import android.os.Binder; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 32 | import android.os.Bundle; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 33 | import android.os.Environment; |
| 34 | import android.os.FileUtils; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 35 | import android.os.Handler; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 36 | import android.os.IUserManager; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 37 | import android.os.Message; |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 38 | import android.os.ParcelFileDescriptor; |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 39 | import android.os.Parcelable; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 40 | import android.os.Process; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 41 | import android.os.RemoteException; |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 42 | import android.os.ServiceManager; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 44 | import android.os.UserManager; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 45 | import android.util.AtomicFile; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 46 | import android.util.Log; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 47 | import android.util.Slog; |
| 48 | import android.util.SparseArray; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 49 | import android.util.SparseBooleanArray; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 50 | import android.util.TimeUtils; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 51 | import android.util.Xml; |
| 52 | |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 53 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 54 | import com.android.internal.app.IAppOpsService; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 55 | import com.android.internal.util.ArrayUtils; |
| 56 | import com.android.internal.util.FastXmlSerializer; |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 57 | import com.android.internal.util.XmlUtils; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 58 | |
| 59 | import org.xmlpull.v1.XmlPullParser; |
| 60 | import org.xmlpull.v1.XmlPullParserException; |
| 61 | import org.xmlpull.v1.XmlSerializer; |
| 62 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 63 | import java.io.BufferedOutputStream; |
| 64 | import java.io.File; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 65 | import java.io.FileDescriptor; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 66 | import java.io.FileInputStream; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 67 | import java.io.FileNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 68 | import java.io.FileOutputStream; |
| 69 | import java.io.IOException; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 70 | import java.io.PrintWriter; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 71 | import java.security.MessageDigest; |
| 72 | import java.security.NoSuchAlgorithmException; |
| 73 | import java.security.SecureRandom; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
| 75 | import java.util.List; |
| 76 | |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 77 | import libcore.io.IoUtils; |
| 78 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 79 | public class UserManagerService extends IUserManager.Stub { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 80 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 81 | private static final String LOG_TAG = "UserManagerService"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 82 | |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 83 | private static final boolean DBG = false; |
| 84 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 85 | private static final String TAG_NAME = "name"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 86 | private static final String ATTR_FLAGS = "flags"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 87 | private static final String ATTR_ICON_PATH = "icon"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 88 | private static final String ATTR_ID = "id"; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 89 | private static final String ATTR_CREATION_TIME = "created"; |
| 90 | private static final String ATTR_LAST_LOGGED_IN_TIME = "lastLoggedIn"; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 91 | private static final String ATTR_SALT = "salt"; |
| 92 | private static final String ATTR_PIN_HASH = "pinHash"; |
| 93 | private static final String ATTR_FAILED_ATTEMPTS = "failedAttempts"; |
| 94 | private static final String ATTR_LAST_RETRY_MS = "lastAttemptMs"; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 95 | private static final String ATTR_SERIAL_NO = "serialNumber"; |
| 96 | private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 97 | private static final String ATTR_PARTIAL = "partial"; |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 98 | private static final String ATTR_GUEST_TO_REMOVE = "guestToRemove"; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 99 | private static final String ATTR_USER_VERSION = "version"; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 100 | private static final String ATTR_PROFILE_GROUP_ID = "profileGroupId"; |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 101 | private static final String TAG_GUEST_RESTRICTIONS = "guestRestrictions"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 102 | private static final String TAG_USERS = "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 103 | private static final String TAG_USER = "user"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 104 | private static final String TAG_RESTRICTIONS = "restrictions"; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 105 | private static final String TAG_ENTRY = "entry"; |
| 106 | private static final String TAG_VALUE = "value"; |
| 107 | private static final String ATTR_KEY = "key"; |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 108 | private static final String ATTR_VALUE_TYPE = "type"; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 109 | private static final String ATTR_MULTIPLE = "m"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 110 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 111 | private static final String ATTR_TYPE_STRING_ARRAY = "sa"; |
| 112 | private static final String ATTR_TYPE_STRING = "s"; |
| 113 | private static final String ATTR_TYPE_BOOLEAN = "b"; |
Amith Yamasani | 5b5aa40 | 2014-06-01 20:10:14 -0700 | [diff] [blame] | 114 | private static final String ATTR_TYPE_INTEGER = "i"; |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 115 | private static final String ATTR_TYPE_BUNDLE = "B"; |
| 116 | private static final String ATTR_TYPE_BUNDLE_ARRAY = "BA"; |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 117 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 118 | private static final String USER_INFO_DIR = "system" + File.separator + "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 119 | private static final String USER_LIST_FILENAME = "userlist.xml"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 120 | private static final String USER_PHOTO_FILENAME = "photo.png"; |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 121 | private static final String USER_PHOTO_FILENAME_TMP = USER_PHOTO_FILENAME + ".tmp"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 122 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 123 | private static final String RESTRICTIONS_FILE_PREFIX = "res_"; |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 124 | private static final String XML_SUFFIX = ".xml"; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 125 | |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 126 | private static final int MIN_USER_ID = 10; |
| 127 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 128 | private static final int USER_VERSION = 5; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 129 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 130 | private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms |
| 131 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 132 | // Number of attempts before jumping to the next BACKOFF_TIMES slot |
| 133 | private static final int BACKOFF_INC_INTERVAL = 5; |
| 134 | |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 135 | // Maximum number of managed profiles permitted is 1. This cannot be increased |
| 136 | // without first making sure that the rest of the framework is prepared for it. |
| 137 | private static final int MAX_MANAGED_PROFILES = 1; |
| 138 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 139 | // Amount of time to force the user to wait before entering the PIN again, after failing |
| 140 | // BACKOFF_INC_INTERVAL times. |
| 141 | private static final int[] BACKOFF_TIMES = { 0, 30*1000, 60*1000, 5*60*1000, 30*60*1000 }; |
| 142 | |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 143 | static final int WRITE_USER_MSG = 1; |
| 144 | static final int WRITE_USER_DELAY = 2*1000; // 2 seconds |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 145 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 146 | private final Context mContext; |
| 147 | private final PackageManagerService mPm; |
| 148 | private final Object mInstallLock; |
| 149 | private final Object mPackagesLock; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 150 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 151 | private final Handler mHandler; |
| 152 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 153 | private final File mUsersDir; |
| 154 | private final File mUserListFile; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 155 | private final File mBaseUserPath; |
| 156 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 157 | private final SparseArray<UserInfo> mUsers = new SparseArray<UserInfo>(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 158 | private final SparseArray<Bundle> mUserRestrictions = new SparseArray<Bundle>(); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 159 | private final Bundle mGuestRestrictions = new Bundle(); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 160 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 161 | class RestrictionsPinState { |
| 162 | long salt; |
| 163 | String pinHash; |
| 164 | int failedAttempts; |
| 165 | long lastAttemptTime; |
| 166 | } |
| 167 | |
| 168 | private final SparseArray<RestrictionsPinState> mRestrictionsPinStates = |
| 169 | new SparseArray<RestrictionsPinState>(); |
| 170 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Set of user IDs being actively removed. Removed IDs linger in this set |
| 173 | * for several seconds to work around a VFS caching issue. |
| 174 | */ |
| 175 | // @GuardedBy("mPackagesLock") |
| 176 | private final SparseBooleanArray mRemovingUserIds = new SparseBooleanArray(); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 177 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 178 | private int[] mUserIds; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 179 | private int mNextSerialNumber; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 180 | private int mUserVersion = 0; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 181 | |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 182 | private IAppOpsService mAppOpsService; |
| 183 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 184 | private static UserManagerService sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 185 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 186 | public static UserManagerService getInstance() { |
| 187 | synchronized (UserManagerService.class) { |
| 188 | return sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 189 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 190 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Available for testing purposes. |
| 194 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 195 | UserManagerService(File dataDir, File baseUserPath) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 196 | this(null, null, new Object(), new Object(), dataDir, baseUserPath); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Called by package manager to create the service. This is closely |
| 201 | * associated with the package manager, and the given lock is the |
| 202 | * package manager's own lock. |
| 203 | */ |
| 204 | UserManagerService(Context context, PackageManagerService pm, |
| 205 | Object installLock, Object packagesLock) { |
| 206 | this(context, pm, installLock, packagesLock, |
| 207 | Environment.getDataDirectory(), |
| 208 | new File(Environment.getDataDirectory(), "user")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 211 | /** |
| 212 | * Available for testing purposes. |
| 213 | */ |
| 214 | private UserManagerService(Context context, PackageManagerService pm, |
| 215 | Object installLock, Object packagesLock, |
| 216 | File dataDir, File baseUserPath) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 217 | mContext = context; |
| 218 | mPm = pm; |
| 219 | mInstallLock = installLock; |
| 220 | mPackagesLock = packagesLock; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 221 | mHandler = new MainHandler(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 222 | synchronized (mInstallLock) { |
| 223 | synchronized (mPackagesLock) { |
| 224 | mUsersDir = new File(dataDir, USER_INFO_DIR); |
| 225 | mUsersDir.mkdirs(); |
| 226 | // Make zeroth user directory, for services to migrate their files to that location |
| 227 | File userZeroDir = new File(mUsersDir, "0"); |
| 228 | userZeroDir.mkdirs(); |
| 229 | mBaseUserPath = baseUserPath; |
| 230 | FileUtils.setPermissions(mUsersDir.toString(), |
| 231 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 232 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 233 | -1, -1); |
| 234 | mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); |
Amith Yamasani | da0b168 | 2014-11-21 12:58:17 -0800 | [diff] [blame] | 235 | initDefaultGuestRestrictions(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 236 | readUserListLocked(); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 237 | // Prune out any partially created/partially removed users. |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 238 | ArrayList<UserInfo> partials = new ArrayList<UserInfo>(); |
| 239 | for (int i = 0; i < mUsers.size(); i++) { |
| 240 | UserInfo ui = mUsers.valueAt(i); |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 241 | if ((ui.partial || ui.guestToRemove) && i != 0) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 242 | partials.add(ui); |
| 243 | } |
| 244 | } |
| 245 | for (int i = 0; i < partials.size(); i++) { |
| 246 | UserInfo ui = partials.get(i); |
| 247 | Slog.w(LOG_TAG, "Removing partially created user #" + i |
| 248 | + " (name=" + ui.name + ")"); |
| 249 | removeUserStateLocked(ui.id); |
| 250 | } |
| 251 | sInstance = this; |
| 252 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 253 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void systemReady() { |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 257 | userForeground(UserHandle.USER_OWNER); |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 258 | mAppOpsService = IAppOpsService.Stub.asInterface( |
| 259 | ServiceManager.getService(Context.APP_OPS_SERVICE)); |
| 260 | for (int i = 0; i < mUserIds.length; ++i) { |
| 261 | try { |
| 262 | mAppOpsService.setUserRestrictions(mUserRestrictions.get(mUserIds[i]), mUserIds[i]); |
| 263 | } catch (RemoteException e) { |
| 264 | Log.w(LOG_TAG, "Unable to notify AppOpsService of UserRestrictions"); |
| 265 | } |
| 266 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | @Override |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 270 | public List<UserInfo> getUsers(boolean excludeDying) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 271 | checkManageUsersPermission("query users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 272 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 273 | ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); |
| 274 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 275 | UserInfo ui = mUsers.valueAt(i); |
| 276 | if (ui.partial) { |
| 277 | continue; |
| 278 | } |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 279 | if (!excludeDying || !mRemovingUserIds.get(ui.id)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 280 | users.add(ui); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 281 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 282 | } |
| 283 | return users; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 284 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 287 | @Override |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 288 | public List<UserInfo> getProfiles(int userId, boolean enabledOnly) { |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 289 | if (userId != UserHandle.getCallingUserId()) { |
| 290 | checkManageUsersPermission("getting profiles related to user " + userId); |
| 291 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 292 | final long ident = Binder.clearCallingIdentity(); |
| 293 | try { |
| 294 | synchronized (mPackagesLock) { |
| 295 | return getProfilesLocked(userId, enabledOnly); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 296 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 297 | } finally { |
| 298 | Binder.restoreCallingIdentity(ident); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 302 | /** Assume permissions already checked and caller's identity cleared */ |
| 303 | private List<UserInfo> getProfilesLocked(int userId, boolean enabledOnly) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 304 | UserInfo user = getUserInfoLocked(userId); |
| 305 | ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); |
Amith Yamasani | dda003f | 2014-08-28 18:06:51 -0700 | [diff] [blame] | 306 | if (user == null) { |
| 307 | // Probably a dying user |
| 308 | return users; |
| 309 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 310 | for (int i = 0; i < mUsers.size(); i++) { |
| 311 | UserInfo profile = mUsers.valueAt(i); |
| 312 | if (!isProfileOf(user, profile)) { |
| 313 | continue; |
| 314 | } |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 315 | if (enabledOnly && !profile.isEnabled()) { |
| 316 | continue; |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 317 | } |
Amith Yamasani | 70fcf0c | 2014-07-11 08:40:19 -0700 | [diff] [blame] | 318 | if (mRemovingUserIds.get(profile.id)) { |
| 319 | continue; |
| 320 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 321 | users.add(profile); |
| 322 | } |
| 323 | return users; |
| 324 | } |
| 325 | |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 326 | @Override |
| 327 | public UserInfo getProfileParent(int userHandle) { |
| 328 | checkManageUsersPermission("get the profile parent"); |
| 329 | synchronized (mPackagesLock) { |
| 330 | UserInfo profile = getUserInfoLocked(userHandle); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 331 | if (profile == null) { |
| 332 | return null; |
| 333 | } |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 334 | int parentUserId = profile.profileGroupId; |
| 335 | if (parentUserId == UserInfo.NO_PROFILE_GROUP_ID) { |
| 336 | return null; |
| 337 | } else { |
| 338 | return getUserInfoLocked(parentUserId); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 343 | private boolean isProfileOf(UserInfo user, UserInfo profile) { |
| 344 | return user.id == profile.id || |
| 345 | (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID |
| 346 | && user.profileGroupId == profile.profileGroupId); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | @Override |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 350 | public void setUserEnabled(int userId) { |
| 351 | checkManageUsersPermission("enable user"); |
| 352 | synchronized (mPackagesLock) { |
| 353 | UserInfo info = getUserInfoLocked(userId); |
| 354 | if (info != null && !info.isEnabled()) { |
| 355 | info.flags ^= UserInfo.FLAG_DISABLED; |
| 356 | writeUserLocked(info); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | @Override |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 362 | public UserInfo getUserInfo(int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 363 | checkManageUsersPermission("query user"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 364 | synchronized (mPackagesLock) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 365 | return getUserInfoLocked(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 369 | @Override |
| 370 | public boolean isRestricted() { |
| 371 | synchronized (mPackagesLock) { |
| 372 | return getUserInfoLocked(UserHandle.getCallingUserId()).isRestricted(); |
| 373 | } |
| 374 | } |
| 375 | |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 376 | /* |
| 377 | * Should be locked on mUsers before calling this. |
| 378 | */ |
| 379 | private UserInfo getUserInfoLocked(int userId) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 380 | UserInfo ui = mUsers.get(userId); |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 381 | // If it is partial and not in the process of being removed, return as unknown user. |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 382 | if (ui != null && ui.partial && !mRemovingUserIds.get(userId)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 383 | Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId); |
| 384 | return null; |
| 385 | } |
| 386 | return ui; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 389 | public boolean exists(int userId) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 390 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 391 | return ArrayUtils.contains(mUserIds, userId); |
| 392 | } |
| 393 | } |
| 394 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 395 | @Override |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 396 | public void setUserName(int userId, String name) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 397 | checkManageUsersPermission("rename users"); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 398 | boolean changed = false; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 399 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 400 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 401 | if (info == null || info.partial) { |
| 402 | Slog.w(LOG_TAG, "setUserName: unknown user #" + userId); |
| 403 | return; |
| 404 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 405 | if (name != null && !name.equals(info.name)) { |
| 406 | info.name = name; |
| 407 | writeUserLocked(info); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 408 | changed = true; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 411 | if (changed) { |
| 412 | sendUserInfoChangedBroadcast(userId); |
| 413 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 416 | @Override |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 417 | public void setUserIcon(int userId, Bitmap bitmap) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 418 | checkManageUsersPermission("update users"); |
Jason Monk | 9a94453 | 2014-07-08 09:31:21 -0400 | [diff] [blame] | 419 | long ident = Binder.clearCallingIdentity(); |
| 420 | try { |
| 421 | synchronized (mPackagesLock) { |
| 422 | UserInfo info = mUsers.get(userId); |
| 423 | if (info == null || info.partial) { |
| 424 | Slog.w(LOG_TAG, "setUserIcon: unknown user #" + userId); |
| 425 | return; |
| 426 | } |
| 427 | writeBitmapLocked(info, bitmap); |
| 428 | writeUserLocked(info); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 429 | } |
Jason Monk | 9a94453 | 2014-07-08 09:31:21 -0400 | [diff] [blame] | 430 | sendUserInfoChangedBroadcast(userId); |
| 431 | } finally { |
| 432 | Binder.restoreCallingIdentity(ident); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 433 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | private void sendUserInfoChangedBroadcast(int userId) { |
| 437 | Intent changedIntent = new Intent(Intent.ACTION_USER_INFO_CHANGED); |
| 438 | changedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 439 | changedIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
Amith Yamasani | 6fc1d4e | 2013-05-08 16:43:58 -0700 | [diff] [blame] | 440 | mContext.sendBroadcastAsUser(changedIntent, UserHandle.ALL); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 443 | @Override |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 444 | public ParcelFileDescriptor getUserIcon(int userId) { |
| 445 | String iconPath; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 446 | synchronized (mPackagesLock) { |
| 447 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 448 | if (info == null || info.partial) { |
| 449 | Slog.w(LOG_TAG, "getUserIcon: unknown user #" + userId); |
| 450 | return null; |
| 451 | } |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 452 | int callingGroupId = mUsers.get(UserHandle.getCallingUserId()).profileGroupId; |
| 453 | if (callingGroupId == UserInfo.NO_PROFILE_GROUP_ID |
| 454 | || callingGroupId != info.profileGroupId) { |
| 455 | checkManageUsersPermission("get the icon of a user who is not related"); |
| 456 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 457 | if (info.iconPath == null) { |
| 458 | return null; |
| 459 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 460 | iconPath = info.iconPath; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 461 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 462 | |
| 463 | try { |
| 464 | return ParcelFileDescriptor.open( |
| 465 | new File(iconPath), ParcelFileDescriptor.MODE_READ_ONLY); |
| 466 | } catch (FileNotFoundException e) { |
| 467 | Log.e(LOG_TAG, "Couldn't find icon file", e); |
| 468 | } |
| 469 | return null; |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 472 | public void makeInitialized(int userId) { |
| 473 | checkManageUsersPermission("makeInitialized"); |
| 474 | synchronized (mPackagesLock) { |
| 475 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 476 | if (info == null || info.partial) { |
| 477 | Slog.w(LOG_TAG, "makeInitialized: unknown user #" + userId); |
| 478 | } |
| 479 | if ((info.flags&UserInfo.FLAG_INITIALIZED) == 0) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 480 | info.flags |= UserInfo.FLAG_INITIALIZED; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 481 | scheduleWriteUserLocked(info); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 486 | /** |
| 487 | * If default guest restrictions haven't been initialized yet, add the basic |
| 488 | * restrictions. |
| 489 | */ |
| 490 | private void initDefaultGuestRestrictions() { |
| 491 | if (mGuestRestrictions.isEmpty()) { |
| 492 | mGuestRestrictions.putBoolean(UserManager.DISALLOW_OUTGOING_CALLS, true); |
Amith Yamasani | da0b168 | 2014-11-21 12:58:17 -0800 | [diff] [blame] | 493 | mGuestRestrictions.putBoolean(UserManager.DISALLOW_SMS, true); |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 497 | @Override |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 498 | public Bundle getDefaultGuestRestrictions() { |
| 499 | checkManageUsersPermission("getDefaultGuestRestrictions"); |
| 500 | synchronized (mPackagesLock) { |
| 501 | return new Bundle(mGuestRestrictions); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void setDefaultGuestRestrictions(Bundle restrictions) { |
| 507 | checkManageUsersPermission("setDefaultGuestRestrictions"); |
| 508 | synchronized (mPackagesLock) { |
| 509 | mGuestRestrictions.clear(); |
| 510 | mGuestRestrictions.putAll(restrictions); |
| 511 | writeUserListLocked(); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | @Override |
Amith Yamasani | 8cd28b5 | 2014-06-08 17:54:27 -0700 | [diff] [blame] | 516 | public boolean hasUserRestriction(String restrictionKey, int userId) { |
| 517 | synchronized (mPackagesLock) { |
| 518 | Bundle restrictions = mUserRestrictions.get(userId); |
| 519 | return restrictions != null ? restrictions.getBoolean(restrictionKey) : false; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | @Override |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 524 | public Bundle getUserRestrictions(int userId) { |
| 525 | // checkManageUsersPermission("getUserRestrictions"); |
| 526 | |
| 527 | synchronized (mPackagesLock) { |
| 528 | Bundle restrictions = mUserRestrictions.get(userId); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 529 | return restrictions != null ? new Bundle(restrictions) : new Bundle(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public void setUserRestrictions(Bundle restrictions, int userId) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 535 | checkManageUsersPermission("setUserRestrictions"); |
Amith Yamasani | 0343ec3 | 2013-07-22 14:52:06 -0700 | [diff] [blame] | 536 | if (restrictions == null) return; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 537 | |
| 538 | synchronized (mPackagesLock) { |
Amith Yamasani | 350962c | 2013-08-06 11:18:53 -0700 | [diff] [blame] | 539 | mUserRestrictions.get(userId).clear(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 540 | mUserRestrictions.get(userId).putAll(restrictions); |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 541 | long token = Binder.clearCallingIdentity(); |
| 542 | try { |
| 543 | mAppOpsService.setUserRestrictions(mUserRestrictions.get(userId), userId); |
| 544 | } catch (RemoteException e) { |
| 545 | Log.w(LOG_TAG, "Unable to notify AppOpsService of UserRestrictions"); |
| 546 | } finally { |
| 547 | Binder.restoreCallingIdentity(token); |
| 548 | } |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 549 | scheduleWriteUserLocked(mUsers.get(userId)); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 553 | /** |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 554 | * Check if we've hit the limit of how many users can be created. |
| 555 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 556 | private boolean isUserLimitReachedLocked() { |
Amith Yamasani | f584f01 | 2014-05-19 17:57:25 -0700 | [diff] [blame] | 557 | int aliveUserCount = 0; |
| 558 | final int totalUserCount = mUsers.size(); |
| 559 | // Skip over users being removed |
| 560 | for (int i = 0; i < totalUserCount; i++) { |
| 561 | UserInfo user = mUsers.valueAt(i); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 562 | if (!mRemovingUserIds.get(user.id) |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 563 | && !user.isGuest() && !user.partial) { |
Amith Yamasani | f584f01 | 2014-05-19 17:57:25 -0700 | [diff] [blame] | 564 | aliveUserCount++; |
| 565 | } |
| 566 | } |
| 567 | return aliveUserCount >= UserManager.getMaxSupportedUsers(); |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 571 | * Enforces that only the system UID or root's UID or apps that have the |
Dianne Hackborn | 10ad982 | 2014-03-17 11:28:36 -0700 | [diff] [blame] | 572 | * {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS} |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 573 | * permission can make certain calls to the UserManager. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 574 | * |
| 575 | * @param message used as message if SecurityException is thrown |
| 576 | * @throws SecurityException if the caller is not system or root |
| 577 | */ |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 578 | private static final void checkManageUsersPermission(String message) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 579 | final int uid = Binder.getCallingUid(); |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 580 | if (uid != Process.SYSTEM_UID && uid != 0 |
Emily Bernier | 7a2b4d1 | 2014-04-23 12:51:35 -0400 | [diff] [blame] | 581 | && ActivityManager.checkComponentPermission( |
| 582 | android.Manifest.permission.MANAGE_USERS, |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 583 | uid, -1, true) != PackageManager.PERMISSION_GRANTED) { |
| 584 | throw new SecurityException("You need MANAGE_USERS permission to: " + message); |
| 585 | } |
Emily Bernier | 7a2b4d1 | 2014-04-23 12:51:35 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 588 | private void writeBitmapLocked(UserInfo info, Bitmap bitmap) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 589 | try { |
| 590 | File dir = new File(mUsersDir, Integer.toString(info.id)); |
| 591 | File file = new File(dir, USER_PHOTO_FILENAME); |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 592 | File tmp = new File(dir, USER_PHOTO_FILENAME_TMP); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 593 | if (!dir.exists()) { |
| 594 | dir.mkdir(); |
| 595 | FileUtils.setPermissions( |
| 596 | dir.getPath(), |
| 597 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 598 | -1, -1); |
| 599 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 600 | FileOutputStream os; |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 601 | if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(tmp)) |
| 602 | && tmp.renameTo(file)) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 603 | info.iconPath = file.getAbsolutePath(); |
| 604 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 605 | try { |
| 606 | os.close(); |
| 607 | } catch (IOException ioe) { |
| 608 | // What the ... ! |
| 609 | } |
Adrian Roos | 1bdff91 | 2015-02-17 15:51:35 +0100 | [diff] [blame] | 610 | tmp.delete(); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 611 | } catch (FileNotFoundException e) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 612 | Slog.w(LOG_TAG, "Error setting photo for user ", e); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 613 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 616 | /** |
| 617 | * Returns an array of user ids. This array is cached here for quick access, so do not modify or |
| 618 | * cache it elsewhere. |
| 619 | * @return the array of user ids. |
| 620 | */ |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 621 | public int[] getUserIds() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 622 | synchronized (mPackagesLock) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 623 | return mUserIds; |
| 624 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 627 | int[] getUserIdsLPr() { |
| 628 | return mUserIds; |
| 629 | } |
| 630 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 631 | private void readUserListLocked() { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 632 | if (!mUserListFile.exists()) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 633 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 634 | return; |
| 635 | } |
| 636 | FileInputStream fis = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 637 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 638 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 639 | fis = userListFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 640 | XmlPullParser parser = Xml.newPullParser(); |
| 641 | parser.setInput(fis, null); |
| 642 | int type; |
| 643 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 644 | && type != XmlPullParser.END_DOCUMENT) { |
| 645 | ; |
| 646 | } |
| 647 | |
| 648 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 649 | Slog.e(LOG_TAG, "Unable to read user list"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 650 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 651 | return; |
| 652 | } |
| 653 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 654 | mNextSerialNumber = -1; |
| 655 | if (parser.getName().equals(TAG_USERS)) { |
| 656 | String lastSerialNumber = parser.getAttributeValue(null, ATTR_NEXT_SERIAL_NO); |
| 657 | if (lastSerialNumber != null) { |
| 658 | mNextSerialNumber = Integer.parseInt(lastSerialNumber); |
| 659 | } |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 660 | String versionNumber = parser.getAttributeValue(null, ATTR_USER_VERSION); |
| 661 | if (versionNumber != null) { |
| 662 | mUserVersion = Integer.parseInt(versionNumber); |
| 663 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 666 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 667 | if (type == XmlPullParser.START_TAG) { |
| 668 | final String name = parser.getName(); |
| 669 | if (name.equals(TAG_USER)) { |
| 670 | String id = parser.getAttributeValue(null, ATTR_ID); |
| 671 | UserInfo user = readUserLocked(Integer.parseInt(id)); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 672 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 673 | if (user != null) { |
| 674 | mUsers.put(user.id, user); |
| 675 | if (mNextSerialNumber < 0 || mNextSerialNumber <= user.id) { |
| 676 | mNextSerialNumber = user.id + 1; |
| 677 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 678 | } |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 679 | } else if (name.equals(TAG_GUEST_RESTRICTIONS)) { |
Amith Yamasani | da0b168 | 2014-11-21 12:58:17 -0800 | [diff] [blame] | 680 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 681 | && type != XmlPullParser.END_TAG) { |
| 682 | if (type == XmlPullParser.START_TAG) { |
| 683 | if (parser.getName().equals(TAG_RESTRICTIONS)) { |
| 684 | readRestrictionsLocked(parser, mGuestRestrictions); |
| 685 | } |
| 686 | break; |
| 687 | } |
| 688 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 689 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 692 | updateUserIdsLocked(); |
Amith Yamasani | 350962c | 2013-08-06 11:18:53 -0700 | [diff] [blame] | 693 | upgradeIfNecessaryLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 694 | } catch (IOException ioe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 695 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 696 | } catch (XmlPullParserException pe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 697 | fallbackToSingleUserLocked(); |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 698 | } finally { |
| 699 | if (fis != null) { |
| 700 | try { |
| 701 | fis.close(); |
| 702 | } catch (IOException e) { |
| 703 | } |
| 704 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 708 | /** |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 709 | * Upgrade steps between versions, either for fixing bugs or changing the data format. |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 710 | */ |
Amith Yamasani | 350962c | 2013-08-06 11:18:53 -0700 | [diff] [blame] | 711 | private void upgradeIfNecessaryLocked() { |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 712 | int userVersion = mUserVersion; |
| 713 | if (userVersion < 1) { |
| 714 | // Assign a proper name for the owner, if not initialized correctly before |
| 715 | UserInfo user = mUsers.get(UserHandle.USER_OWNER); |
| 716 | if ("Primary".equals(user.name)) { |
| 717 | user.name = mContext.getResources().getString(com.android.internal.R.string.owner_name); |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 718 | scheduleWriteUserLocked(user); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 719 | } |
| 720 | userVersion = 1; |
| 721 | } |
| 722 | |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 723 | if (userVersion < 2) { |
| 724 | // Owner should be marked as initialized |
| 725 | UserInfo user = mUsers.get(UserHandle.USER_OWNER); |
| 726 | if ((user.flags & UserInfo.FLAG_INITIALIZED) == 0) { |
| 727 | user.flags |= UserInfo.FLAG_INITIALIZED; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 728 | scheduleWriteUserLocked(user); |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 729 | } |
| 730 | userVersion = 2; |
| 731 | } |
| 732 | |
Amith Yamasani | 350962c | 2013-08-06 11:18:53 -0700 | [diff] [blame] | 733 | |
Amith Yamasani | 5e486f5 | 2013-08-07 11:06:44 -0700 | [diff] [blame] | 734 | if (userVersion < 4) { |
Amith Yamasani | 5e486f5 | 2013-08-07 11:06:44 -0700 | [diff] [blame] | 735 | userVersion = 4; |
| 736 | } |
| 737 | |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 738 | if (userVersion < 5) { |
| 739 | initDefaultGuestRestrictions(); |
| 740 | userVersion = 5; |
| 741 | } |
| 742 | |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 743 | if (userVersion < USER_VERSION) { |
| 744 | Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to " |
| 745 | + USER_VERSION); |
| 746 | } else { |
| 747 | mUserVersion = userVersion; |
| 748 | writeUserListLocked(); |
| 749 | } |
| 750 | } |
| 751 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 752 | private void fallbackToSingleUserLocked() { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 753 | // Create the primary user |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 754 | UserInfo primary = new UserInfo(UserHandle.USER_OWNER, |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 755 | mContext.getResources().getString(com.android.internal.R.string.owner_name), null, |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 756 | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY | UserInfo.FLAG_INITIALIZED); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 757 | mUsers.put(0, primary); |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 758 | mNextSerialNumber = MIN_USER_ID; |
Geoffrey Borggaard | 15b8b2c | 2013-08-28 22:11:10 -0400 | [diff] [blame] | 759 | mUserVersion = USER_VERSION; |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 760 | |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 761 | Bundle restrictions = new Bundle(); |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 762 | mUserRestrictions.append(UserHandle.USER_OWNER, restrictions); |
| 763 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 764 | updateUserIdsLocked(); |
Amith Yamasani | aa6634e | 2014-10-06 14:20:28 -0700 | [diff] [blame] | 765 | initDefaultGuestRestrictions(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 766 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 767 | writeUserListLocked(); |
| 768 | writeUserLocked(primary); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 771 | private void scheduleWriteUserLocked(UserInfo userInfo) { |
| 772 | if (!mHandler.hasMessages(WRITE_USER_MSG, userInfo)) { |
| 773 | Message msg = mHandler.obtainMessage(WRITE_USER_MSG, userInfo); |
| 774 | mHandler.sendMessageDelayed(msg, WRITE_USER_DELAY); |
| 775 | } |
| 776 | } |
| 777 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 778 | /* |
| 779 | * Writes the user file in this format: |
| 780 | * |
| 781 | * <user flags="20039023" id="0"> |
| 782 | * <name>Primary</name> |
| 783 | * </user> |
| 784 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 785 | private void writeUserLocked(UserInfo userInfo) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 786 | FileOutputStream fos = null; |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 787 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + XML_SUFFIX)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 788 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 789 | fos = userFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 790 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 791 | |
| 792 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 793 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 794 | serializer.setOutput(bos, "utf-8"); |
| 795 | serializer.startDocument(null, true); |
| 796 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 797 | |
| 798 | serializer.startTag(null, TAG_USER); |
| 799 | serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id)); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 800 | serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 801 | serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags)); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 802 | serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime)); |
| 803 | serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME, |
| 804 | Long.toString(userInfo.lastLoggedInTime)); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 805 | RestrictionsPinState pinState = mRestrictionsPinStates.get(userInfo.id); |
| 806 | if (pinState != null) { |
| 807 | if (pinState.salt != 0) { |
| 808 | serializer.attribute(null, ATTR_SALT, Long.toString(pinState.salt)); |
| 809 | } |
| 810 | if (pinState.pinHash != null) { |
| 811 | serializer.attribute(null, ATTR_PIN_HASH, pinState.pinHash); |
| 812 | } |
| 813 | if (pinState.failedAttempts != 0) { |
| 814 | serializer.attribute(null, ATTR_FAILED_ATTEMPTS, |
| 815 | Integer.toString(pinState.failedAttempts)); |
| 816 | serializer.attribute(null, ATTR_LAST_RETRY_MS, |
| 817 | Long.toString(pinState.lastAttemptTime)); |
| 818 | } |
| 819 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 820 | if (userInfo.iconPath != null) { |
| 821 | serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); |
| 822 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 823 | if (userInfo.partial) { |
| 824 | serializer.attribute(null, ATTR_PARTIAL, "true"); |
| 825 | } |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 826 | if (userInfo.guestToRemove) { |
| 827 | serializer.attribute(null, ATTR_GUEST_TO_REMOVE, "true"); |
| 828 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 829 | if (userInfo.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) { |
| 830 | serializer.attribute(null, ATTR_PROFILE_GROUP_ID, |
| 831 | Integer.toString(userInfo.profileGroupId)); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 832 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 833 | |
| 834 | serializer.startTag(null, TAG_NAME); |
| 835 | serializer.text(userInfo.name); |
| 836 | serializer.endTag(null, TAG_NAME); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 837 | Bundle restrictions = mUserRestrictions.get(userInfo.id); |
| 838 | if (restrictions != null) { |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 839 | writeRestrictionsLocked(serializer, restrictions); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 840 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 841 | serializer.endTag(null, TAG_USER); |
| 842 | |
| 843 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 844 | userFile.finishWrite(fos); |
| 845 | } catch (Exception ioe) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 846 | Slog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 847 | userFile.failWrite(fos); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * Writes the user list file in this format: |
| 853 | * |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 854 | * <users nextSerialNumber="3"> |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 855 | * <user id="0"></user> |
| 856 | * <user id="2"></user> |
| 857 | * </users> |
| 858 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 859 | private void writeUserListLocked() { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 860 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 861 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 862 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 863 | fos = userListFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 864 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 865 | |
| 866 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 867 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 868 | serializer.setOutput(bos, "utf-8"); |
| 869 | serializer.startDocument(null, true); |
| 870 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 871 | |
| 872 | serializer.startTag(null, TAG_USERS); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 873 | serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 874 | serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 875 | |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 876 | serializer.startTag(null, TAG_GUEST_RESTRICTIONS); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 877 | writeRestrictionsLocked(serializer, mGuestRestrictions); |
| 878 | serializer.endTag(null, TAG_GUEST_RESTRICTIONS); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 879 | for (int i = 0; i < mUsers.size(); i++) { |
| 880 | UserInfo user = mUsers.valueAt(i); |
| 881 | serializer.startTag(null, TAG_USER); |
| 882 | serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); |
| 883 | serializer.endTag(null, TAG_USER); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | serializer.endTag(null, TAG_USERS); |
| 887 | |
| 888 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 889 | userListFile.finishWrite(fos); |
| 890 | } catch (Exception e) { |
| 891 | userListFile.failWrite(fos); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 892 | Slog.e(LOG_TAG, "Error writing user list"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 896 | private void writeRestrictionsLocked(XmlSerializer serializer, Bundle restrictions) |
| 897 | throws IOException { |
| 898 | serializer.startTag(null, TAG_RESTRICTIONS); |
| 899 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_WIFI); |
| 900 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_MODIFY_ACCOUNTS); |
| 901 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_INSTALL_APPS); |
| 902 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_UNINSTALL_APPS); |
| 903 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_SHARE_LOCATION); |
| 904 | writeBoolean(serializer, restrictions, |
| 905 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); |
| 906 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_BLUETOOTH); |
| 907 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_USB_FILE_TRANSFER); |
| 908 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_CREDENTIALS); |
| 909 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_REMOVE_USER); |
| 910 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_DEBUGGING_FEATURES); |
| 911 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_VPN); |
| 912 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_TETHERING); |
| 913 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_FACTORY_RESET); |
| 914 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_ADD_USER); |
| 915 | writeBoolean(serializer, restrictions, UserManager.ENSURE_VERIFY_APPS); |
| 916 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS); |
| 917 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); |
| 918 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_APPS_CONTROL); |
| 919 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA); |
| 920 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_UNMUTE_MICROPHONE); |
| 921 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_ADJUST_VOLUME); |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 922 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_OUTGOING_CALLS); |
| 923 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_SMS); |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 924 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CREATE_WINDOWS); |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 925 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE); |
| 926 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_OUTGOING_BEAM); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 927 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_WALLPAPER); |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 928 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_SAFE_BOOT); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 929 | serializer.endTag(null, TAG_RESTRICTIONS); |
| 930 | } |
| 931 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 932 | private UserInfo readUserLocked(int id) { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 933 | int flags = 0; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 934 | int serialNumber = id; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 935 | String name = null; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 936 | String iconPath = null; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 937 | long creationTime = 0L; |
| 938 | long lastLoggedInTime = 0L; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 939 | long salt = 0L; |
| 940 | String pinHash = null; |
| 941 | int failedAttempts = 0; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 942 | int profileGroupId = UserInfo.NO_PROFILE_GROUP_ID; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 943 | long lastAttemptTime = 0L; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 944 | boolean partial = false; |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 945 | boolean guestToRemove = false; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 946 | Bundle restrictions = new Bundle(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 947 | |
| 948 | FileInputStream fis = null; |
| 949 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 950 | AtomicFile userFile = |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 951 | new AtomicFile(new File(mUsersDir, Integer.toString(id) + XML_SUFFIX)); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 952 | fis = userFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 953 | XmlPullParser parser = Xml.newPullParser(); |
| 954 | parser.setInput(fis, null); |
| 955 | int type; |
| 956 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 957 | && type != XmlPullParser.END_DOCUMENT) { |
| 958 | ; |
| 959 | } |
| 960 | |
| 961 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 962 | Slog.e(LOG_TAG, "Unable to read user " + id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 963 | return null; |
| 964 | } |
| 965 | |
| 966 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 967 | int storedId = readIntAttribute(parser, ATTR_ID, -1); |
| 968 | if (storedId != id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 969 | Slog.e(LOG_TAG, "User id does not match the file name"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 970 | return null; |
| 971 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 972 | serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id); |
| 973 | flags = readIntAttribute(parser, ATTR_FLAGS, 0); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 974 | iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 975 | creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0); |
| 976 | lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 977 | salt = readLongAttribute(parser, ATTR_SALT, 0L); |
| 978 | pinHash = parser.getAttributeValue(null, ATTR_PIN_HASH); |
| 979 | failedAttempts = readIntAttribute(parser, ATTR_FAILED_ATTEMPTS, 0); |
| 980 | lastAttemptTime = readLongAttribute(parser, ATTR_LAST_RETRY_MS, 0L); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 981 | profileGroupId = readIntAttribute(parser, ATTR_PROFILE_GROUP_ID, |
| 982 | UserInfo.NO_PROFILE_GROUP_ID); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 983 | String valueString = parser.getAttributeValue(null, ATTR_PARTIAL); |
| 984 | if ("true".equals(valueString)) { |
| 985 | partial = true; |
| 986 | } |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 987 | valueString = parser.getAttributeValue(null, ATTR_GUEST_TO_REMOVE); |
| 988 | if ("true".equals(valueString)) { |
| 989 | guestToRemove = true; |
| 990 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 991 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 992 | int outerDepth = parser.getDepth(); |
| 993 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 994 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 995 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 996 | continue; |
| 997 | } |
| 998 | String tag = parser.getName(); |
| 999 | if (TAG_NAME.equals(tag)) { |
| 1000 | type = parser.next(); |
| 1001 | if (type == XmlPullParser.TEXT) { |
| 1002 | name = parser.getText(); |
| 1003 | } |
| 1004 | } else if (TAG_RESTRICTIONS.equals(tag)) { |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 1005 | readRestrictionsLocked(parser, restrictions); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1009 | |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 1010 | UserInfo userInfo = new UserInfo(id, name, iconPath, flags); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1011 | userInfo.serialNumber = serialNumber; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1012 | userInfo.creationTime = creationTime; |
| 1013 | userInfo.lastLoggedInTime = lastLoggedInTime; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1014 | userInfo.partial = partial; |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 1015 | userInfo.guestToRemove = guestToRemove; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1016 | userInfo.profileGroupId = profileGroupId; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1017 | mUserRestrictions.append(id, restrictions); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1018 | if (salt != 0L) { |
| 1019 | RestrictionsPinState pinState = mRestrictionsPinStates.get(id); |
| 1020 | if (pinState == null) { |
| 1021 | pinState = new RestrictionsPinState(); |
| 1022 | mRestrictionsPinStates.put(id, pinState); |
| 1023 | } |
| 1024 | pinState.salt = salt; |
| 1025 | pinState.pinHash = pinHash; |
| 1026 | pinState.failedAttempts = failedAttempts; |
| 1027 | pinState.lastAttemptTime = lastAttemptTime; |
| 1028 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1029 | return userInfo; |
| 1030 | |
| 1031 | } catch (IOException ioe) { |
| 1032 | } catch (XmlPullParserException pe) { |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 1033 | } finally { |
| 1034 | if (fis != null) { |
| 1035 | try { |
| 1036 | fis.close(); |
| 1037 | } catch (IOException e) { |
| 1038 | } |
| 1039 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1040 | } |
| 1041 | return null; |
| 1042 | } |
| 1043 | |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 1044 | private void readRestrictionsLocked(XmlPullParser parser, Bundle restrictions) |
| 1045 | throws IOException { |
| 1046 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_WIFI); |
| 1047 | readBoolean(parser, restrictions, UserManager.DISALLOW_MODIFY_ACCOUNTS); |
| 1048 | readBoolean(parser, restrictions, UserManager.DISALLOW_INSTALL_APPS); |
| 1049 | readBoolean(parser, restrictions, UserManager.DISALLOW_UNINSTALL_APPS); |
| 1050 | readBoolean(parser, restrictions, UserManager.DISALLOW_SHARE_LOCATION); |
| 1051 | readBoolean(parser, restrictions, |
| 1052 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); |
| 1053 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_BLUETOOTH); |
| 1054 | readBoolean(parser, restrictions, UserManager.DISALLOW_USB_FILE_TRANSFER); |
| 1055 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_CREDENTIALS); |
| 1056 | readBoolean(parser, restrictions, UserManager.DISALLOW_REMOVE_USER); |
| 1057 | readBoolean(parser, restrictions, UserManager.DISALLOW_DEBUGGING_FEATURES); |
| 1058 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_VPN); |
| 1059 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_TETHERING); |
| 1060 | readBoolean(parser, restrictions, UserManager.DISALLOW_FACTORY_RESET); |
| 1061 | readBoolean(parser, restrictions, UserManager.DISALLOW_ADD_USER); |
| 1062 | readBoolean(parser, restrictions, UserManager.ENSURE_VERIFY_APPS); |
| 1063 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS); |
| 1064 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); |
| 1065 | readBoolean(parser, restrictions, UserManager.DISALLOW_APPS_CONTROL); |
| 1066 | readBoolean(parser, restrictions, |
| 1067 | UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA); |
| 1068 | readBoolean(parser, restrictions, UserManager.DISALLOW_UNMUTE_MICROPHONE); |
| 1069 | readBoolean(parser, restrictions, UserManager.DISALLOW_ADJUST_VOLUME); |
Amith Yamasani | 390989d | 2014-07-17 10:52:03 -0700 | [diff] [blame] | 1070 | readBoolean(parser, restrictions, UserManager.DISALLOW_OUTGOING_CALLS); |
| 1071 | readBoolean(parser, restrictions, UserManager.DISALLOW_SMS); |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1072 | readBoolean(parser, restrictions, UserManager.DISALLOW_CREATE_WINDOWS); |
Amith Yamasani | 26af829 | 2014-09-09 09:57:27 -0700 | [diff] [blame] | 1073 | readBoolean(parser, restrictions, UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE); |
| 1074 | readBoolean(parser, restrictions, UserManager.DISALLOW_OUTGOING_BEAM); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1075 | readBoolean(parser, restrictions, UserManager.DISALLOW_WALLPAPER); |
Benjamin Franz | bff46ba | 2015-03-05 18:33:51 +0000 | [diff] [blame] | 1076 | readBoolean(parser, restrictions, UserManager.DISALLOW_SAFE_BOOT); |
Amith Yamasani | e4afaa3 | 2014-06-30 14:55:07 +0530 | [diff] [blame] | 1077 | } |
| 1078 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1079 | private void readBoolean(XmlPullParser parser, Bundle restrictions, |
| 1080 | String restrictionKey) { |
| 1081 | String value = parser.getAttributeValue(null, restrictionKey); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1082 | if (value != null) { |
| 1083 | restrictions.putBoolean(restrictionKey, Boolean.parseBoolean(value)); |
| 1084 | } |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | private void writeBoolean(XmlSerializer xml, Bundle restrictions, String restrictionKey) |
| 1088 | throws IOException { |
| 1089 | if (restrictions.containsKey(restrictionKey)) { |
| 1090 | xml.attribute(null, restrictionKey, |
| 1091 | Boolean.toString(restrictions.getBoolean(restrictionKey))); |
| 1092 | } |
| 1093 | } |
| 1094 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1095 | private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) { |
| 1096 | String valueString = parser.getAttributeValue(null, attr); |
| 1097 | if (valueString == null) return defaultValue; |
| 1098 | try { |
| 1099 | return Integer.parseInt(valueString); |
| 1100 | } catch (NumberFormatException nfe) { |
| 1101 | return defaultValue; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | private long readLongAttribute(XmlPullParser parser, String attr, long defaultValue) { |
| 1106 | String valueString = parser.getAttributeValue(null, attr); |
| 1107 | if (valueString == null) return defaultValue; |
| 1108 | try { |
| 1109 | return Long.parseLong(valueString); |
| 1110 | } catch (NumberFormatException nfe) { |
| 1111 | return defaultValue; |
| 1112 | } |
| 1113 | } |
| 1114 | |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1115 | private boolean isPackageInstalled(String pkg, int userId) { |
| 1116 | final ApplicationInfo info = mPm.getApplicationInfo(pkg, |
| 1117 | PackageManager.GET_UNINSTALLED_PACKAGES, |
| 1118 | userId); |
| 1119 | if (info == null || (info.flags&ApplicationInfo.FLAG_INSTALLED) == 0) { |
| 1120 | return false; |
| 1121 | } |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Amith Yamasani | b82add2 | 2013-07-09 11:24:44 -0700 | [diff] [blame] | 1125 | /** |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1126 | * Removes all the restrictions files (res_<packagename>) for a given user. |
Amith Yamasani | b82add2 | 2013-07-09 11:24:44 -0700 | [diff] [blame] | 1127 | * Does not do any permissions checking. |
| 1128 | */ |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1129 | private void cleanAppRestrictions(int userId) { |
Amith Yamasani | b82add2 | 2013-07-09 11:24:44 -0700 | [diff] [blame] | 1130 | synchronized (mPackagesLock) { |
| 1131 | File dir = Environment.getUserSystemDirectory(userId); |
| 1132 | String[] files = dir.list(); |
| 1133 | if (files == null) return; |
| 1134 | for (String fileName : files) { |
| 1135 | if (fileName.startsWith(RESTRICTIONS_FILE_PREFIX)) { |
| 1136 | File resFile = new File(dir, fileName); |
| 1137 | if (resFile.exists()) { |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1138 | resFile.delete(); |
Amith Yamasani | b82add2 | 2013-07-09 11:24:44 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1145 | /** |
| 1146 | * Removes the app restrictions file for a specific package and user id, if it exists. |
| 1147 | */ |
| 1148 | private void cleanAppRestrictionsForPackage(String pkg, int userId) { |
| 1149 | synchronized (mPackagesLock) { |
| 1150 | File dir = Environment.getUserSystemDirectory(userId); |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 1151 | File resFile = new File(dir, packageToRestrictionsFileName(pkg)); |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1152 | if (resFile.exists()) { |
| 1153 | resFile.delete(); |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1158 | @Override |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1159 | public UserInfo createProfileForUser(String name, int flags, int userId) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1160 | checkManageUsersPermission("Only the system can create users"); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1161 | if (userId != UserHandle.USER_OWNER) { |
| 1162 | Slog.w(LOG_TAG, "Only user owner can have profiles"); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1163 | return null; |
| 1164 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1165 | return createUserInternal(name, flags, userId); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1168 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1169 | public UserInfo createUser(String name, int flags) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1170 | checkManageUsersPermission("Only the system can create users"); |
Nicolas Prevot | c6d033e | 2014-02-27 13:11:09 +0000 | [diff] [blame] | 1171 | return createUserInternal(name, flags, UserHandle.USER_NULL); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1172 | } |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 1173 | |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1174 | private UserInfo createUserInternal(String name, int flags, int parentId) { |
Julia Reynolds | 7517502 | 2014-06-26 16:35:00 -0400 | [diff] [blame] | 1175 | if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean( |
| 1176 | UserManager.DISALLOW_ADD_USER, false)) { |
| 1177 | Log.w(LOG_TAG, "Cannot add user. DISALLOW_ADD_USER is enabled."); |
| 1178 | return null; |
| 1179 | } |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1180 | final boolean isGuest = (flags & UserInfo.FLAG_GUEST) != 0; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1181 | final long ident = Binder.clearCallingIdentity(); |
Nicolas Prevot | c6d033e | 2014-02-27 13:11:09 +0000 | [diff] [blame] | 1182 | UserInfo userInfo = null; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1183 | try { |
| 1184 | synchronized (mInstallLock) { |
| 1185 | synchronized (mPackagesLock) { |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1186 | UserInfo parent = null; |
| 1187 | if (parentId != UserHandle.USER_NULL) { |
| 1188 | parent = getUserInfoLocked(parentId); |
| 1189 | if (parent == null) return null; |
Nicolas Prevot | c6d033e | 2014-02-27 13:11:09 +0000 | [diff] [blame] | 1190 | } |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1191 | // If we're not adding a guest user and the limit has been reached, |
| 1192 | // cannot add a user. |
| 1193 | if (!isGuest && isUserLimitReachedLocked()) { |
| 1194 | return null; |
| 1195 | } |
| 1196 | // If we're adding a guest and there already exists one, bail. |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 1197 | if (isGuest && findCurrentGuestUserLocked() != null) { |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1198 | return null; |
| 1199 | } |
| 1200 | // Limit number of managed profiles that can be created |
| 1201 | if ((flags & UserInfo.FLAG_MANAGED_PROFILE) != 0 |
| 1202 | && numberOfUsersOfTypeLocked(UserInfo.FLAG_MANAGED_PROFILE, true) |
| 1203 | >= MAX_MANAGED_PROFILES) { |
| 1204 | return null; |
| 1205 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1206 | int userId = getNextAvailableIdLocked(); |
| 1207 | userInfo = new UserInfo(userId, name, null, flags); |
| 1208 | File userPath = new File(mBaseUserPath, Integer.toString(userId)); |
| 1209 | userInfo.serialNumber = mNextSerialNumber++; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1210 | long now = System.currentTimeMillis(); |
| 1211 | userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1212 | userInfo.partial = true; |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1213 | Environment.getUserSystemDirectory(userInfo.id).mkdirs(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1214 | mUsers.put(userId, userInfo); |
| 1215 | writeUserListLocked(); |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1216 | if (parent != null) { |
| 1217 | if (parent.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { |
| 1218 | parent.profileGroupId = parent.id; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1219 | scheduleWriteUserLocked(parent); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1220 | } |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 1221 | userInfo.profileGroupId = parent.profileGroupId; |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 1222 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1223 | mPm.createNewUserLILPw(userId, userPath); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1224 | userInfo.partial = false; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1225 | scheduleWriteUserLocked(userInfo); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1226 | updateUserIdsLocked(); |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 1227 | Bundle restrictions = new Bundle(); |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 1228 | mUserRestrictions.append(userId, restrictions); |
Svet Ganov | 78027f3 | 2015-03-25 09:10:09 -0700 | [diff] [blame] | 1229 | mPm.newUserCreatedLILPw(userId); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1230 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1231 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1232 | if (userInfo != null) { |
| 1233 | Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED); |
| 1234 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id); |
| 1235 | mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 1236 | android.Manifest.permission.MANAGE_USERS); |
| 1237 | } |
| 1238 | } finally { |
| 1239 | Binder.restoreCallingIdentity(ident); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1240 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1241 | return userInfo; |
| 1242 | } |
| 1243 | |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 1244 | private int numberOfUsersOfTypeLocked(int flags, boolean excludeDying) { |
| 1245 | int count = 0; |
| 1246 | for (int i = mUsers.size() - 1; i >= 0; i--) { |
| 1247 | UserInfo user = mUsers.valueAt(i); |
| 1248 | if (!excludeDying || !mRemovingUserIds.get(user.id)) { |
| 1249 | if ((user.flags & flags) != 0) { |
| 1250 | count++; |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | return count; |
| 1255 | } |
| 1256 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1257 | /** |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 1258 | * Find the current guest user. If the Guest user is partial, |
| 1259 | * then do not include it in the results as it is about to die. |
| 1260 | * This is different than {@link #numberOfUsersOfTypeLocked(int, boolean)} due to |
| 1261 | * the special handling of Guests being removed. |
| 1262 | */ |
| 1263 | private UserInfo findCurrentGuestUserLocked() { |
| 1264 | final int size = mUsers.size(); |
| 1265 | for (int i = 0; i < size; i++) { |
| 1266 | final UserInfo user = mUsers.valueAt(i); |
| 1267 | if (user.isGuest() && !user.guestToRemove && !mRemovingUserIds.get(user.id)) { |
| 1268 | return user; |
| 1269 | } |
| 1270 | } |
| 1271 | return null; |
| 1272 | } |
| 1273 | |
| 1274 | /** |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1275 | * Mark this guest user for deletion to allow us to create another guest |
| 1276 | * and switch to that user before actually removing this guest. |
| 1277 | * @param userHandle the userid of the current guest |
| 1278 | * @return whether the user could be marked for deletion |
| 1279 | */ |
| 1280 | public boolean markGuestForDeletion(int userHandle) { |
| 1281 | checkManageUsersPermission("Only the system can remove users"); |
| 1282 | if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean( |
| 1283 | UserManager.DISALLOW_REMOVE_USER, false)) { |
| 1284 | Log.w(LOG_TAG, "Cannot remove user. DISALLOW_REMOVE_USER is enabled."); |
| 1285 | return false; |
| 1286 | } |
| 1287 | |
| 1288 | long ident = Binder.clearCallingIdentity(); |
| 1289 | try { |
| 1290 | final UserInfo user; |
| 1291 | synchronized (mPackagesLock) { |
| 1292 | user = mUsers.get(userHandle); |
| 1293 | if (userHandle == 0 || user == null || mRemovingUserIds.get(userHandle)) { |
| 1294 | return false; |
| 1295 | } |
| 1296 | if (!user.isGuest()) { |
| 1297 | return false; |
| 1298 | } |
Adam Lesinski | eddeb49 | 2014-09-08 17:50:03 -0700 | [diff] [blame] | 1299 | // We set this to a guest user that is to be removed. This is a temporary state |
| 1300 | // where we are allowed to add new Guest users, even if this one is still not |
| 1301 | // removed. This user will still show up in getUserInfo() calls. |
| 1302 | // If we don't get around to removing this Guest user, it will be purged on next |
| 1303 | // startup. |
| 1304 | user.guestToRemove = true; |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1305 | // Mark it as disabled, so that it isn't returned any more when |
| 1306 | // profiles are queried. |
| 1307 | user.flags |= UserInfo.FLAG_DISABLED; |
Amith Yamasani | 1df1473 | 2014-08-29 21:37:27 -0700 | [diff] [blame] | 1308 | writeUserLocked(user); |
| 1309 | } |
| 1310 | } finally { |
| 1311 | Binder.restoreCallingIdentity(ident); |
| 1312 | } |
| 1313 | return true; |
| 1314 | } |
| 1315 | |
| 1316 | /** |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1317 | * Removes a user and all data directories created for that user. This method should be called |
| 1318 | * after the user's processes have been terminated. |
Dianne Hackborn | 10ad982 | 2014-03-17 11:28:36 -0700 | [diff] [blame] | 1319 | * @param userHandle the user's id |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1320 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1321 | public boolean removeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1322 | checkManageUsersPermission("Only the system can remove users"); |
Julia Reynolds | 4ac5f85 | 2014-06-23 17:38:51 -0400 | [diff] [blame] | 1323 | if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean( |
| 1324 | UserManager.DISALLOW_REMOVE_USER, false)) { |
| 1325 | Log.w(LOG_TAG, "Cannot remove user. DISALLOW_REMOVE_USER is enabled."); |
| 1326 | return false; |
| 1327 | } |
| 1328 | |
Kenny Guy | ee58b4f | 2014-05-23 15:19:53 +0100 | [diff] [blame] | 1329 | long ident = Binder.clearCallingIdentity(); |
| 1330 | try { |
| 1331 | final UserInfo user; |
| 1332 | synchronized (mPackagesLock) { |
| 1333 | user = mUsers.get(userHandle); |
Kenny Guy | 17c9d69 | 2014-06-13 13:51:42 +0100 | [diff] [blame] | 1334 | if (userHandle == 0 || user == null || mRemovingUserIds.get(userHandle)) { |
Kenny Guy | ee58b4f | 2014-05-23 15:19:53 +0100 | [diff] [blame] | 1335 | return false; |
| 1336 | } |
Jeff Sharkey | 6eb0939 | 2014-11-14 15:57:59 -0800 | [diff] [blame] | 1337 | |
| 1338 | // We remember deleted user IDs to prevent them from being |
| 1339 | // reused during the current boot; they can still be reused |
| 1340 | // after a reboot. |
Kenny Guy | ee58b4f | 2014-05-23 15:19:53 +0100 | [diff] [blame] | 1341 | mRemovingUserIds.put(userHandle, true); |
Jeff Sharkey | 6eb0939 | 2014-11-14 15:57:59 -0800 | [diff] [blame] | 1342 | |
Kenny Guy | ee58b4f | 2014-05-23 15:19:53 +0100 | [diff] [blame] | 1343 | try { |
| 1344 | mAppOpsService.removeUser(userHandle); |
| 1345 | } catch (RemoteException e) { |
| 1346 | Log.w(LOG_TAG, "Unable to notify AppOpsService of removing user", e); |
| 1347 | } |
| 1348 | // Set this to a partially created user, so that the user will be purged |
| 1349 | // on next startup, in case the runtime stops now before stopping and |
| 1350 | // removing the user completely. |
| 1351 | user.partial = true; |
| 1352 | // Mark it as disabled, so that it isn't returned any more when |
| 1353 | // profiles are queried. |
| 1354 | user.flags |= UserInfo.FLAG_DISABLED; |
| 1355 | writeUserLocked(user); |
| 1356 | } |
| 1357 | |
| 1358 | if (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID |
| 1359 | && user.isManagedProfile()) { |
| 1360 | // Send broadcast to notify system that the user removed was a |
| 1361 | // managed user. |
| 1362 | sendProfileRemovedBroadcast(user.profileGroupId, user.id); |
| 1363 | } |
| 1364 | |
| 1365 | if (DBG) Slog.i(LOG_TAG, "Stopping user " + userHandle); |
| 1366 | int res; |
| 1367 | try { |
| 1368 | res = ActivityManagerNative.getDefault().stopUser(userHandle, |
| 1369 | new IStopUserCallback.Stub() { |
| 1370 | @Override |
| 1371 | public void userStopped(int userId) { |
| 1372 | finishRemoveUser(userId); |
| 1373 | } |
| 1374 | @Override |
| 1375 | public void userStopAborted(int userId) { |
| 1376 | } |
| 1377 | }); |
| 1378 | } catch (RemoteException e) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
Kenny Guy | ee58b4f | 2014-05-23 15:19:53 +0100 | [diff] [blame] | 1381 | return res == ActivityManager.USER_OP_SUCCESS; |
| 1382 | } finally { |
| 1383 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1384 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 1387 | void finishRemoveUser(final int userHandle) { |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1388 | if (DBG) Slog.i(LOG_TAG, "finishRemoveUser " + userHandle); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 1389 | // Let other services shutdown any activity and clean up their state before completely |
| 1390 | // wiping the user's system directory and removing from the user list |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1391 | long ident = Binder.clearCallingIdentity(); |
| 1392 | try { |
| 1393 | Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED); |
| 1394 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 1395 | mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 1396 | android.Manifest.permission.MANAGE_USERS, |
| 1397 | |
| 1398 | new BroadcastReceiver() { |
| 1399 | @Override |
| 1400 | public void onReceive(Context context, Intent intent) { |
| 1401 | if (DBG) { |
| 1402 | Slog.i(LOG_TAG, |
| 1403 | "USER_REMOVED broadcast sent, cleaning up user data " |
| 1404 | + userHandle); |
| 1405 | } |
| 1406 | new Thread() { |
| 1407 | public void run() { |
| 1408 | synchronized (mInstallLock) { |
| 1409 | synchronized (mPackagesLock) { |
| 1410 | removeUserStateLocked(userHandle); |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | }.start(); |
| 1415 | } |
| 1416 | }, |
| 1417 | |
| 1418 | null, Activity.RESULT_OK, null, null); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1419 | } finally { |
| 1420 | Binder.restoreCallingIdentity(ident); |
| 1421 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1424 | private void removeUserStateLocked(final int userHandle) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1425 | // Cleanup package manager settings |
Amith Yamasani | dda003f | 2014-08-28 18:06:51 -0700 | [diff] [blame] | 1426 | mPm.cleanUpUserLILPw(this, userHandle); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1427 | |
| 1428 | // Remove this user from the list |
| 1429 | mUsers.remove(userHandle); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1430 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1431 | mRestrictionsPinStates.remove(userHandle); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1432 | // Remove user file |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 1433 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + XML_SUFFIX)); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1434 | userFile.delete(); |
| 1435 | // Update the user list |
| 1436 | writeUserListLocked(); |
| 1437 | updateUserIdsLocked(); |
| 1438 | removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle)); |
| 1439 | } |
| 1440 | |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1441 | private void removeDirectoryRecursive(File parent) { |
| 1442 | if (parent.isDirectory()) { |
| 1443 | String[] files = parent.list(); |
| 1444 | for (String filename : files) { |
| 1445 | File child = new File(parent, filename); |
| 1446 | removeDirectoryRecursive(child); |
| 1447 | } |
| 1448 | } |
| 1449 | parent.delete(); |
| 1450 | } |
| 1451 | |
Kenny Guy | f8d3a23 | 2014-05-15 16:09:52 +0100 | [diff] [blame] | 1452 | private void sendProfileRemovedBroadcast(int parentUserId, int removedUserId) { |
Adam Connors | 7b66ed5 | 2014-04-14 11:58:10 +0100 | [diff] [blame] | 1453 | Intent managedProfileIntent = new Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED); |
Adam Connors | d4b584e | 2014-06-09 13:55:47 +0100 | [diff] [blame] | 1454 | managedProfileIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | |
| 1455 | Intent.FLAG_RECEIVER_FOREGROUND); |
Kenny Guy | f8d3a23 | 2014-05-15 16:09:52 +0100 | [diff] [blame] | 1456 | managedProfileIntent.putExtra(Intent.EXTRA_USER, new UserHandle(removedUserId)); |
| 1457 | mContext.sendBroadcastAsUser(managedProfileIntent, new UserHandle(parentUserId), null); |
Adam Connors | 7b66ed5 | 2014-04-14 11:58:10 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1460 | @Override |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1461 | public Bundle getApplicationRestrictions(String packageName) { |
| 1462 | return getApplicationRestrictionsForUser(packageName, UserHandle.getCallingUserId()); |
| 1463 | } |
| 1464 | |
| 1465 | @Override |
| 1466 | public Bundle getApplicationRestrictionsForUser(String packageName, int userId) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1467 | if (UserHandle.getCallingUserId() != userId |
Amith Yamasani | 9429afb | 2013-04-10 18:40:51 -0700 | [diff] [blame] | 1468 | || !UserHandle.isSameApp(Binder.getCallingUid(), getUidForPackage(packageName))) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1469 | checkManageUsersPermission("Only system can get restrictions for other users/apps"); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1470 | } |
| 1471 | synchronized (mPackagesLock) { |
| 1472 | // Read the restrictions from XML |
| 1473 | return readApplicationRestrictionsLocked(packageName, userId); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | @Override |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1478 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1479 | int userId) { |
| 1480 | if (UserHandle.getCallingUserId() != userId |
Amith Yamasani | 9429afb | 2013-04-10 18:40:51 -0700 | [diff] [blame] | 1481 | || !UserHandle.isSameApp(Binder.getCallingUid(), getUidForPackage(packageName))) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1482 | checkManageUsersPermission("Only system can set restrictions for other users/apps"); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1483 | } |
| 1484 | synchronized (mPackagesLock) { |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1485 | if (restrictions == null || restrictions.isEmpty()) { |
| 1486 | cleanAppRestrictionsForPackage(packageName, userId); |
| 1487 | } else { |
| 1488 | // Write the restrictions to XML |
| 1489 | writeApplicationRestrictionsLocked(packageName, restrictions, userId); |
| 1490 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1491 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 1492 | |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1493 | if (isPackageInstalled(packageName, userId)) { |
| 1494 | // Notify package of changes via an intent - only sent to explicitly registered receivers. |
| 1495 | Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); |
| 1496 | changeIntent.setPackage(packageName); |
| 1497 | changeIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1498 | mContext.sendBroadcastAsUser(changeIntent, new UserHandle(userId)); |
| 1499 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1502 | @Override |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1503 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1504 | checkManageUsersPermission("Only system can modify the restrictions pin"); |
| 1505 | int userId = UserHandle.getCallingUserId(); |
| 1506 | synchronized (mPackagesLock) { |
| 1507 | RestrictionsPinState pinState = mRestrictionsPinStates.get(userId); |
| 1508 | if (pinState == null) { |
| 1509 | pinState = new RestrictionsPinState(); |
| 1510 | } |
| 1511 | if (newPin == null) { |
| 1512 | pinState.salt = 0; |
| 1513 | pinState.pinHash = null; |
| 1514 | } else { |
| 1515 | try { |
| 1516 | pinState.salt = SecureRandom.getInstance("SHA1PRNG").nextLong(); |
| 1517 | } catch (NoSuchAlgorithmException e) { |
| 1518 | pinState.salt = (long) (Math.random() * Long.MAX_VALUE); |
| 1519 | } |
| 1520 | pinState.pinHash = passwordToHash(newPin, pinState.salt); |
| 1521 | pinState.failedAttempts = 0; |
| 1522 | } |
| 1523 | mRestrictionsPinStates.put(userId, pinState); |
| 1524 | writeUserLocked(mUsers.get(userId)); |
| 1525 | } |
| 1526 | return true; |
| 1527 | } |
| 1528 | |
| 1529 | @Override |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1530 | public int checkRestrictionsChallenge(String pin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1531 | checkManageUsersPermission("Only system can verify the restrictions pin"); |
| 1532 | int userId = UserHandle.getCallingUserId(); |
| 1533 | synchronized (mPackagesLock) { |
| 1534 | RestrictionsPinState pinState = mRestrictionsPinStates.get(userId); |
| 1535 | // If there's no pin set, return error code |
| 1536 | if (pinState == null || pinState.salt == 0 || pinState.pinHash == null) { |
| 1537 | return UserManager.PIN_VERIFICATION_FAILED_NOT_SET; |
| 1538 | } else if (pin == null) { |
| 1539 | // If just checking if user can be prompted, return remaining time |
| 1540 | int waitTime = getRemainingTimeForPinAttempt(pinState); |
| 1541 | Slog.d(LOG_TAG, "Remaining waittime peek=" + waitTime); |
| 1542 | return waitTime; |
| 1543 | } else { |
| 1544 | int waitTime = getRemainingTimeForPinAttempt(pinState); |
| 1545 | Slog.d(LOG_TAG, "Remaining waittime=" + waitTime); |
| 1546 | if (waitTime > 0) { |
| 1547 | return waitTime; |
| 1548 | } |
| 1549 | if (passwordToHash(pin, pinState.salt).equals(pinState.pinHash)) { |
| 1550 | pinState.failedAttempts = 0; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1551 | scheduleWriteUserLocked(mUsers.get(userId)); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1552 | return UserManager.PIN_VERIFICATION_SUCCESS; |
| 1553 | } else { |
| 1554 | pinState.failedAttempts++; |
| 1555 | pinState.lastAttemptTime = System.currentTimeMillis(); |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1556 | scheduleWriteUserLocked(mUsers.get(userId)); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1557 | return waitTime; |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | private int getRemainingTimeForPinAttempt(RestrictionsPinState pinState) { |
| 1564 | int backoffIndex = Math.min(pinState.failedAttempts / BACKOFF_INC_INTERVAL, |
| 1565 | BACKOFF_TIMES.length - 1); |
| 1566 | int backoffTime = (pinState.failedAttempts % BACKOFF_INC_INTERVAL) == 0 ? |
| 1567 | BACKOFF_TIMES[backoffIndex] : 0; |
| 1568 | return (int) Math.max(backoffTime + pinState.lastAttemptTime - System.currentTimeMillis(), |
| 1569 | 0); |
| 1570 | } |
| 1571 | |
| 1572 | @Override |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1573 | public boolean hasRestrictionsChallenge() { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1574 | int userId = UserHandle.getCallingUserId(); |
| 1575 | synchronized (mPackagesLock) { |
Amith Yamasani | 0343ec3 | 2013-07-22 14:52:06 -0700 | [diff] [blame] | 1576 | return hasRestrictionsPinLocked(userId); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | private boolean hasRestrictionsPinLocked(int userId) { |
| 1581 | RestrictionsPinState pinState = mRestrictionsPinStates.get(userId); |
| 1582 | if (pinState == null || pinState.salt == 0 || pinState.pinHash == null) { |
| 1583 | return false; |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1584 | } |
| 1585 | return true; |
| 1586 | } |
| 1587 | |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1588 | @Override |
| 1589 | public void removeRestrictions() { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 1590 | checkManageUsersPermission("Only system can remove restrictions"); |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1591 | final int userHandle = UserHandle.getCallingUserId(); |
Amith Yamasani | 5e486f5 | 2013-08-07 11:06:44 -0700 | [diff] [blame] | 1592 | removeRestrictionsForUser(userHandle, true); |
Amith Yamasani | 350962c | 2013-08-06 11:18:53 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1595 | private void removeRestrictionsForUser(final int userHandle, boolean unhideApps) { |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1596 | synchronized (mPackagesLock) { |
| 1597 | // Remove all user restrictions |
| 1598 | setUserRestrictions(new Bundle(), userHandle); |
| 1599 | // Remove restrictions pin |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 1600 | setRestrictionsChallenge(null); |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1601 | // Remove any app restrictions |
Kenny Guy | d21b218 | 2014-07-17 16:38:55 +0100 | [diff] [blame] | 1602 | cleanAppRestrictions(userHandle); |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1603 | } |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1604 | if (unhideApps) { |
| 1605 | unhideAllInstalledAppsForUser(userHandle); |
Amith Yamasani | 5e486f5 | 2013-08-07 11:06:44 -0700 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1609 | private void unhideAllInstalledAppsForUser(final int userHandle) { |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1610 | mHandler.post(new Runnable() { |
| 1611 | @Override |
| 1612 | public void run() { |
| 1613 | List<ApplicationInfo> apps = |
| 1614 | mPm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES, |
| 1615 | userHandle).getList(); |
| 1616 | final long ident = Binder.clearCallingIdentity(); |
| 1617 | try { |
| 1618 | for (ApplicationInfo appInfo : apps) { |
| 1619 | if ((appInfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0 |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1620 | && (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_HIDDEN) |
| 1621 | != 0) { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1622 | mPm.setApplicationHiddenSettingAsUser(appInfo.packageName, false, |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1623 | userHandle); |
| 1624 | } |
| 1625 | } |
| 1626 | } finally { |
| 1627 | Binder.restoreCallingIdentity(ident); |
| 1628 | } |
| 1629 | } |
| 1630 | }); |
| 1631 | } |
| 1632 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1633 | /* |
| 1634 | * Generate a hash for the given password. To avoid brute force attacks, we use a salted hash. |
| 1635 | * Not the most secure, but it is at least a second level of protection. First level is that |
| 1636 | * the file is in a location only readable by the system process. |
| 1637 | * @param password the password. |
| 1638 | * @param salt the randomly generated salt |
| 1639 | * @return the hash of the pattern in a String. |
| 1640 | */ |
| 1641 | private String passwordToHash(String password, long salt) { |
| 1642 | if (password == null) { |
| 1643 | return null; |
| 1644 | } |
| 1645 | String algo = null; |
| 1646 | String hashed = salt + password; |
| 1647 | try { |
| 1648 | byte[] saltedPassword = (password + salt).getBytes(); |
| 1649 | byte[] sha1 = MessageDigest.getInstance(algo = "SHA-1").digest(saltedPassword); |
| 1650 | byte[] md5 = MessageDigest.getInstance(algo = "MD5").digest(saltedPassword); |
| 1651 | hashed = toHex(sha1) + toHex(md5); |
| 1652 | } catch (NoSuchAlgorithmException e) { |
| 1653 | Log.w(LOG_TAG, "Failed to encode string because of missing algorithm: " + algo); |
| 1654 | } |
| 1655 | return hashed; |
| 1656 | } |
| 1657 | |
| 1658 | private static String toHex(byte[] ary) { |
| 1659 | final String hex = "0123456789ABCDEF"; |
| 1660 | String ret = ""; |
| 1661 | for (int i = 0; i < ary.length; i++) { |
| 1662 | ret += hex.charAt((ary[i] >> 4) & 0xf); |
| 1663 | ret += hex.charAt(ary[i] & 0xf); |
| 1664 | } |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1668 | private int getUidForPackage(String packageName) { |
Amith Yamasani | 9429afb | 2013-04-10 18:40:51 -0700 | [diff] [blame] | 1669 | long ident = Binder.clearCallingIdentity(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1670 | try { |
| 1671 | return mContext.getPackageManager().getApplicationInfo(packageName, |
| 1672 | PackageManager.GET_UNINSTALLED_PACKAGES).uid; |
| 1673 | } catch (NameNotFoundException nnfe) { |
| 1674 | return -1; |
Amith Yamasani | 9429afb | 2013-04-10 18:40:51 -0700 | [diff] [blame] | 1675 | } finally { |
| 1676 | Binder.restoreCallingIdentity(ident); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1680 | private Bundle readApplicationRestrictionsLocked(String packageName, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1681 | int userId) { |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1682 | AtomicFile restrictionsFile = |
| 1683 | new AtomicFile(new File(Environment.getUserSystemDirectory(userId), |
| 1684 | packageToRestrictionsFileName(packageName))); |
| 1685 | return readApplicationRestrictionsLocked(restrictionsFile); |
| 1686 | } |
| 1687 | |
| 1688 | @VisibleForTesting |
| 1689 | static Bundle readApplicationRestrictionsLocked(AtomicFile restrictionsFile) { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1690 | final Bundle restrictions = new Bundle(); |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1691 | final ArrayList<String> values = new ArrayList<>(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1692 | |
| 1693 | FileInputStream fis = null; |
| 1694 | try { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1695 | fis = restrictionsFile.openRead(); |
| 1696 | XmlPullParser parser = Xml.newPullParser(); |
| 1697 | parser.setInput(fis, null); |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1698 | XmlUtils.nextElement(parser); |
| 1699 | if (parser.getEventType() != XmlPullParser.START_TAG) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1700 | Slog.e(LOG_TAG, "Unable to read restrictions file " |
| 1701 | + restrictionsFile.getBaseFile()); |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1702 | return restrictions; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1703 | } |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1704 | while (parser.next() != XmlPullParser.END_DOCUMENT) { |
| 1705 | readEntry(restrictions, values, parser); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1706 | } |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1707 | } catch (IOException|XmlPullParserException e) { |
| 1708 | Log.w(LOG_TAG, "Error parsing " + restrictionsFile.getBaseFile(), e); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1709 | } finally { |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1710 | IoUtils.closeQuietly(fis); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1711 | } |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1712 | return restrictions; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1715 | private static void readEntry(Bundle restrictions, ArrayList<String> values, |
| 1716 | XmlPullParser parser) throws XmlPullParserException, IOException { |
| 1717 | int type = parser.getEventType(); |
| 1718 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_ENTRY)) { |
| 1719 | String key = parser.getAttributeValue(null, ATTR_KEY); |
| 1720 | String valType = parser.getAttributeValue(null, ATTR_VALUE_TYPE); |
| 1721 | String multiple = parser.getAttributeValue(null, ATTR_MULTIPLE); |
| 1722 | if (multiple != null) { |
| 1723 | values.clear(); |
| 1724 | int count = Integer.parseInt(multiple); |
| 1725 | while (count > 0 && (type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 1726 | if (type == XmlPullParser.START_TAG |
| 1727 | && parser.getName().equals(TAG_VALUE)) { |
| 1728 | values.add(parser.nextText().trim()); |
| 1729 | count--; |
| 1730 | } |
| 1731 | } |
| 1732 | String [] valueStrings = new String[values.size()]; |
| 1733 | values.toArray(valueStrings); |
| 1734 | restrictions.putStringArray(key, valueStrings); |
| 1735 | } else if (ATTR_TYPE_BUNDLE.equals(valType)) { |
| 1736 | restrictions.putBundle(key, readBundleEntry(parser, values)); |
| 1737 | } else if (ATTR_TYPE_BUNDLE_ARRAY.equals(valType)) { |
| 1738 | final int outerDepth = parser.getDepth(); |
| 1739 | ArrayList<Bundle> bundleList = new ArrayList<>(); |
| 1740 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 1741 | Bundle childBundle = readBundleEntry(parser, values); |
| 1742 | bundleList.add(childBundle); |
| 1743 | } |
| 1744 | restrictions.putParcelableArray(key, |
| 1745 | bundleList.toArray(new Bundle[bundleList.size()])); |
| 1746 | } else { |
| 1747 | String value = parser.nextText().trim(); |
| 1748 | if (ATTR_TYPE_BOOLEAN.equals(valType)) { |
| 1749 | restrictions.putBoolean(key, Boolean.parseBoolean(value)); |
| 1750 | } else if (ATTR_TYPE_INTEGER.equals(valType)) { |
| 1751 | restrictions.putInt(key, Integer.parseInt(value)); |
| 1752 | } else { |
| 1753 | restrictions.putString(key, value); |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | private static Bundle readBundleEntry(XmlPullParser parser, ArrayList<String> values) |
| 1760 | throws IOException, XmlPullParserException { |
| 1761 | Bundle childBundle = new Bundle(); |
| 1762 | final int outerDepth = parser.getDepth(); |
| 1763 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 1764 | readEntry(childBundle, values, parser); |
| 1765 | } |
| 1766 | return childBundle; |
| 1767 | } |
| 1768 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1769 | private void writeApplicationRestrictionsLocked(String packageName, |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 1770 | Bundle restrictions, int userId) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1771 | AtomicFile restrictionsFile = new AtomicFile( |
| 1772 | new File(Environment.getUserSystemDirectory(userId), |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 1773 | packageToRestrictionsFileName(packageName))); |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1774 | writeApplicationRestrictionsLocked(restrictions, restrictionsFile); |
| 1775 | } |
| 1776 | |
| 1777 | @VisibleForTesting |
| 1778 | static void writeApplicationRestrictionsLocked(Bundle restrictions, |
| 1779 | AtomicFile restrictionsFile) { |
| 1780 | FileOutputStream fos = null; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1781 | try { |
| 1782 | fos = restrictionsFile.startWrite(); |
| 1783 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 1784 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1785 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 1786 | serializer.setOutput(bos, "utf-8"); |
| 1787 | serializer.startDocument(null, true); |
| 1788 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 1789 | |
| 1790 | serializer.startTag(null, TAG_RESTRICTIONS); |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1791 | writeBundle(restrictions, serializer); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1792 | serializer.endTag(null, TAG_RESTRICTIONS); |
| 1793 | |
| 1794 | serializer.endDocument(); |
| 1795 | restrictionsFile.finishWrite(fos); |
| 1796 | } catch (Exception e) { |
| 1797 | restrictionsFile.failWrite(fos); |
Fyodor Kupolov | 262f995 | 2015-03-23 18:55:11 -0700 | [diff] [blame^] | 1798 | Slog.e(LOG_TAG, "Error writing application restrictions list", e); |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | private static void writeBundle(Bundle restrictions, XmlSerializer serializer) |
| 1803 | throws IOException { |
| 1804 | for (String key : restrictions.keySet()) { |
| 1805 | Object value = restrictions.get(key); |
| 1806 | serializer.startTag(null, TAG_ENTRY); |
| 1807 | serializer.attribute(null, ATTR_KEY, key); |
| 1808 | |
| 1809 | if (value instanceof Boolean) { |
| 1810 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_BOOLEAN); |
| 1811 | serializer.text(value.toString()); |
| 1812 | } else if (value instanceof Integer) { |
| 1813 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_INTEGER); |
| 1814 | serializer.text(value.toString()); |
| 1815 | } else if (value == null || value instanceof String) { |
| 1816 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_STRING); |
| 1817 | serializer.text(value != null ? (String) value : ""); |
| 1818 | } else if (value instanceof Bundle) { |
| 1819 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_BUNDLE); |
| 1820 | writeBundle((Bundle) value, serializer); |
| 1821 | } else if (value instanceof Parcelable[]) { |
| 1822 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_BUNDLE_ARRAY); |
| 1823 | Parcelable[] array = (Parcelable[]) value; |
| 1824 | for (Parcelable parcelable : array) { |
| 1825 | if (!(parcelable instanceof Bundle)) { |
| 1826 | throw new IllegalArgumentException("bundle-array can only hold Bundles"); |
| 1827 | } |
| 1828 | serializer.startTag(null, TAG_ENTRY); |
| 1829 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_BUNDLE); |
| 1830 | writeBundle((Bundle) parcelable, serializer); |
| 1831 | serializer.endTag(null, TAG_ENTRY); |
| 1832 | } |
| 1833 | } else { |
| 1834 | serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_STRING_ARRAY); |
| 1835 | String[] values = (String[]) value; |
| 1836 | serializer.attribute(null, ATTR_MULTIPLE, Integer.toString(values.length)); |
| 1837 | for (String choice : values) { |
| 1838 | serializer.startTag(null, TAG_VALUE); |
| 1839 | serializer.text(choice != null ? choice : ""); |
| 1840 | serializer.endTag(null, TAG_VALUE); |
| 1841 | } |
| 1842 | } |
| 1843 | serializer.endTag(null, TAG_ENTRY); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | @Override |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1848 | public int getUserSerialNumber(int userHandle) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1849 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1850 | if (!exists(userHandle)) return -1; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1851 | return getUserInfoLocked(userHandle).serialNumber; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | @Override |
| 1856 | public int getUserHandle(int userSerialNumber) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1857 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1858 | for (int userId : mUserIds) { |
Kenny Guy | 945f883 | 2015-02-10 15:17:26 +0000 | [diff] [blame] | 1859 | UserInfo info = getUserInfoLocked(userId); |
| 1860 | if (info != null && info.serialNumber == userSerialNumber) return userId; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1861 | } |
| 1862 | // Not found |
| 1863 | return -1; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1867 | /** |
| 1868 | * Caches the list of user ids in an array, adjusting the array size when necessary. |
| 1869 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1870 | private void updateUserIdsLocked() { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1871 | int num = 0; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1872 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1873 | if (!mUsers.valueAt(i).partial) { |
| 1874 | num++; |
| 1875 | } |
| 1876 | } |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1877 | final int[] newUsers = new int[num]; |
| 1878 | int n = 0; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1879 | for (int i = 0; i < mUsers.size(); i++) { |
| 1880 | if (!mUsers.valueAt(i).partial) { |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1881 | newUsers[n++] = mUsers.keyAt(i); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1882 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1883 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1884 | mUserIds = newUsers; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /** |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1888 | * Make a note of the last started time of a user and do some cleanup. |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1889 | * @param userId the user that was just foregrounded |
| 1890 | */ |
| 1891 | public void userForeground(int userId) { |
| 1892 | synchronized (mPackagesLock) { |
| 1893 | UserInfo user = mUsers.get(userId); |
| 1894 | long now = System.currentTimeMillis(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1895 | if (user == null || user.partial) { |
| 1896 | Slog.w(LOG_TAG, "userForeground: unknown user #" + userId); |
| 1897 | return; |
| 1898 | } |
| 1899 | if (now > EPOCH_PLUS_30_YEARS) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1900 | user.lastLoggedInTime = now; |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1901 | scheduleWriteUserLocked(user); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | /** |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1907 | * Returns the next available user id, filling in any holes in the ids. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1908 | * TODO: May not be a good idea to recycle ids, in case it results in confusion |
| 1909 | * for data and battery stats collection, or unexpected cross-talk. |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1910 | * @return |
| 1911 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1912 | private int getNextAvailableIdLocked() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1913 | synchronized (mPackagesLock) { |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1914 | int i = MIN_USER_ID; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1915 | while (i < Integer.MAX_VALUE) { |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1916 | if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.get(i)) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1917 | break; |
| 1918 | } |
| 1919 | i++; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1920 | } |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1921 | return i; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1922 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1923 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1924 | |
Amith Yamasani | fc95e70 | 2013-09-26 13:20:17 -0700 | [diff] [blame] | 1925 | private String packageToRestrictionsFileName(String packageName) { |
| 1926 | return RESTRICTIONS_FILE_PREFIX + packageName + XML_SUFFIX; |
| 1927 | } |
| 1928 | |
| 1929 | private String restrictionsFileNameToPackage(String fileName) { |
| 1930 | return fileName.substring(RESTRICTIONS_FILE_PREFIX.length(), |
| 1931 | (int) (fileName.length() - XML_SUFFIX.length())); |
| 1932 | } |
| 1933 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1934 | @Override |
| 1935 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1936 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1937 | != PackageManager.PERMISSION_GRANTED) { |
| 1938 | pw.println("Permission Denial: can't dump UserManager from from pid=" |
| 1939 | + Binder.getCallingPid() |
| 1940 | + ", uid=" + Binder.getCallingUid() |
| 1941 | + " without permission " |
| 1942 | + android.Manifest.permission.DUMP); |
| 1943 | return; |
| 1944 | } |
| 1945 | |
| 1946 | long now = System.currentTimeMillis(); |
| 1947 | StringBuilder sb = new StringBuilder(); |
| 1948 | synchronized (mPackagesLock) { |
| 1949 | pw.println("Users:"); |
| 1950 | for (int i = 0; i < mUsers.size(); i++) { |
| 1951 | UserInfo user = mUsers.valueAt(i); |
| 1952 | if (user == null) continue; |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 1953 | pw.print(" "); pw.print(user); pw.print(" serialNo="); pw.print(user.serialNumber); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1954 | if (mRemovingUserIds.get(mUsers.keyAt(i))) pw.print(" <removing> "); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1955 | if (user.partial) pw.print(" <partial>"); |
| 1956 | pw.println(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1957 | pw.print(" Created: "); |
| 1958 | if (user.creationTime == 0) { |
| 1959 | pw.println("<unknown>"); |
| 1960 | } else { |
| 1961 | sb.setLength(0); |
| 1962 | TimeUtils.formatDuration(now - user.creationTime, sb); |
| 1963 | sb.append(" ago"); |
| 1964 | pw.println(sb); |
| 1965 | } |
| 1966 | pw.print(" Last logged in: "); |
| 1967 | if (user.lastLoggedInTime == 0) { |
| 1968 | pw.println("<unknown>"); |
| 1969 | } else { |
| 1970 | sb.setLength(0); |
| 1971 | TimeUtils.formatDuration(now - user.lastLoggedInTime, sb); |
| 1972 | sb.append(" ago"); |
| 1973 | pw.println(sb); |
| 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | } |
Fyodor Kupolov | 75d0ea8 | 2014-12-15 16:21:07 -0800 | [diff] [blame] | 1978 | |
| 1979 | final class MainHandler extends Handler { |
| 1980 | |
| 1981 | @Override |
| 1982 | public void handleMessage(Message msg) { |
| 1983 | switch (msg.what) { |
| 1984 | case WRITE_USER_MSG: |
| 1985 | removeMessages(WRITE_USER_MSG, msg.obj); |
| 1986 | synchronized (mPackagesLock) { |
| 1987 | int userId = ((UserInfo) msg.obj).id; |
| 1988 | UserInfo userInfo = mUsers.get(userId); |
| 1989 | if (userInfo != null) { |
| 1990 | writeUserLocked(userInfo); |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1996 | } |