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 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 19 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 20 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
| 24 | import android.app.IStopUserCallback; |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 28 | import android.content.RestrictionEntry; |
| 29 | import android.content.SharedPreferences; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager.NameNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 32 | import android.content.pm.UserInfo; |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 33 | import android.graphics.Bitmap; |
| 34 | import android.graphics.BitmapFactory; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 35 | import android.os.Binder; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 36 | import android.os.Bundle; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 37 | import android.os.Environment; |
| 38 | import android.os.FileUtils; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 39 | import android.os.Handler; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 40 | import android.os.IUserManager; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 41 | import android.os.Process; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 42 | import android.os.RemoteException; |
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 | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 46 | import android.util.Slog; |
| 47 | import android.util.SparseArray; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 48 | import android.util.SparseBooleanArray; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 49 | import android.util.TimeUtils; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 50 | import android.util.Xml; |
| 51 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 52 | import com.android.internal.util.ArrayUtils; |
| 53 | import com.android.internal.util.FastXmlSerializer; |
| 54 | |
| 55 | import org.xmlpull.v1.XmlPullParser; |
| 56 | import org.xmlpull.v1.XmlPullParserException; |
| 57 | import org.xmlpull.v1.XmlSerializer; |
| 58 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 59 | import java.io.BufferedOutputStream; |
| 60 | import java.io.File; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 61 | import java.io.FileDescriptor; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 62 | import java.io.FileInputStream; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 63 | import java.io.FileNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 64 | import java.io.FileOutputStream; |
| 65 | import java.io.IOException; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 66 | import java.io.PrintWriter; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 67 | import java.util.ArrayList; |
| 68 | import java.util.List; |
| 69 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 70 | public class UserManagerService extends IUserManager.Stub { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 71 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 72 | private static final String LOG_TAG = "UserManagerService"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 73 | |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 74 | private static final boolean DBG = false; |
| 75 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 76 | private static final String TAG_NAME = "name"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 77 | private static final String ATTR_FLAGS = "flags"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 78 | private static final String ATTR_ICON_PATH = "icon"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 79 | private static final String ATTR_ID = "id"; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 80 | private static final String ATTR_CREATION_TIME = "created"; |
| 81 | private static final String ATTR_LAST_LOGGED_IN_TIME = "lastLoggedIn"; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 82 | private static final String ATTR_SERIAL_NO = "serialNumber"; |
| 83 | private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 84 | private static final String ATTR_PARTIAL = "partial"; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 85 | private static final String ATTR_USER_VERSION = "version"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 86 | private static final String TAG_USERS = "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 87 | private static final String TAG_USER = "user"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 88 | private static final String TAG_RESTRICTIONS = "restrictions"; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 89 | private static final String TAG_ENTRY = "entry"; |
| 90 | private static final String TAG_VALUE = "value"; |
| 91 | private static final String ATTR_KEY = "key"; |
| 92 | private static final String ATTR_MULTIPLE = "m"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 93 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 94 | private static final String USER_INFO_DIR = "system" + File.separator + "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 95 | private static final String USER_LIST_FILENAME = "userlist.xml"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 96 | private static final String USER_PHOTO_FILENAME = "photo.png"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 97 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 98 | private static final String RESTRICTIONS_FILE_PREFIX = "res_"; |
| 99 | |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 100 | private static final int MIN_USER_ID = 10; |
| 101 | |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 102 | private static final int USER_VERSION = 2; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 103 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 104 | private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms |
| 105 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 106 | private final Context mContext; |
| 107 | private final PackageManagerService mPm; |
| 108 | private final Object mInstallLock; |
| 109 | private final Object mPackagesLock; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 111 | private final Handler mHandler; |
| 112 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 113 | private final File mUsersDir; |
| 114 | private final File mUserListFile; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 115 | private final File mBaseUserPath; |
| 116 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 117 | private final SparseArray<UserInfo> mUsers = new SparseArray<UserInfo>(); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 118 | private final SparseArray<Bundle> mUserRestrictions = new SparseArray<Bundle>(); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Set of user IDs being actively removed. Removed IDs linger in this set |
| 122 | * for several seconds to work around a VFS caching issue. |
| 123 | */ |
| 124 | // @GuardedBy("mPackagesLock") |
| 125 | private final SparseBooleanArray mRemovingUserIds = new SparseBooleanArray(); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 126 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 127 | private int[] mUserIds; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 128 | private boolean mGuestEnabled; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 129 | private int mNextSerialNumber; |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 130 | private int mUserVersion = 0; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 131 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 132 | private static UserManagerService sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 133 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 134 | public static UserManagerService getInstance() { |
| 135 | synchronized (UserManagerService.class) { |
| 136 | return sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 137 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 138 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Available for testing purposes. |
| 142 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 143 | UserManagerService(File dataDir, File baseUserPath) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 144 | this(null, null, new Object(), new Object(), dataDir, baseUserPath); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 147 | /** |
| 148 | * Called by package manager to create the service. This is closely |
| 149 | * associated with the package manager, and the given lock is the |
| 150 | * package manager's own lock. |
| 151 | */ |
| 152 | UserManagerService(Context context, PackageManagerService pm, |
| 153 | Object installLock, Object packagesLock) { |
| 154 | this(context, pm, installLock, packagesLock, |
| 155 | Environment.getDataDirectory(), |
| 156 | new File(Environment.getDataDirectory(), "user")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Available for testing purposes. |
| 161 | */ |
| 162 | private UserManagerService(Context context, PackageManagerService pm, |
| 163 | Object installLock, Object packagesLock, |
| 164 | File dataDir, File baseUserPath) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 165 | mContext = context; |
| 166 | mPm = pm; |
| 167 | mInstallLock = installLock; |
| 168 | mPackagesLock = packagesLock; |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 169 | mHandler = new Handler(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 170 | synchronized (mInstallLock) { |
| 171 | synchronized (mPackagesLock) { |
| 172 | mUsersDir = new File(dataDir, USER_INFO_DIR); |
| 173 | mUsersDir.mkdirs(); |
| 174 | // Make zeroth user directory, for services to migrate their files to that location |
| 175 | File userZeroDir = new File(mUsersDir, "0"); |
| 176 | userZeroDir.mkdirs(); |
| 177 | mBaseUserPath = baseUserPath; |
| 178 | FileUtils.setPermissions(mUsersDir.toString(), |
| 179 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 180 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 181 | -1, -1); |
| 182 | mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); |
| 183 | readUserListLocked(); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 184 | // Prune out any partially created/partially removed users. |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 185 | ArrayList<UserInfo> partials = new ArrayList<UserInfo>(); |
| 186 | for (int i = 0; i < mUsers.size(); i++) { |
| 187 | UserInfo ui = mUsers.valueAt(i); |
| 188 | if (ui.partial && i != 0) { |
| 189 | partials.add(ui); |
| 190 | } |
| 191 | } |
| 192 | for (int i = 0; i < partials.size(); i++) { |
| 193 | UserInfo ui = partials.get(i); |
| 194 | Slog.w(LOG_TAG, "Removing partially created user #" + i |
| 195 | + " (name=" + ui.name + ")"); |
| 196 | removeUserStateLocked(ui.id); |
| 197 | } |
| 198 | sInstance = this; |
| 199 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 200 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 204 | public List<UserInfo> getUsers(boolean excludeDying) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 205 | checkManageUsersPermission("query users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 206 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 207 | ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); |
| 208 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 209 | UserInfo ui = mUsers.valueAt(i); |
| 210 | if (ui.partial) { |
| 211 | continue; |
| 212 | } |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 213 | if (!excludeDying || !mRemovingUserIds.get(ui.id)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 214 | users.add(ui); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 215 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 216 | } |
| 217 | return users; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 218 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 221 | @Override |
| 222 | public UserInfo getUserInfo(int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 223 | checkManageUsersPermission("query user"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 224 | synchronized (mPackagesLock) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 225 | return getUserInfoLocked(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame^] | 229 | @Override |
| 230 | public boolean isRestricted() { |
| 231 | synchronized (mPackagesLock) { |
| 232 | return getUserInfoLocked(UserHandle.getCallingUserId()).isRestricted(); |
| 233 | } |
| 234 | } |
| 235 | |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 236 | /* |
| 237 | * Should be locked on mUsers before calling this. |
| 238 | */ |
| 239 | private UserInfo getUserInfoLocked(int userId) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 240 | UserInfo ui = mUsers.get(userId); |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 241 | // 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] | 242 | if (ui != null && ui.partial && !mRemovingUserIds.get(userId)) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 243 | Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId); |
| 244 | return null; |
| 245 | } |
| 246 | return ui; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 249 | public boolean exists(int userId) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 250 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 251 | return ArrayUtils.contains(mUserIds, userId); |
| 252 | } |
| 253 | } |
| 254 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 255 | @Override |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 256 | public void setUserName(int userId, String name) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 257 | checkManageUsersPermission("rename users"); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 258 | boolean changed = false; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 259 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 260 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 261 | if (info == null || info.partial) { |
| 262 | Slog.w(LOG_TAG, "setUserName: unknown user #" + userId); |
| 263 | return; |
| 264 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 265 | if (name != null && !name.equals(info.name)) { |
| 266 | info.name = name; |
| 267 | writeUserLocked(info); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 268 | changed = true; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 271 | if (changed) { |
| 272 | sendUserInfoChangedBroadcast(userId); |
| 273 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 276 | @Override |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 277 | public void setUserIcon(int userId, Bitmap bitmap) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 278 | checkManageUsersPermission("update users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 279 | synchronized (mPackagesLock) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 280 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 281 | if (info == null || info.partial) { |
| 282 | Slog.w(LOG_TAG, "setUserIcon: unknown user #" + userId); |
| 283 | return; |
| 284 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 285 | writeBitmapLocked(info, bitmap); |
| 286 | writeUserLocked(info); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 287 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 288 | sendUserInfoChangedBroadcast(userId); |
| 289 | } |
| 290 | |
| 291 | private void sendUserInfoChangedBroadcast(int userId) { |
| 292 | Intent changedIntent = new Intent(Intent.ACTION_USER_INFO_CHANGED); |
| 293 | changedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 294 | changedIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 295 | mContext.sendBroadcastAsUser(changedIntent, new UserHandle(userId)); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 298 | @Override |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 299 | public Bitmap getUserIcon(int userId) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 300 | checkManageUsersPermission("read users"); |
| 301 | synchronized (mPackagesLock) { |
| 302 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 303 | if (info == null || info.partial) { |
| 304 | Slog.w(LOG_TAG, "getUserIcon: unknown user #" + userId); |
| 305 | return null; |
| 306 | } |
| 307 | if (info.iconPath == null) { |
| 308 | return null; |
| 309 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 310 | return BitmapFactory.decodeFile(info.iconPath); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | @Override |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 315 | public void setGuestEnabled(boolean enable) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 316 | checkManageUsersPermission("enable guest users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 317 | synchronized (mPackagesLock) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 318 | if (mGuestEnabled != enable) { |
| 319 | mGuestEnabled = enable; |
| 320 | // Erase any guest user that currently exists |
| 321 | for (int i = 0; i < mUsers.size(); i++) { |
| 322 | UserInfo user = mUsers.valueAt(i); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 323 | if (!user.partial && user.isGuest()) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 324 | if (!enable) { |
| 325 | removeUser(user.id); |
| 326 | } |
| 327 | return; |
| 328 | } |
| 329 | } |
| 330 | // No guest was found |
| 331 | if (enable) { |
| 332 | createUser("Guest", UserInfo.FLAG_GUEST); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public boolean isGuestEnabled() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 340 | synchronized (mPackagesLock) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 341 | return mGuestEnabled; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void wipeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 347 | checkManageUsersPermission("wipe user"); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 348 | // TODO: |
| 349 | } |
| 350 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 351 | public void makeInitialized(int userId) { |
| 352 | checkManageUsersPermission("makeInitialized"); |
| 353 | synchronized (mPackagesLock) { |
| 354 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 355 | if (info == null || info.partial) { |
| 356 | Slog.w(LOG_TAG, "makeInitialized: unknown user #" + userId); |
| 357 | } |
| 358 | if ((info.flags&UserInfo.FLAG_INITIALIZED) == 0) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 359 | info.flags |= UserInfo.FLAG_INITIALIZED; |
| 360 | writeUserLocked(info); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public Bundle getUserRestrictions(int userId) { |
| 367 | // checkManageUsersPermission("getUserRestrictions"); |
| 368 | |
| 369 | synchronized (mPackagesLock) { |
| 370 | Bundle restrictions = mUserRestrictions.get(userId); |
| 371 | return restrictions != null ? restrictions : Bundle.EMPTY; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void setUserRestrictions(Bundle restrictions, int userId) { |
| 377 | checkManageUsersPermission("setUserRestrictions"); |
| 378 | |
| 379 | synchronized (mPackagesLock) { |
| 380 | mUserRestrictions.get(userId).putAll(restrictions); |
| 381 | writeUserLocked(mUsers.get(userId)); |
| 382 | } |
| 383 | } |
| 384 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 385 | /** |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 386 | * Check if we've hit the limit of how many users can be created. |
| 387 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 388 | private boolean isUserLimitReachedLocked() { |
| 389 | int nUsers = mUsers.size(); |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 390 | return nUsers >= UserManager.getMaxSupportedUsers(); |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /** |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 394 | * Enforces that only the system UID or root's UID or apps that have the |
| 395 | * {@link android.Manifest.permission.MANAGE_USERS MANAGE_USERS} |
| 396 | * permission can make certain calls to the UserManager. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 397 | * |
| 398 | * @param message used as message if SecurityException is thrown |
| 399 | * @throws SecurityException if the caller is not system or root |
| 400 | */ |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 401 | private static final void checkManageUsersPermission(String message) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 402 | final int uid = Binder.getCallingUid(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 403 | if (uid != Process.SYSTEM_UID && uid != 0 |
| 404 | && ActivityManager.checkComponentPermission( |
| 405 | android.Manifest.permission.MANAGE_USERS, |
| 406 | uid, -1, true) != PackageManager.PERMISSION_GRANTED) { |
| 407 | throw new SecurityException("You need MANAGE_USERS permission to: " + message); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 411 | private void writeBitmapLocked(UserInfo info, Bitmap bitmap) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 412 | try { |
| 413 | File dir = new File(mUsersDir, Integer.toString(info.id)); |
| 414 | File file = new File(dir, USER_PHOTO_FILENAME); |
| 415 | if (!dir.exists()) { |
| 416 | dir.mkdir(); |
| 417 | FileUtils.setPermissions( |
| 418 | dir.getPath(), |
| 419 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 420 | -1, -1); |
| 421 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 422 | FileOutputStream os; |
| 423 | if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(file))) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 424 | info.iconPath = file.getAbsolutePath(); |
| 425 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 426 | try { |
| 427 | os.close(); |
| 428 | } catch (IOException ioe) { |
| 429 | // What the ... ! |
| 430 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 431 | } catch (FileNotFoundException e) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 432 | Slog.w(LOG_TAG, "Error setting photo for user ", e); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 433 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 436 | /** |
| 437 | * Returns an array of user ids. This array is cached here for quick access, so do not modify or |
| 438 | * cache it elsewhere. |
| 439 | * @return the array of user ids. |
| 440 | */ |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 441 | public int[] getUserIds() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 442 | synchronized (mPackagesLock) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 443 | return mUserIds; |
| 444 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 447 | int[] getUserIdsLPr() { |
| 448 | return mUserIds; |
| 449 | } |
| 450 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 451 | private void readUserList() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 452 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 453 | readUserListLocked(); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | private void readUserListLocked() { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 458 | mGuestEnabled = false; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 459 | if (!mUserListFile.exists()) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 460 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | FileInputStream fis = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 464 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 465 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 466 | fis = userListFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 467 | XmlPullParser parser = Xml.newPullParser(); |
| 468 | parser.setInput(fis, null); |
| 469 | int type; |
| 470 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 471 | && type != XmlPullParser.END_DOCUMENT) { |
| 472 | ; |
| 473 | } |
| 474 | |
| 475 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 476 | Slog.e(LOG_TAG, "Unable to read user list"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 477 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 478 | return; |
| 479 | } |
| 480 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 481 | mNextSerialNumber = -1; |
| 482 | if (parser.getName().equals(TAG_USERS)) { |
| 483 | String lastSerialNumber = parser.getAttributeValue(null, ATTR_NEXT_SERIAL_NO); |
| 484 | if (lastSerialNumber != null) { |
| 485 | mNextSerialNumber = Integer.parseInt(lastSerialNumber); |
| 486 | } |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 487 | String versionNumber = parser.getAttributeValue(null, ATTR_USER_VERSION); |
| 488 | if (versionNumber != null) { |
| 489 | mUserVersion = Integer.parseInt(versionNumber); |
| 490 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 493 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 494 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
| 495 | String id = parser.getAttributeValue(null, ATTR_ID); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 496 | UserInfo user = readUserLocked(Integer.parseInt(id)); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 497 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 498 | if (user != null) { |
| 499 | mUsers.put(user.id, user); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 500 | if (user.isGuest()) { |
| 501 | mGuestEnabled = true; |
| 502 | } |
| 503 | if (mNextSerialNumber < 0 || mNextSerialNumber <= user.id) { |
| 504 | mNextSerialNumber = user.id + 1; |
| 505 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 506 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 509 | updateUserIdsLocked(); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 510 | upgradeIfNecessary(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 511 | } catch (IOException ioe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 512 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 513 | } catch (XmlPullParserException pe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 514 | fallbackToSingleUserLocked(); |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 515 | } finally { |
| 516 | if (fis != null) { |
| 517 | try { |
| 518 | fis.close(); |
| 519 | } catch (IOException e) { |
| 520 | } |
| 521 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 525 | /** |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 526 | * 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] | 527 | */ |
| 528 | private void upgradeIfNecessary() { |
| 529 | int userVersion = mUserVersion; |
| 530 | if (userVersion < 1) { |
| 531 | // Assign a proper name for the owner, if not initialized correctly before |
| 532 | UserInfo user = mUsers.get(UserHandle.USER_OWNER); |
| 533 | if ("Primary".equals(user.name)) { |
| 534 | user.name = mContext.getResources().getString(com.android.internal.R.string.owner_name); |
| 535 | writeUserLocked(user); |
| 536 | } |
| 537 | userVersion = 1; |
| 538 | } |
| 539 | |
Amith Yamasani | bc962505 | 2012-11-15 14:39:18 -0800 | [diff] [blame] | 540 | if (userVersion < 2) { |
| 541 | // Owner should be marked as initialized |
| 542 | UserInfo user = mUsers.get(UserHandle.USER_OWNER); |
| 543 | if ((user.flags & UserInfo.FLAG_INITIALIZED) == 0) { |
| 544 | user.flags |= UserInfo.FLAG_INITIALIZED; |
| 545 | writeUserLocked(user); |
| 546 | } |
| 547 | userVersion = 2; |
| 548 | } |
| 549 | |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 550 | if (userVersion < USER_VERSION) { |
| 551 | Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to " |
| 552 | + USER_VERSION); |
| 553 | } else { |
| 554 | mUserVersion = userVersion; |
| 555 | writeUserListLocked(); |
| 556 | } |
| 557 | } |
| 558 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 559 | private void fallbackToSingleUserLocked() { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 560 | // Create the primary user |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 561 | UserInfo primary = new UserInfo(UserHandle.USER_OWNER, |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 562 | mContext.getResources().getString(com.android.internal.R.string.owner_name), null, |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 563 | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY | UserInfo.FLAG_INITIALIZED); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 564 | mUsers.put(0, primary); |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 565 | mNextSerialNumber = MIN_USER_ID; |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 566 | |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 567 | Bundle restrictions = new Bundle(); |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 568 | mUserRestrictions.append(UserHandle.USER_OWNER, restrictions); |
| 569 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 570 | updateUserIdsLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 571 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 572 | writeUserListLocked(); |
| 573 | writeUserLocked(primary); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Writes the user file in this format: |
| 578 | * |
| 579 | * <user flags="20039023" id="0"> |
| 580 | * <name>Primary</name> |
| 581 | * </user> |
| 582 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 583 | private void writeUserLocked(UserInfo userInfo) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 584 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 585 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 586 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 587 | fos = userFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 588 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 589 | |
| 590 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 591 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 592 | serializer.setOutput(bos, "utf-8"); |
| 593 | serializer.startDocument(null, true); |
| 594 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 595 | |
| 596 | serializer.startTag(null, TAG_USER); |
| 597 | serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id)); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 598 | serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 599 | serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags)); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 600 | serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime)); |
| 601 | serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME, |
| 602 | Long.toString(userInfo.lastLoggedInTime)); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 603 | if (userInfo.iconPath != null) { |
| 604 | serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); |
| 605 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 606 | if (userInfo.partial) { |
| 607 | serializer.attribute(null, ATTR_PARTIAL, "true"); |
| 608 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 609 | |
| 610 | serializer.startTag(null, TAG_NAME); |
| 611 | serializer.text(userInfo.name); |
| 612 | serializer.endTag(null, TAG_NAME); |
| 613 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 614 | Bundle restrictions = mUserRestrictions.get(userInfo.id); |
| 615 | if (restrictions != null) { |
| 616 | serializer.startTag(null, TAG_RESTRICTIONS); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame^] | 617 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_WIFI); |
| 618 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_MODIFY_ACCOUNTS); |
| 619 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_INSTALL_APPS); |
| 620 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_UNINSTALL_APPS); |
| 621 | writeBoolean(serializer, restrictions, UserManager.DISALLOW_SHARE_LOCATION); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 622 | serializer.endTag(null, TAG_RESTRICTIONS); |
| 623 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 624 | serializer.endTag(null, TAG_USER); |
| 625 | |
| 626 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 627 | userFile.finishWrite(fos); |
| 628 | } catch (Exception ioe) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 629 | Slog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 630 | userFile.failWrite(fos); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * Writes the user list file in this format: |
| 636 | * |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 637 | * <users nextSerialNumber="3"> |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 638 | * <user id="0"></user> |
| 639 | * <user id="2"></user> |
| 640 | * </users> |
| 641 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 642 | private void writeUserListLocked() { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 643 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 644 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 645 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 646 | fos = userListFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 647 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 648 | |
| 649 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 650 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 651 | serializer.setOutput(bos, "utf-8"); |
| 652 | serializer.startDocument(null, true); |
| 653 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 654 | |
| 655 | serializer.startTag(null, TAG_USERS); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 656 | serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); |
Amith Yamasani | 6f34b41 | 2012-10-22 18:19:27 -0700 | [diff] [blame] | 657 | serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 658 | |
| 659 | for (int i = 0; i < mUsers.size(); i++) { |
| 660 | UserInfo user = mUsers.valueAt(i); |
| 661 | serializer.startTag(null, TAG_USER); |
| 662 | serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); |
| 663 | serializer.endTag(null, TAG_USER); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | serializer.endTag(null, TAG_USERS); |
| 667 | |
| 668 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 669 | userListFile.finishWrite(fos); |
| 670 | } catch (Exception e) { |
| 671 | userListFile.failWrite(fos); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 672 | Slog.e(LOG_TAG, "Error writing user list"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 676 | private UserInfo readUserLocked(int id) { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 677 | int flags = 0; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 678 | int serialNumber = id; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 679 | String name = null; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 680 | String iconPath = null; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 681 | long creationTime = 0L; |
| 682 | long lastLoggedInTime = 0L; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 683 | boolean partial = false; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 684 | Bundle restrictions = new Bundle(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 685 | |
| 686 | FileInputStream fis = null; |
| 687 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 688 | AtomicFile userFile = |
| 689 | new AtomicFile(new File(mUsersDir, Integer.toString(id) + ".xml")); |
| 690 | fis = userFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 691 | XmlPullParser parser = Xml.newPullParser(); |
| 692 | parser.setInput(fis, null); |
| 693 | int type; |
| 694 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 695 | && type != XmlPullParser.END_DOCUMENT) { |
| 696 | ; |
| 697 | } |
| 698 | |
| 699 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 700 | Slog.e(LOG_TAG, "Unable to read user " + id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 701 | return null; |
| 702 | } |
| 703 | |
| 704 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 705 | int storedId = readIntAttribute(parser, ATTR_ID, -1); |
| 706 | if (storedId != id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 707 | Slog.e(LOG_TAG, "User id does not match the file name"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 708 | return null; |
| 709 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 710 | serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id); |
| 711 | flags = readIntAttribute(parser, ATTR_FLAGS, 0); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 712 | iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 713 | creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0); |
| 714 | lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 715 | String valueString = parser.getAttributeValue(null, ATTR_PARTIAL); |
| 716 | if ("true".equals(valueString)) { |
| 717 | partial = true; |
| 718 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 719 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 720 | int outerDepth = parser.getDepth(); |
| 721 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 722 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 723 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 724 | continue; |
| 725 | } |
| 726 | String tag = parser.getName(); |
| 727 | if (TAG_NAME.equals(tag)) { |
| 728 | type = parser.next(); |
| 729 | if (type == XmlPullParser.TEXT) { |
| 730 | name = parser.getText(); |
| 731 | } |
| 732 | } else if (TAG_RESTRICTIONS.equals(tag)) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame^] | 733 | readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_WIFI); |
| 734 | readBoolean(parser, restrictions, UserManager.DISALLOW_MODIFY_ACCOUNTS); |
| 735 | readBoolean(parser, restrictions, UserManager.DISALLOW_INSTALL_APPS); |
| 736 | readBoolean(parser, restrictions, UserManager.DISALLOW_UNINSTALL_APPS); |
| 737 | readBoolean(parser, restrictions, UserManager.DISALLOW_SHARE_LOCATION); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 741 | |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 742 | UserInfo userInfo = new UserInfo(id, name, iconPath, flags); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 743 | userInfo.serialNumber = serialNumber; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 744 | userInfo.creationTime = creationTime; |
| 745 | userInfo.lastLoggedInTime = lastLoggedInTime; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 746 | userInfo.partial = partial; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 747 | mUserRestrictions.append(id, restrictions); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 748 | return userInfo; |
| 749 | |
| 750 | } catch (IOException ioe) { |
| 751 | } catch (XmlPullParserException pe) { |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 752 | } finally { |
| 753 | if (fis != null) { |
| 754 | try { |
| 755 | fis.close(); |
| 756 | } catch (IOException e) { |
| 757 | } |
| 758 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 759 | } |
| 760 | return null; |
| 761 | } |
| 762 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 763 | private void readBoolean(XmlPullParser parser, Bundle restrictions, |
| 764 | String restrictionKey) { |
| 765 | String value = parser.getAttributeValue(null, restrictionKey); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame^] | 766 | if (value != null) { |
| 767 | restrictions.putBoolean(restrictionKey, Boolean.parseBoolean(value)); |
| 768 | } |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | private void writeBoolean(XmlSerializer xml, Bundle restrictions, String restrictionKey) |
| 772 | throws IOException { |
| 773 | if (restrictions.containsKey(restrictionKey)) { |
| 774 | xml.attribute(null, restrictionKey, |
| 775 | Boolean.toString(restrictions.getBoolean(restrictionKey))); |
| 776 | } |
| 777 | } |
| 778 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 779 | private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) { |
| 780 | String valueString = parser.getAttributeValue(null, attr); |
| 781 | if (valueString == null) return defaultValue; |
| 782 | try { |
| 783 | return Integer.parseInt(valueString); |
| 784 | } catch (NumberFormatException nfe) { |
| 785 | return defaultValue; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | private long readLongAttribute(XmlPullParser parser, String attr, long defaultValue) { |
| 790 | String valueString = parser.getAttributeValue(null, attr); |
| 791 | if (valueString == null) return defaultValue; |
| 792 | try { |
| 793 | return Long.parseLong(valueString); |
| 794 | } catch (NumberFormatException nfe) { |
| 795 | return defaultValue; |
| 796 | } |
| 797 | } |
| 798 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 799 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 800 | public UserInfo createUser(String name, int flags) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 801 | checkManageUsersPermission("Only the system can create users"); |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 802 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 803 | final long ident = Binder.clearCallingIdentity(); |
| 804 | final UserInfo userInfo; |
| 805 | try { |
| 806 | synchronized (mInstallLock) { |
| 807 | synchronized (mPackagesLock) { |
| 808 | if (isUserLimitReachedLocked()) return null; |
| 809 | int userId = getNextAvailableIdLocked(); |
| 810 | userInfo = new UserInfo(userId, name, null, flags); |
| 811 | File userPath = new File(mBaseUserPath, Integer.toString(userId)); |
| 812 | userInfo.serialNumber = mNextSerialNumber++; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 813 | long now = System.currentTimeMillis(); |
| 814 | userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 815 | userInfo.partial = true; |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 816 | Environment.getUserSystemDirectory(userInfo.id).mkdirs(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 817 | mUsers.put(userId, userInfo); |
| 818 | writeUserListLocked(); |
| 819 | writeUserLocked(userInfo); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 820 | mPm.createNewUserLILPw(userId, userPath); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 821 | userInfo.partial = false; |
| 822 | writeUserLocked(userInfo); |
| 823 | updateUserIdsLocked(); |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 824 | Bundle restrictions = new Bundle(); |
Geoffrey Borggaard | e45e45e3 | 2013-01-24 10:03:20 -0500 | [diff] [blame] | 825 | mUserRestrictions.append(userId, restrictions); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 826 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 827 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 828 | if (userInfo != null) { |
| 829 | Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED); |
| 830 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id); |
| 831 | mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 832 | android.Manifest.permission.MANAGE_USERS); |
| 833 | } |
| 834 | } finally { |
| 835 | Binder.restoreCallingIdentity(ident); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 836 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 837 | return userInfo; |
| 838 | } |
| 839 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 840 | /** |
| 841 | * Removes a user and all data directories created for that user. This method should be called |
| 842 | * after the user's processes have been terminated. |
| 843 | * @param id the user's id |
| 844 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 845 | public boolean removeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 846 | checkManageUsersPermission("Only the system can remove users"); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 847 | final UserInfo user; |
| 848 | synchronized (mPackagesLock) { |
| 849 | user = mUsers.get(userHandle); |
| 850 | if (userHandle == 0 || user == null) { |
| 851 | return false; |
| 852 | } |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 853 | mRemovingUserIds.put(userHandle, true); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 854 | // Set this to a partially created user, so that the user will be purged |
| 855 | // on next startup, in case the runtime stops now before stopping and |
| 856 | // removing the user completely. |
| 857 | user.partial = true; |
| 858 | writeUserLocked(user); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 859 | } |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 860 | if (DBG) Slog.i(LOG_TAG, "Stopping user " + userHandle); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 861 | int res; |
| 862 | try { |
| 863 | res = ActivityManagerNative.getDefault().stopUser(userHandle, |
| 864 | new IStopUserCallback.Stub() { |
| 865 | @Override |
| 866 | public void userStopped(int userId) { |
| 867 | finishRemoveUser(userId); |
| 868 | } |
| 869 | @Override |
| 870 | public void userStopAborted(int userId) { |
| 871 | } |
| 872 | }); |
| 873 | } catch (RemoteException e) { |
| 874 | return false; |
| 875 | } |
| 876 | |
| 877 | return res == ActivityManager.USER_OP_SUCCESS; |
| 878 | } |
| 879 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 880 | void finishRemoveUser(final int userHandle) { |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 881 | if (DBG) Slog.i(LOG_TAG, "finishRemoveUser " + userHandle); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 882 | // Let other services shutdown any activity and clean up their state before completely |
| 883 | // wiping the user's system directory and removing from the user list |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 884 | long ident = Binder.clearCallingIdentity(); |
| 885 | try { |
| 886 | Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED); |
| 887 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 888 | mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 889 | android.Manifest.permission.MANAGE_USERS, |
| 890 | |
| 891 | new BroadcastReceiver() { |
| 892 | @Override |
| 893 | public void onReceive(Context context, Intent intent) { |
| 894 | if (DBG) { |
| 895 | Slog.i(LOG_TAG, |
| 896 | "USER_REMOVED broadcast sent, cleaning up user data " |
| 897 | + userHandle); |
| 898 | } |
| 899 | new Thread() { |
| 900 | public void run() { |
| 901 | synchronized (mInstallLock) { |
| 902 | synchronized (mPackagesLock) { |
| 903 | removeUserStateLocked(userHandle); |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | }.start(); |
| 908 | } |
| 909 | }, |
| 910 | |
| 911 | null, Activity.RESULT_OK, null, null); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 912 | } finally { |
| 913 | Binder.restoreCallingIdentity(ident); |
| 914 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 917 | private void removeUserStateLocked(final int userHandle) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 918 | // Cleanup package manager settings |
| 919 | mPm.cleanUpUserLILPw(userHandle); |
| 920 | |
| 921 | // Remove this user from the list |
| 922 | mUsers.remove(userHandle); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 923 | |
| 924 | // Have user ID linger for several seconds to let external storage VFS |
| 925 | // cache entries expire. This must be greater than the 'entry_valid' |
| 926 | // timeout used by the FUSE daemon. |
| 927 | mHandler.postDelayed(new Runnable() { |
| 928 | @Override |
| 929 | public void run() { |
| 930 | synchronized (mPackagesLock) { |
| 931 | mRemovingUserIds.delete(userHandle); |
| 932 | } |
| 933 | } |
| 934 | }, MINUTE_IN_MILLIS); |
| 935 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 936 | // Remove user file |
| 937 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); |
| 938 | userFile.delete(); |
| 939 | // Update the user list |
| 940 | writeUserListLocked(); |
| 941 | updateUserIdsLocked(); |
| 942 | removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle)); |
| 943 | } |
| 944 | |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 945 | private void removeDirectoryRecursive(File parent) { |
| 946 | if (parent.isDirectory()) { |
| 947 | String[] files = parent.list(); |
| 948 | for (String filename : files) { |
| 949 | File child = new File(parent, filename); |
| 950 | removeDirectoryRecursive(child); |
| 951 | } |
| 952 | } |
| 953 | parent.delete(); |
| 954 | } |
| 955 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 956 | @Override |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 957 | public List<RestrictionEntry> getApplicationRestrictions(String packageName, int userId) { |
| 958 | if (UserHandle.getCallingUserId() != userId |
| 959 | || Binder.getCallingUid() != getUidForPackage(packageName)) { |
| 960 | checkManageUsersPermission("Only system can get restrictions for other users/apps"); |
| 961 | } |
| 962 | synchronized (mPackagesLock) { |
| 963 | // Read the restrictions from XML |
| 964 | return readApplicationRestrictionsLocked(packageName, userId); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | @Override |
| 969 | public void setApplicationRestrictions(String packageName, List<RestrictionEntry> entries, |
| 970 | int userId) { |
| 971 | if (UserHandle.getCallingUserId() != userId |
| 972 | || Binder.getCallingUid() != getUidForPackage(packageName)) { |
| 973 | checkManageUsersPermission("Only system can set restrictions for other users/apps"); |
| 974 | } |
| 975 | synchronized (mPackagesLock) { |
| 976 | // Write the restrictions to XML |
| 977 | writeApplicationRestrictionsLocked(packageName, entries, userId); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | private int getUidForPackage(String packageName) { |
| 982 | try { |
| 983 | return mContext.getPackageManager().getApplicationInfo(packageName, |
| 984 | PackageManager.GET_UNINSTALLED_PACKAGES).uid; |
| 985 | } catch (NameNotFoundException nnfe) { |
| 986 | return -1; |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | private List<RestrictionEntry> readApplicationRestrictionsLocked(String packageName, |
| 991 | int userId) { |
| 992 | final ArrayList<RestrictionEntry> entries = new ArrayList<RestrictionEntry>(); |
| 993 | final ArrayList<String> values = new ArrayList<String>(); |
| 994 | |
| 995 | FileInputStream fis = null; |
| 996 | try { |
| 997 | AtomicFile restrictionsFile = |
| 998 | new AtomicFile(new File(Environment.getUserSystemDirectory(userId), |
| 999 | RESTRICTIONS_FILE_PREFIX + packageName + ".xml")); |
| 1000 | fis = restrictionsFile.openRead(); |
| 1001 | XmlPullParser parser = Xml.newPullParser(); |
| 1002 | parser.setInput(fis, null); |
| 1003 | int type; |
| 1004 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 1005 | && type != XmlPullParser.END_DOCUMENT) { |
| 1006 | ; |
| 1007 | } |
| 1008 | |
| 1009 | if (type != XmlPullParser.START_TAG) { |
| 1010 | Slog.e(LOG_TAG, "Unable to read restrictions file " |
| 1011 | + restrictionsFile.getBaseFile()); |
| 1012 | return entries; |
| 1013 | } |
| 1014 | |
| 1015 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 1016 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_ENTRY)) { |
| 1017 | String key = parser.getAttributeValue(null, ATTR_KEY); |
| 1018 | String multiple = parser.getAttributeValue(null, ATTR_MULTIPLE); |
| 1019 | if (multiple != null) { |
| 1020 | int count = Integer.parseInt(multiple); |
| 1021 | while (count > 0 && (type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 1022 | if (type == XmlPullParser.START_TAG |
| 1023 | && parser.getName().equals(TAG_VALUE)) { |
| 1024 | values.add(parser.nextText().trim()); |
| 1025 | count--; |
| 1026 | } |
| 1027 | } |
| 1028 | String [] valueStrings = new String[values.size()]; |
| 1029 | values.toArray(valueStrings); |
| 1030 | Slog.d(LOG_TAG, "Got RestrictionEntry " + key + "," + valueStrings); |
| 1031 | RestrictionEntry entry = new RestrictionEntry(key, valueStrings); |
| 1032 | entries.add(entry); |
| 1033 | } else { |
| 1034 | String value = parser.nextText().trim(); |
| 1035 | Slog.d(LOG_TAG, "Got RestrictionEntry " + key + "," + value); |
| 1036 | RestrictionEntry entry = new RestrictionEntry(key, value); |
| 1037 | entries.add(entry); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | } catch (IOException ioe) { |
| 1043 | } catch (XmlPullParserException pe) { |
| 1044 | } finally { |
| 1045 | if (fis != null) { |
| 1046 | try { |
| 1047 | fis.close(); |
| 1048 | } catch (IOException e) { |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | return entries; |
| 1053 | } |
| 1054 | |
| 1055 | private void writeApplicationRestrictionsLocked(String packageName, |
| 1056 | List<RestrictionEntry> entries, int userId) { |
| 1057 | FileOutputStream fos = null; |
| 1058 | AtomicFile restrictionsFile = new AtomicFile( |
| 1059 | new File(Environment.getUserSystemDirectory(userId), |
| 1060 | RESTRICTIONS_FILE_PREFIX + packageName + ".xml")); |
| 1061 | try { |
| 1062 | fos = restrictionsFile.startWrite(); |
| 1063 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 1064 | |
| 1065 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 1066 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 1067 | serializer.setOutput(bos, "utf-8"); |
| 1068 | serializer.startDocument(null, true); |
| 1069 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 1070 | |
| 1071 | serializer.startTag(null, TAG_RESTRICTIONS); |
| 1072 | |
| 1073 | for (RestrictionEntry entry : entries) { |
| 1074 | serializer.startTag(null, TAG_ENTRY); |
| 1075 | serializer.attribute(null, ATTR_KEY, entry.key); |
| 1076 | if (entry.getStringValue() != null || entry.getMultipleValues() == null) { |
| 1077 | String value = entry.getStringValue(); |
| 1078 | serializer.text(value != null ? value : ""); |
| 1079 | } else { |
| 1080 | String[] values = entry.getMultipleValues(); |
| 1081 | serializer.attribute(null, ATTR_MULTIPLE, Integer.toString(values.length)); |
| 1082 | for (String value : values) { |
| 1083 | serializer.startTag(null, TAG_VALUE); |
| 1084 | serializer.text(value != null ? value : ""); |
| 1085 | serializer.endTag(null, TAG_VALUE); |
| 1086 | } |
| 1087 | } |
| 1088 | serializer.endTag(null, TAG_ENTRY); |
| 1089 | } |
| 1090 | |
| 1091 | serializer.endTag(null, TAG_RESTRICTIONS); |
| 1092 | |
| 1093 | serializer.endDocument(); |
| 1094 | restrictionsFile.finishWrite(fos); |
| 1095 | } catch (Exception e) { |
| 1096 | restrictionsFile.failWrite(fos); |
| 1097 | Slog.e(LOG_TAG, "Error writing application restrictions list"); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | @Override |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1102 | public int getUserSerialNumber(int userHandle) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1103 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1104 | if (!exists(userHandle)) return -1; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1105 | return getUserInfoLocked(userHandle).serialNumber; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | @Override |
| 1110 | public int getUserHandle(int userSerialNumber) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1111 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1112 | for (int userId : mUserIds) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1113 | if (getUserInfoLocked(userId).serialNumber == userSerialNumber) return userId; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 1114 | } |
| 1115 | // Not found |
| 1116 | return -1; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1120 | /** |
| 1121 | * Caches the list of user ids in an array, adjusting the array size when necessary. |
| 1122 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1123 | private void updateUserIdsLocked() { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1124 | int num = 0; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1125 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1126 | if (!mUsers.valueAt(i).partial) { |
| 1127 | num++; |
| 1128 | } |
| 1129 | } |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1130 | final int[] newUsers = new int[num]; |
| 1131 | int n = 0; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1132 | for (int i = 0; i < mUsers.size(); i++) { |
| 1133 | if (!mUsers.valueAt(i).partial) { |
Amith Yamasani | 1638931 | 2012-10-17 21:20:14 -0700 | [diff] [blame] | 1134 | newUsers[n++] = mUsers.keyAt(i); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1135 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1136 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1137 | mUserIds = newUsers; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1141 | * Make a note of the last started time of a user. |
| 1142 | * @param userId the user that was just foregrounded |
| 1143 | */ |
| 1144 | public void userForeground(int userId) { |
| 1145 | synchronized (mPackagesLock) { |
| 1146 | UserInfo user = mUsers.get(userId); |
| 1147 | long now = System.currentTimeMillis(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1148 | if (user == null || user.partial) { |
| 1149 | Slog.w(LOG_TAG, "userForeground: unknown user #" + userId); |
| 1150 | return; |
| 1151 | } |
| 1152 | if (now > EPOCH_PLUS_30_YEARS) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1153 | user.lastLoggedInTime = now; |
| 1154 | writeUserLocked(user); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | /** |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1160 | * 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] | 1161 | * TODO: May not be a good idea to recycle ids, in case it results in confusion |
| 1162 | * for data and battery stats collection, or unexpected cross-talk. |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 1163 | * @return |
| 1164 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1165 | private int getNextAvailableIdLocked() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 1166 | synchronized (mPackagesLock) { |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1167 | int i = MIN_USER_ID; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1168 | while (i < Integer.MAX_VALUE) { |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1169 | if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.get(i)) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | } |
| 1172 | i++; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1173 | } |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 1174 | return i; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1175 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1176 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1177 | |
| 1178 | @Override |
| 1179 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1180 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1181 | != PackageManager.PERMISSION_GRANTED) { |
| 1182 | pw.println("Permission Denial: can't dump UserManager from from pid=" |
| 1183 | + Binder.getCallingPid() |
| 1184 | + ", uid=" + Binder.getCallingUid() |
| 1185 | + " without permission " |
| 1186 | + android.Manifest.permission.DUMP); |
| 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | long now = System.currentTimeMillis(); |
| 1191 | StringBuilder sb = new StringBuilder(); |
| 1192 | synchronized (mPackagesLock) { |
| 1193 | pw.println("Users:"); |
| 1194 | for (int i = 0; i < mUsers.size(); i++) { |
| 1195 | UserInfo user = mUsers.valueAt(i); |
| 1196 | if (user == null) continue; |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 1197 | pw.print(" "); pw.print(user); pw.print(" serialNo="); pw.print(user.serialNumber); |
Jeff Sharkey | ffe0cb4 | 2012-11-05 17:24:43 -0800 | [diff] [blame] | 1198 | if (mRemovingUserIds.get(mUsers.keyAt(i))) pw.print(" <removing> "); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 1199 | if (user.partial) pw.print(" <partial>"); |
| 1200 | pw.println(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 1201 | pw.print(" Created: "); |
| 1202 | if (user.creationTime == 0) { |
| 1203 | pw.println("<unknown>"); |
| 1204 | } else { |
| 1205 | sb.setLength(0); |
| 1206 | TimeUtils.formatDuration(now - user.creationTime, sb); |
| 1207 | sb.append(" ago"); |
| 1208 | pw.println(sb); |
| 1209 | } |
| 1210 | pw.print(" Last logged in: "); |
| 1211 | if (user.lastLoggedInTime == 0) { |
| 1212 | pw.println("<unknown>"); |
| 1213 | } else { |
| 1214 | sb.setLength(0); |
| 1215 | TimeUtils.formatDuration(now - user.lastLoggedInTime, sb); |
| 1216 | sb.append(" ago"); |
| 1217 | pw.println(sb); |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1222 | } |