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 | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 19 | import static android.os.ParcelFileDescriptor.MODE_CREATE; |
| 20 | import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; |
| 21 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 22 | import com.android.internal.util.ArrayUtils; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 23 | import com.android.internal.util.FastXmlSerializer; |
| 24 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
| 29 | import android.content.pm.PackageManager; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 30 | import android.content.pm.UserInfo; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 31 | import android.os.Binder; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 32 | import android.os.Environment; |
| 33 | import android.os.FileUtils; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 34 | import android.os.IUserManager; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 35 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 36 | import android.os.Process; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 37 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 38 | import android.os.UserHandle; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 39 | import android.util.AtomicFile; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 41 | import android.util.Slog; |
| 42 | import android.util.SparseArray; |
| 43 | import android.util.Xml; |
| 44 | |
| 45 | import java.io.BufferedOutputStream; |
| 46 | import java.io.File; |
| 47 | import java.io.FileInputStream; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 48 | import java.io.FileNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 49 | import java.io.FileOutputStream; |
| 50 | import java.io.IOException; |
| 51 | import java.util.ArrayList; |
| 52 | import java.util.List; |
| 53 | |
| 54 | import org.xmlpull.v1.XmlPullParser; |
| 55 | import org.xmlpull.v1.XmlPullParserException; |
| 56 | import org.xmlpull.v1.XmlSerializer; |
| 57 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 58 | public class UserManagerService extends IUserManager.Stub { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 59 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 60 | private static final String LOG_TAG = "UserManagerService"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 61 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 62 | private static final String TAG_NAME = "name"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 63 | private static final String ATTR_FLAGS = "flags"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 64 | private static final String ATTR_ICON_PATH = "icon"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 65 | private static final String ATTR_ID = "id"; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 66 | private static final String ATTR_SERIAL_NO = "serialNumber"; |
| 67 | private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 68 | private static final String TAG_USERS = "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 69 | private static final String TAG_USER = "user"; |
| 70 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 71 | private static final String USER_INFO_DIR = "system" + File.separator + "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 72 | private static final String USER_LIST_FILENAME = "userlist.xml"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 73 | private static final String USER_PHOTO_FILENAME = "photo.png"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 74 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 75 | private SparseArray<UserInfo> mUsers = new SparseArray<UserInfo>(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 76 | |
| 77 | private final File mUsersDir; |
| 78 | private final File mUserListFile; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 79 | private int[] mUserIds; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 80 | private boolean mGuestEnabled; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 81 | private int mNextSerialNumber; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 82 | |
| 83 | private Installer mInstaller; |
| 84 | private File mBaseUserPath; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 85 | private Context mContext; |
| 86 | private static UserManagerService sInstance; |
| 87 | private PackageManagerService mPm; |
| 88 | |
| 89 | public synchronized static UserManagerService getInstance(Context context) { |
| 90 | if (sInstance == null) { |
| 91 | sInstance = new UserManagerService(context); |
| 92 | } |
| 93 | return sInstance; |
| 94 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Available for testing purposes. |
| 98 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 99 | UserManagerService(File dataDir, File baseUserPath) { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 100 | mUsersDir = new File(dataDir, USER_INFO_DIR); |
| 101 | mUsersDir.mkdirs(); |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 102 | // Make zeroth user directory, for services to migrate their files to that location |
| 103 | File userZeroDir = new File(mUsersDir, "0"); |
| 104 | userZeroDir.mkdirs(); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 105 | mBaseUserPath = baseUserPath; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 106 | FileUtils.setPermissions(mUsersDir.toString(), |
| 107 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 108 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 109 | -1, -1); |
| 110 | mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); |
| 111 | readUserList(); |
| 112 | } |
| 113 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 114 | public UserManagerService(Context context) { |
| 115 | this(Environment.getDataDirectory(), new File(Environment.getDataDirectory(), "user")); |
| 116 | mContext = context; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 119 | void setInstaller(PackageManagerService pm, Installer installer) { |
| 120 | mInstaller = installer; |
| 121 | mPm = pm; |
| 122 | } |
| 123 | |
| 124 | @Override |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 125 | public List<UserInfo> getUsers() { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 126 | checkManageUsersPermission("query users"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 127 | synchronized (mUsers) { |
| 128 | ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); |
| 129 | for (int i = 0; i < mUsers.size(); i++) { |
| 130 | users.add(mUsers.valueAt(i)); |
| 131 | } |
| 132 | return users; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 133 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 136 | @Override |
| 137 | public UserInfo getUserInfo(int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 138 | checkManageUsersPermission("query user"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 139 | synchronized (mUsers) { |
| 140 | UserInfo info = mUsers.get(userId); |
| 141 | return info; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | public boolean exists(int userId) { |
| 146 | synchronized (mUsers) { |
| 147 | return ArrayUtils.contains(mUserIds, userId); |
| 148 | } |
| 149 | } |
| 150 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 151 | @Override |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 152 | public void setUserName(int userId, String name) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 153 | checkManageUsersPermission("rename users"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 154 | synchronized (mUsers) { |
| 155 | UserInfo info = mUsers.get(userId); |
| 156 | if (name != null && !name.equals(info.name)) { |
| 157 | info.name = name; |
| 158 | writeUserLocked(info); |
| 159 | } |
| 160 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 163 | @Override |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 164 | public ParcelFileDescriptor setUserIcon(int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 165 | checkManageUsersPermission("update users"); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 166 | synchronized (mUsers) { |
| 167 | UserInfo info = mUsers.get(userId); |
| 168 | if (info == null) return null; |
| 169 | ParcelFileDescriptor fd = updateIconBitmapLocked(info); |
| 170 | if (fd != null) { |
| 171 | writeUserLocked(info); |
| 172 | } |
| 173 | return fd; |
| 174 | } |
| 175 | } |
| 176 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 177 | @Override |
| 178 | public void setGuestEnabled(boolean enable) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 179 | checkManageUsersPermission("enable guest users"); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 180 | synchronized (mUsers) { |
| 181 | if (mGuestEnabled != enable) { |
| 182 | mGuestEnabled = enable; |
| 183 | // Erase any guest user that currently exists |
| 184 | for (int i = 0; i < mUsers.size(); i++) { |
| 185 | UserInfo user = mUsers.valueAt(i); |
| 186 | if (user.isGuest()) { |
| 187 | if (!enable) { |
| 188 | removeUser(user.id); |
| 189 | } |
| 190 | return; |
| 191 | } |
| 192 | } |
| 193 | // No guest was found |
| 194 | if (enable) { |
| 195 | createUser("Guest", UserInfo.FLAG_GUEST); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public boolean isGuestEnabled() { |
| 203 | synchronized (mUsers) { |
| 204 | return mGuestEnabled; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public void wipeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 210 | checkManageUsersPermission("wipe user"); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 211 | // TODO: |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Enforces that only the system UID or root's UID can call a method exposed |
| 216 | * via Binder. |
| 217 | * |
| 218 | * @param message used as message if SecurityException is thrown |
| 219 | * @throws SecurityException if the caller is not system or root |
| 220 | */ |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 221 | private static final void checkManageUsersPermission(String message) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 222 | final int uid = Binder.getCallingUid(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 223 | if (uid != Process.SYSTEM_UID && uid != 0 |
| 224 | && ActivityManager.checkComponentPermission( |
| 225 | android.Manifest.permission.MANAGE_USERS, |
| 226 | uid, -1, true) != PackageManager.PERMISSION_GRANTED) { |
| 227 | throw new SecurityException("You need MANAGE_USERS permission to: " + message); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 231 | private ParcelFileDescriptor updateIconBitmapLocked(UserInfo info) { |
| 232 | try { |
| 233 | File dir = new File(mUsersDir, Integer.toString(info.id)); |
| 234 | File file = new File(dir, USER_PHOTO_FILENAME); |
| 235 | if (!dir.exists()) { |
| 236 | dir.mkdir(); |
| 237 | FileUtils.setPermissions( |
| 238 | dir.getPath(), |
| 239 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 240 | -1, -1); |
| 241 | } |
| 242 | ParcelFileDescriptor fd = ParcelFileDescriptor.open(file, |
| 243 | MODE_CREATE|MODE_READ_WRITE); |
| 244 | info.iconPath = file.getAbsolutePath(); |
| 245 | return fd; |
| 246 | } catch (FileNotFoundException e) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 247 | Slog.w(LOG_TAG, "Error setting photo for user ", e); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 248 | } |
| 249 | return null; |
| 250 | } |
| 251 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 252 | /** |
| 253 | * Returns an array of user ids. This array is cached here for quick access, so do not modify or |
| 254 | * cache it elsewhere. |
| 255 | * @return the array of user ids. |
| 256 | */ |
| 257 | int[] getUserIds() { |
| 258 | return mUserIds; |
| 259 | } |
| 260 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 261 | private void readUserList() { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 262 | synchronized (mUsers) { |
| 263 | readUserListLocked(); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | private void readUserListLocked() { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 268 | mGuestEnabled = false; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 269 | if (!mUserListFile.exists()) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 270 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | FileInputStream fis = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 274 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 275 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 276 | fis = userListFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 277 | XmlPullParser parser = Xml.newPullParser(); |
| 278 | parser.setInput(fis, null); |
| 279 | int type; |
| 280 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 281 | && type != XmlPullParser.END_DOCUMENT) { |
| 282 | ; |
| 283 | } |
| 284 | |
| 285 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 286 | Slog.e(LOG_TAG, "Unable to read user list"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 287 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 291 | mNextSerialNumber = -1; |
| 292 | if (parser.getName().equals(TAG_USERS)) { |
| 293 | String lastSerialNumber = parser.getAttributeValue(null, ATTR_NEXT_SERIAL_NO); |
| 294 | if (lastSerialNumber != null) { |
| 295 | mNextSerialNumber = Integer.parseInt(lastSerialNumber); |
| 296 | } |
| 297 | } |
| 298 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 299 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 300 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
| 301 | String id = parser.getAttributeValue(null, ATTR_ID); |
| 302 | UserInfo user = readUser(Integer.parseInt(id)); |
| 303 | if (user != null) { |
| 304 | mUsers.put(user.id, user); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 305 | if (user.isGuest()) { |
| 306 | mGuestEnabled = true; |
| 307 | } |
| 308 | if (mNextSerialNumber < 0 || mNextSerialNumber <= user.id) { |
| 309 | mNextSerialNumber = user.id + 1; |
| 310 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 311 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 314 | updateUserIdsLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 315 | } catch (IOException ioe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 316 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 317 | } catch (XmlPullParserException pe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 318 | fallbackToSingleUserLocked(); |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 319 | } finally { |
| 320 | if (fis != null) { |
| 321 | try { |
| 322 | fis.close(); |
| 323 | } catch (IOException e) { |
| 324 | } |
| 325 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 329 | private void fallbackToSingleUserLocked() { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 330 | // Create the primary user |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 331 | UserInfo primary = new UserInfo(0, "Primary", null, |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 332 | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY); |
| 333 | mUsers.put(0, primary); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 334 | updateUserIdsLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 335 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 336 | writeUserListLocked(); |
| 337 | writeUserLocked(primary); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* |
| 341 | * Writes the user file in this format: |
| 342 | * |
| 343 | * <user flags="20039023" id="0"> |
| 344 | * <name>Primary</name> |
| 345 | * </user> |
| 346 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 347 | private void writeUserLocked(UserInfo userInfo) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 348 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 349 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 350 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 351 | fos = userFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 352 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 353 | |
| 354 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 355 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 356 | serializer.setOutput(bos, "utf-8"); |
| 357 | serializer.startDocument(null, true); |
| 358 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 359 | |
| 360 | serializer.startTag(null, TAG_USER); |
| 361 | serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id)); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 362 | serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 363 | serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags)); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 364 | if (userInfo.iconPath != null) { |
| 365 | serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); |
| 366 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 367 | |
| 368 | serializer.startTag(null, TAG_NAME); |
| 369 | serializer.text(userInfo.name); |
| 370 | serializer.endTag(null, TAG_NAME); |
| 371 | |
| 372 | serializer.endTag(null, TAG_USER); |
| 373 | |
| 374 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 375 | userFile.finishWrite(fos); |
| 376 | } catch (Exception ioe) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 377 | Slog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 378 | userFile.failWrite(fos); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Writes the user list file in this format: |
| 384 | * |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 385 | * <users nextSerialNumber="3"> |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 386 | * <user id="0"></user> |
| 387 | * <user id="2"></user> |
| 388 | * </users> |
| 389 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 390 | private void writeUserListLocked() { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 391 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 392 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 393 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 394 | fos = userListFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 395 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 396 | |
| 397 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 398 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 399 | serializer.setOutput(bos, "utf-8"); |
| 400 | serializer.startDocument(null, true); |
| 401 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 402 | |
| 403 | serializer.startTag(null, TAG_USERS); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 404 | serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 405 | |
| 406 | for (int i = 0; i < mUsers.size(); i++) { |
| 407 | UserInfo user = mUsers.valueAt(i); |
| 408 | serializer.startTag(null, TAG_USER); |
| 409 | serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); |
| 410 | serializer.endTag(null, TAG_USER); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | serializer.endTag(null, TAG_USERS); |
| 414 | |
| 415 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 416 | userListFile.finishWrite(fos); |
| 417 | } catch (Exception e) { |
| 418 | userListFile.failWrite(fos); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 419 | Slog.e(LOG_TAG, "Error writing user list"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | private UserInfo readUser(int id) { |
| 424 | int flags = 0; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 425 | int serialNumber = id; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 426 | String name = null; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 427 | String iconPath = null; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 428 | |
| 429 | FileInputStream fis = null; |
| 430 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 431 | AtomicFile userFile = |
| 432 | new AtomicFile(new File(mUsersDir, Integer.toString(id) + ".xml")); |
| 433 | fis = userFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 434 | XmlPullParser parser = Xml.newPullParser(); |
| 435 | parser.setInput(fis, null); |
| 436 | int type; |
| 437 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 438 | && type != XmlPullParser.END_DOCUMENT) { |
| 439 | ; |
| 440 | } |
| 441 | |
| 442 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 443 | Slog.e(LOG_TAG, "Unable to read user " + id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 444 | return null; |
| 445 | } |
| 446 | |
| 447 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
| 448 | String storedId = parser.getAttributeValue(null, ATTR_ID); |
| 449 | if (Integer.parseInt(storedId) != id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 450 | Slog.e(LOG_TAG, "User id does not match the file name"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 451 | return null; |
| 452 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 453 | String serialNumberValue = parser.getAttributeValue(null, ATTR_SERIAL_NO); |
| 454 | if (serialNumberValue != null) { |
| 455 | serialNumber = Integer.parseInt(serialNumberValue); |
| 456 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 457 | String flagString = parser.getAttributeValue(null, ATTR_FLAGS); |
| 458 | flags = Integer.parseInt(flagString); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 459 | iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 460 | |
| 461 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 462 | && type != XmlPullParser.END_DOCUMENT) { |
| 463 | } |
| 464 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_NAME)) { |
| 465 | type = parser.next(); |
| 466 | if (type == XmlPullParser.TEXT) { |
| 467 | name = parser.getText(); |
| 468 | } |
| 469 | } |
| 470 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 471 | |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 472 | UserInfo userInfo = new UserInfo(id, name, iconPath, flags); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 473 | userInfo.serialNumber = serialNumber; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 474 | return userInfo; |
| 475 | |
| 476 | } catch (IOException ioe) { |
| 477 | } catch (XmlPullParserException pe) { |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 478 | } finally { |
| 479 | if (fis != null) { |
| 480 | try { |
| 481 | fis.close(); |
| 482 | } catch (IOException e) { |
| 483 | } |
| 484 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 485 | } |
| 486 | return null; |
| 487 | } |
| 488 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 489 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 490 | public UserInfo createUser(String name, int flags) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 491 | checkManageUsersPermission("Only the system can create users"); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 492 | int userId = getNextAvailableId(); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 493 | UserInfo userInfo = new UserInfo(userId, name, null, flags); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 494 | File userPath = new File(mBaseUserPath, Integer.toString(userId)); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 495 | if (!createPackageFolders(userId, userPath)) { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 496 | return null; |
| 497 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 498 | synchronized (mUsers) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 499 | userInfo.serialNumber = mNextSerialNumber++; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 500 | mUsers.put(userId, userInfo); |
| 501 | writeUserListLocked(); |
| 502 | writeUserLocked(userInfo); |
| 503 | updateUserIdsLocked(); |
| 504 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 505 | if (userInfo != null) { |
| 506 | Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 507 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id); |
| 508 | mContext.sendBroadcast(addedIntent, android.Manifest.permission.MANAGE_USERS); |
Amith Yamasani | fc6e0ca | 2012-08-17 17:07:14 -0700 | [diff] [blame] | 509 | mContext.sendBroadcastAsUser(new Intent(Intent.ACTION_BOOT_COMPLETED), |
| 510 | new UserHandle(userInfo.id)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 511 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 512 | return userInfo; |
| 513 | } |
| 514 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 515 | /** |
| 516 | * Removes a user and all data directories created for that user. This method should be called |
| 517 | * after the user's processes have been terminated. |
| 518 | * @param id the user's id |
| 519 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 520 | public boolean removeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 521 | checkManageUsersPermission("Only the system can remove users"); |
| 522 | boolean result; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 523 | synchronized (mUsers) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 524 | result = removeUserLocked(userHandle); |
| 525 | } |
| 526 | // Let other services shutdown any activity |
| 527 | Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED); |
| 528 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); |
| 529 | mContext.sendBroadcast(addedIntent, android.Manifest.permission.MANAGE_USERS); |
| 530 | return result; |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public int getUserSerialNumber(int userHandle) { |
| 535 | synchronized (mUsers) { |
| 536 | if (!exists(userHandle)) return -1; |
| 537 | return getUserInfo(userHandle).serialNumber; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | @Override |
| 542 | public int getUserHandle(int userSerialNumber) { |
| 543 | synchronized (mUsers) { |
| 544 | for (int userId : mUserIds) { |
| 545 | if (getUserInfo(userId).serialNumber == userSerialNumber) return userId; |
| 546 | } |
| 547 | // Not found |
| 548 | return -1; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 552 | private boolean removeUserLocked(int userHandle) { |
| 553 | final UserInfo user = mUsers.get(userHandle); |
| 554 | if (userHandle == 0 || user == null) { |
| 555 | return false; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 556 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 557 | |
| 558 | mPm.cleanUpUser(userHandle); |
| 559 | |
| 560 | // Remove this user from the list |
| 561 | mUsers.remove(userHandle); |
| 562 | // Remove user file |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 563 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 564 | userFile.delete(); |
| 565 | // Update the user list |
| 566 | writeUserListLocked(); |
| 567 | updateUserIdsLocked(); |
| 568 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 569 | removePackageFolders(userHandle); |
| 570 | return true; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 573 | public void installPackageForAllUsers(String packageName, int uid) { |
| 574 | for (int userId : mUserIds) { |
| 575 | // Don't do it for the primary user, it will become recursive. |
| 576 | if (userId == 0) |
| 577 | continue; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 578 | mInstaller.createUserData(packageName, UserHandle.getUid(userId, uid), |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 579 | userId); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | public void clearUserDataForAllUsers(String packageName) { |
| 584 | for (int userId : mUserIds) { |
| 585 | // Don't do it for the primary user, it will become recursive. |
| 586 | if (userId == 0) |
| 587 | continue; |
| 588 | mInstaller.clearUserData(packageName, userId); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | public void removePackageForAllUsers(String packageName) { |
| 593 | for (int userId : mUserIds) { |
| 594 | // Don't do it for the primary user, it will become recursive. |
| 595 | if (userId == 0) |
| 596 | continue; |
| 597 | mInstaller.remove(packageName, userId); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Caches the list of user ids in an array, adjusting the array size when necessary. |
| 603 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 604 | private void updateUserIdsLocked() { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 605 | if (mUserIds == null || mUserIds.length != mUsers.size()) { |
| 606 | mUserIds = new int[mUsers.size()]; |
| 607 | } |
| 608 | for (int i = 0; i < mUsers.size(); i++) { |
| 609 | mUserIds[i] = mUsers.keyAt(i); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * 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] | 615 | * TODO: May not be a good idea to recycle ids, in case it results in confusion |
| 616 | * for data and battery stats collection, or unexpected cross-talk. |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 617 | * @return |
| 618 | */ |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 619 | private int getNextAvailableId() { |
| 620 | int i = 0; |
| 621 | while (i < Integer.MAX_VALUE) { |
| 622 | if (mUsers.indexOfKey(i) < 0) { |
| 623 | break; |
| 624 | } |
| 625 | i++; |
| 626 | } |
| 627 | return i; |
| 628 | } |
| 629 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 630 | private boolean createPackageFolders(int id, File userPath) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 631 | // mInstaller may not be available for unit-tests. |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 632 | if (mInstaller == null) return true; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 633 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 634 | // Create the user path |
| 635 | userPath.mkdir(); |
| 636 | FileUtils.setPermissions(userPath.toString(), FileUtils.S_IRWXU | FileUtils.S_IRWXG |
| 637 | | FileUtils.S_IXOTH, -1, -1); |
| 638 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 639 | mInstaller.cloneUserData(0, id, false); |
| 640 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 641 | return true; |
| 642 | } |
| 643 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 644 | boolean removePackageFolders(int id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 645 | // mInstaller may not be available for unit-tests. |
| 646 | if (mInstaller == null) return true; |
| 647 | |
| 648 | mInstaller.removeUserDataDirs(id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 649 | return true; |
| 650 | } |
| 651 | } |