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 | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 19 | import com.android.internal.util.ArrayUtils; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 20 | import com.android.internal.util.FastXmlSerializer; |
| 21 | |
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 | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 28 | import android.content.pm.UserInfo; |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
| 30 | import android.graphics.BitmapFactory; |
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 | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 35 | import android.os.Process; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 36 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 38 | import android.os.UserManager; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 39 | import android.util.AtomicFile; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 40 | import android.util.Slog; |
| 41 | import android.util.SparseArray; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 42 | import android.util.TimeUtils; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 43 | import android.util.Xml; |
| 44 | |
| 45 | import java.io.BufferedOutputStream; |
| 46 | import java.io.File; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 47 | import java.io.FileDescriptor; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 48 | import java.io.FileInputStream; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 49 | import java.io.FileNotFoundException; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 50 | import java.io.FileOutputStream; |
| 51 | import java.io.IOException; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 52 | import java.io.PrintWriter; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 53 | import java.util.ArrayList; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 54 | import java.util.HashSet; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 55 | import java.util.List; |
| 56 | |
| 57 | import org.xmlpull.v1.XmlPullParser; |
| 58 | import org.xmlpull.v1.XmlPullParserException; |
| 59 | import org.xmlpull.v1.XmlSerializer; |
| 60 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 61 | public class UserManagerService extends IUserManager.Stub { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 62 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 63 | private static final String LOG_TAG = "UserManagerService"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 64 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 65 | private static final String TAG_NAME = "name"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 66 | private static final String ATTR_FLAGS = "flags"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 67 | private static final String ATTR_ICON_PATH = "icon"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 68 | private static final String ATTR_ID = "id"; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 69 | private static final String ATTR_CREATION_TIME = "created"; |
| 70 | private static final String ATTR_LAST_LOGGED_IN_TIME = "lastLoggedIn"; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 71 | private static final String ATTR_SERIAL_NO = "serialNumber"; |
| 72 | private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 73 | private static final String ATTR_PARTIAL = "partial"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 74 | private static final String TAG_USERS = "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 75 | private static final String TAG_USER = "user"; |
| 76 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 77 | private static final String USER_INFO_DIR = "system" + File.separator + "users"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 78 | private static final String USER_LIST_FILENAME = "userlist.xml"; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 79 | private static final String USER_PHOTO_FILENAME = "photo.png"; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 80 | |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 81 | private static final int MIN_USER_ID = 10; |
| 82 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 83 | private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms |
| 84 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 85 | private final Context mContext; |
| 86 | private final PackageManagerService mPm; |
| 87 | private final Object mInstallLock; |
| 88 | private final Object mPackagesLock; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 89 | |
| 90 | private final File mUsersDir; |
| 91 | private final File mUserListFile; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 92 | private final File mBaseUserPath; |
| 93 | |
| 94 | private SparseArray<UserInfo> mUsers = new SparseArray<UserInfo>(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 95 | private HashSet<Integer> mRemovingUserIds = new HashSet<Integer>(); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 96 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 97 | private int[] mUserIds; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 98 | private boolean mGuestEnabled; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 99 | private int mNextSerialNumber; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 100 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 101 | private static UserManagerService sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 102 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 103 | public static UserManagerService getInstance() { |
| 104 | synchronized (UserManagerService.class) { |
| 105 | return sInstance; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 106 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 107 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Available for testing purposes. |
| 111 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 112 | UserManagerService(File dataDir, File baseUserPath) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 113 | this(null, null, new Object(), new Object(), dataDir, baseUserPath); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Called by package manager to create the service. This is closely |
| 118 | * associated with the package manager, and the given lock is the |
| 119 | * package manager's own lock. |
| 120 | */ |
| 121 | UserManagerService(Context context, PackageManagerService pm, |
| 122 | Object installLock, Object packagesLock) { |
| 123 | this(context, pm, installLock, packagesLock, |
| 124 | Environment.getDataDirectory(), |
| 125 | new File(Environment.getDataDirectory(), "user")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Available for testing purposes. |
| 130 | */ |
| 131 | private UserManagerService(Context context, PackageManagerService pm, |
| 132 | Object installLock, Object packagesLock, |
| 133 | File dataDir, File baseUserPath) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 134 | mContext = context; |
| 135 | mPm = pm; |
| 136 | mInstallLock = installLock; |
| 137 | mPackagesLock = packagesLock; |
| 138 | synchronized (mInstallLock) { |
| 139 | synchronized (mPackagesLock) { |
| 140 | mUsersDir = new File(dataDir, USER_INFO_DIR); |
| 141 | mUsersDir.mkdirs(); |
| 142 | // Make zeroth user directory, for services to migrate their files to that location |
| 143 | File userZeroDir = new File(mUsersDir, "0"); |
| 144 | userZeroDir.mkdirs(); |
| 145 | mBaseUserPath = baseUserPath; |
| 146 | FileUtils.setPermissions(mUsersDir.toString(), |
| 147 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 148 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 149 | -1, -1); |
| 150 | mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); |
| 151 | readUserListLocked(); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame^] | 152 | // Prune out any partially created/partially removed users. |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 153 | ArrayList<UserInfo> partials = new ArrayList<UserInfo>(); |
| 154 | for (int i = 0; i < mUsers.size(); i++) { |
| 155 | UserInfo ui = mUsers.valueAt(i); |
| 156 | if (ui.partial && i != 0) { |
| 157 | partials.add(ui); |
| 158 | } |
| 159 | } |
| 160 | for (int i = 0; i < partials.size(); i++) { |
| 161 | UserInfo ui = partials.get(i); |
| 162 | Slog.w(LOG_TAG, "Removing partially created user #" + i |
| 163 | + " (name=" + ui.name + ")"); |
| 164 | removeUserStateLocked(ui.id); |
| 165 | } |
| 166 | sInstance = this; |
| 167 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 168 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @Override |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 172 | public List<UserInfo> getUsers(boolean excludeDying) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 173 | checkManageUsersPermission("query users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 174 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 175 | ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); |
| 176 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 177 | UserInfo ui = mUsers.valueAt(i); |
| 178 | if (ui.partial) { |
| 179 | continue; |
| 180 | } |
| 181 | if (!excludeDying || !mRemovingUserIds.contains(ui.id)) { |
| 182 | users.add(ui); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 183 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 184 | } |
| 185 | return users; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 186 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 189 | @Override |
| 190 | public UserInfo getUserInfo(int userId) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 191 | checkManageUsersPermission("query user"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 192 | synchronized (mPackagesLock) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 193 | return getUserInfoLocked(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 197 | /* |
| 198 | * Should be locked on mUsers before calling this. |
| 199 | */ |
| 200 | private UserInfo getUserInfoLocked(int userId) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 201 | UserInfo ui = mUsers.get(userId); |
| 202 | if (ui != null && ui.partial) { |
| 203 | Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId); |
| 204 | return null; |
| 205 | } |
| 206 | return ui; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 209 | public boolean exists(int userId) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 210 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 211 | return ArrayUtils.contains(mUserIds, userId); |
| 212 | } |
| 213 | } |
| 214 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 215 | @Override |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 216 | public void setUserName(int userId, String name) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 217 | checkManageUsersPermission("rename users"); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 218 | boolean changed = false; |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 219 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 220 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 221 | if (info == null || info.partial) { |
| 222 | Slog.w(LOG_TAG, "setUserName: unknown user #" + userId); |
| 223 | return; |
| 224 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 225 | if (name != null && !name.equals(info.name)) { |
| 226 | info.name = name; |
| 227 | writeUserLocked(info); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 228 | changed = true; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 231 | if (changed) { |
| 232 | sendUserInfoChangedBroadcast(userId); |
| 233 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 236 | @Override |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 237 | public void setUserIcon(int userId, Bitmap bitmap) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 238 | checkManageUsersPermission("update users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 239 | synchronized (mPackagesLock) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 240 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 241 | if (info == null || info.partial) { |
| 242 | Slog.w(LOG_TAG, "setUserIcon: unknown user #" + userId); |
| 243 | return; |
| 244 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 245 | writeBitmapLocked(info, bitmap); |
| 246 | writeUserLocked(info); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 247 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 248 | sendUserInfoChangedBroadcast(userId); |
| 249 | } |
| 250 | |
| 251 | private void sendUserInfoChangedBroadcast(int userId) { |
| 252 | Intent changedIntent = new Intent(Intent.ACTION_USER_INFO_CHANGED); |
| 253 | changedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); |
| 254 | changedIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 255 | mContext.sendBroadcastAsUser(changedIntent, new UserHandle(userId)); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 258 | @Override |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 259 | public Bitmap getUserIcon(int userId) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 260 | checkManageUsersPermission("read users"); |
| 261 | synchronized (mPackagesLock) { |
| 262 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 263 | if (info == null || info.partial) { |
| 264 | Slog.w(LOG_TAG, "getUserIcon: unknown user #" + userId); |
| 265 | return null; |
| 266 | } |
| 267 | if (info.iconPath == null) { |
| 268 | return null; |
| 269 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 270 | return BitmapFactory.decodeFile(info.iconPath); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | @Override |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 275 | public void setGuestEnabled(boolean enable) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 276 | checkManageUsersPermission("enable guest users"); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 277 | synchronized (mPackagesLock) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 278 | if (mGuestEnabled != enable) { |
| 279 | mGuestEnabled = enable; |
| 280 | // Erase any guest user that currently exists |
| 281 | for (int i = 0; i < mUsers.size(); i++) { |
| 282 | UserInfo user = mUsers.valueAt(i); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 283 | if (!user.partial && user.isGuest()) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 284 | if (!enable) { |
| 285 | removeUser(user.id); |
| 286 | } |
| 287 | return; |
| 288 | } |
| 289 | } |
| 290 | // No guest was found |
| 291 | if (enable) { |
| 292 | createUser("Guest", UserInfo.FLAG_GUEST); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public boolean isGuestEnabled() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 300 | synchronized (mPackagesLock) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 301 | return mGuestEnabled; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public void wipeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 307 | checkManageUsersPermission("wipe user"); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 308 | // TODO: |
| 309 | } |
| 310 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 311 | public void makeInitialized(int userId) { |
| 312 | checkManageUsersPermission("makeInitialized"); |
| 313 | synchronized (mPackagesLock) { |
| 314 | UserInfo info = mUsers.get(userId); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 315 | if (info == null || info.partial) { |
| 316 | Slog.w(LOG_TAG, "makeInitialized: unknown user #" + userId); |
| 317 | } |
| 318 | if ((info.flags&UserInfo.FLAG_INITIALIZED) == 0) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 319 | info.flags |= UserInfo.FLAG_INITIALIZED; |
| 320 | writeUserLocked(info); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 325 | /** |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 326 | * Check if we've hit the limit of how many users can be created. |
| 327 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 328 | private boolean isUserLimitReachedLocked() { |
| 329 | int nUsers = mUsers.size(); |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 330 | return nUsers >= UserManager.getMaxSupportedUsers(); |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 334 | * Enforces that only the system UID or root's UID or apps that have the |
| 335 | * {@link android.Manifest.permission.MANAGE_USERS MANAGE_USERS} |
| 336 | * permission can make certain calls to the UserManager. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 337 | * |
| 338 | * @param message used as message if SecurityException is thrown |
| 339 | * @throws SecurityException if the caller is not system or root |
| 340 | */ |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 341 | private static final void checkManageUsersPermission(String message) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 342 | final int uid = Binder.getCallingUid(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 343 | if (uid != Process.SYSTEM_UID && uid != 0 |
| 344 | && ActivityManager.checkComponentPermission( |
| 345 | android.Manifest.permission.MANAGE_USERS, |
| 346 | uid, -1, true) != PackageManager.PERMISSION_GRANTED) { |
| 347 | throw new SecurityException("You need MANAGE_USERS permission to: " + message); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 351 | private void writeBitmapLocked(UserInfo info, Bitmap bitmap) { |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 352 | try { |
| 353 | File dir = new File(mUsersDir, Integer.toString(info.id)); |
| 354 | File file = new File(dir, USER_PHOTO_FILENAME); |
| 355 | if (!dir.exists()) { |
| 356 | dir.mkdir(); |
| 357 | FileUtils.setPermissions( |
| 358 | dir.getPath(), |
| 359 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 360 | -1, -1); |
| 361 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 362 | FileOutputStream os; |
| 363 | if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(file))) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 364 | info.iconPath = file.getAbsolutePath(); |
| 365 | } |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 366 | try { |
| 367 | os.close(); |
| 368 | } catch (IOException ioe) { |
| 369 | // What the ... ! |
| 370 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 371 | } catch (FileNotFoundException e) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 372 | Slog.w(LOG_TAG, "Error setting photo for user ", e); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 373 | } |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Returns an array of user ids. This array is cached here for quick access, so do not modify or |
| 378 | * cache it elsewhere. |
| 379 | * @return the array of user ids. |
| 380 | */ |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 381 | public int[] getUserIds() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 382 | synchronized (mPackagesLock) { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 383 | return mUserIds; |
| 384 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 387 | int[] getUserIdsLPr() { |
| 388 | return mUserIds; |
| 389 | } |
| 390 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 391 | private void readUserList() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 392 | synchronized (mPackagesLock) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 393 | readUserListLocked(); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | private void readUserListLocked() { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 398 | mGuestEnabled = false; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 399 | if (!mUserListFile.exists()) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 400 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 401 | return; |
| 402 | } |
| 403 | FileInputStream fis = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 404 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 405 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 406 | fis = userListFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 407 | XmlPullParser parser = Xml.newPullParser(); |
| 408 | parser.setInput(fis, null); |
| 409 | int type; |
| 410 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 411 | && type != XmlPullParser.END_DOCUMENT) { |
| 412 | ; |
| 413 | } |
| 414 | |
| 415 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 416 | Slog.e(LOG_TAG, "Unable to read user list"); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 417 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 421 | mNextSerialNumber = -1; |
| 422 | if (parser.getName().equals(TAG_USERS)) { |
| 423 | String lastSerialNumber = parser.getAttributeValue(null, ATTR_NEXT_SERIAL_NO); |
| 424 | if (lastSerialNumber != null) { |
| 425 | mNextSerialNumber = Integer.parseInt(lastSerialNumber); |
| 426 | } |
| 427 | } |
| 428 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 429 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { |
| 430 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
| 431 | String id = parser.getAttributeValue(null, ATTR_ID); |
| 432 | UserInfo user = readUser(Integer.parseInt(id)); |
| 433 | if (user != null) { |
| 434 | mUsers.put(user.id, user); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 435 | if (user.isGuest()) { |
| 436 | mGuestEnabled = true; |
| 437 | } |
| 438 | if (mNextSerialNumber < 0 || mNextSerialNumber <= user.id) { |
| 439 | mNextSerialNumber = user.id + 1; |
| 440 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 441 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 444 | updateUserIdsLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 445 | } catch (IOException ioe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 446 | fallbackToSingleUserLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 447 | } catch (XmlPullParserException pe) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 448 | fallbackToSingleUserLocked(); |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 449 | } finally { |
| 450 | if (fis != null) { |
| 451 | try { |
| 452 | fis.close(); |
| 453 | } catch (IOException e) { |
| 454 | } |
| 455 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 459 | private void fallbackToSingleUserLocked() { |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 460 | // Create the primary user |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 461 | UserInfo primary = new UserInfo(0, "Primary", null, |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame^] | 462 | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY | UserInfo.FLAG_INITIALIZED); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 463 | mUsers.put(0, primary); |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 464 | mNextSerialNumber = MIN_USER_ID; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 465 | updateUserIdsLocked(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 466 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 467 | writeUserListLocked(); |
| 468 | writeUserLocked(primary); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Writes the user file in this format: |
| 473 | * |
| 474 | * <user flags="20039023" id="0"> |
| 475 | * <name>Primary</name> |
| 476 | * </user> |
| 477 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 478 | private void writeUserLocked(UserInfo userInfo) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 479 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 480 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml")); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 481 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 482 | fos = userFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 483 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 484 | |
| 485 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 486 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 487 | serializer.setOutput(bos, "utf-8"); |
| 488 | serializer.startDocument(null, true); |
| 489 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 490 | |
| 491 | serializer.startTag(null, TAG_USER); |
| 492 | serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id)); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 493 | serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 494 | serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags)); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 495 | serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime)); |
| 496 | serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME, |
| 497 | Long.toString(userInfo.lastLoggedInTime)); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 498 | if (userInfo.iconPath != null) { |
| 499 | serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); |
| 500 | } |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 501 | if (userInfo.partial) { |
| 502 | serializer.attribute(null, ATTR_PARTIAL, "true"); |
| 503 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 504 | |
| 505 | serializer.startTag(null, TAG_NAME); |
| 506 | serializer.text(userInfo.name); |
| 507 | serializer.endTag(null, TAG_NAME); |
| 508 | |
| 509 | serializer.endTag(null, TAG_USER); |
| 510 | |
| 511 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 512 | userFile.finishWrite(fos); |
| 513 | } catch (Exception ioe) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 514 | Slog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 515 | userFile.failWrite(fos); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Writes the user list file in this format: |
| 521 | * |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 522 | * <users nextSerialNumber="3"> |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 523 | * <user id="0"></user> |
| 524 | * <user id="2"></user> |
| 525 | * </users> |
| 526 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 527 | private void writeUserListLocked() { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 528 | FileOutputStream fos = null; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 529 | AtomicFile userListFile = new AtomicFile(mUserListFile); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 530 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 531 | fos = userListFile.startWrite(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 532 | final BufferedOutputStream bos = new BufferedOutputStream(fos); |
| 533 | |
| 534 | // XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 535 | final XmlSerializer serializer = new FastXmlSerializer(); |
| 536 | serializer.setOutput(bos, "utf-8"); |
| 537 | serializer.startDocument(null, true); |
| 538 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 539 | |
| 540 | serializer.startTag(null, TAG_USERS); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 541 | serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 542 | |
| 543 | for (int i = 0; i < mUsers.size(); i++) { |
| 544 | UserInfo user = mUsers.valueAt(i); |
| 545 | serializer.startTag(null, TAG_USER); |
| 546 | serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); |
| 547 | serializer.endTag(null, TAG_USER); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | serializer.endTag(null, TAG_USERS); |
| 551 | |
| 552 | serializer.endDocument(); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 553 | userListFile.finishWrite(fos); |
| 554 | } catch (Exception e) { |
| 555 | userListFile.failWrite(fos); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 556 | Slog.e(LOG_TAG, "Error writing user list"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
| 560 | private UserInfo readUser(int id) { |
| 561 | int flags = 0; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 562 | int serialNumber = id; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 563 | String name = null; |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 564 | String iconPath = null; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 565 | long creationTime = 0L; |
| 566 | long lastLoggedInTime = 0L; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 567 | boolean partial = false; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 568 | |
| 569 | FileInputStream fis = null; |
| 570 | try { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 571 | AtomicFile userFile = |
| 572 | new AtomicFile(new File(mUsersDir, Integer.toString(id) + ".xml")); |
| 573 | fis = userFile.openRead(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 574 | XmlPullParser parser = Xml.newPullParser(); |
| 575 | parser.setInput(fis, null); |
| 576 | int type; |
| 577 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 578 | && type != XmlPullParser.END_DOCUMENT) { |
| 579 | ; |
| 580 | } |
| 581 | |
| 582 | if (type != XmlPullParser.START_TAG) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 583 | Slog.e(LOG_TAG, "Unable to read user " + id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 584 | return null; |
| 585 | } |
| 586 | |
| 587 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 588 | int storedId = readIntAttribute(parser, ATTR_ID, -1); |
| 589 | if (storedId != id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 590 | Slog.e(LOG_TAG, "User id does not match the file name"); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 591 | return null; |
| 592 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 593 | serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id); |
| 594 | flags = readIntAttribute(parser, ATTR_FLAGS, 0); |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 595 | iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 596 | creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0); |
| 597 | lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 598 | String valueString = parser.getAttributeValue(null, ATTR_PARTIAL); |
| 599 | if ("true".equals(valueString)) { |
| 600 | partial = true; |
| 601 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 602 | |
| 603 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 604 | && type != XmlPullParser.END_DOCUMENT) { |
| 605 | } |
| 606 | if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_NAME)) { |
| 607 | type = parser.next(); |
| 608 | if (type == XmlPullParser.TEXT) { |
| 609 | name = parser.getText(); |
| 610 | } |
| 611 | } |
| 612 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 613 | |
Amith Yamasani | b8151ec | 2012-04-18 18:02:48 -0700 | [diff] [blame] | 614 | UserInfo userInfo = new UserInfo(id, name, iconPath, flags); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 615 | userInfo.serialNumber = serialNumber; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 616 | userInfo.creationTime = creationTime; |
| 617 | userInfo.lastLoggedInTime = lastLoggedInTime; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 618 | userInfo.partial = partial; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 619 | return userInfo; |
| 620 | |
| 621 | } catch (IOException ioe) { |
| 622 | } catch (XmlPullParserException pe) { |
Dianne Hackborn | bfd89b3 | 2011-12-15 18:22:54 -0800 | [diff] [blame] | 623 | } finally { |
| 624 | if (fis != null) { |
| 625 | try { |
| 626 | fis.close(); |
| 627 | } catch (IOException e) { |
| 628 | } |
| 629 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 630 | } |
| 631 | return null; |
| 632 | } |
| 633 | |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 634 | private int readIntAttribute(XmlPullParser parser, String attr, int defaultValue) { |
| 635 | String valueString = parser.getAttributeValue(null, attr); |
| 636 | if (valueString == null) return defaultValue; |
| 637 | try { |
| 638 | return Integer.parseInt(valueString); |
| 639 | } catch (NumberFormatException nfe) { |
| 640 | return defaultValue; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | private long readLongAttribute(XmlPullParser parser, String attr, long defaultValue) { |
| 645 | String valueString = parser.getAttributeValue(null, attr); |
| 646 | if (valueString == null) return defaultValue; |
| 647 | try { |
| 648 | return Long.parseLong(valueString); |
| 649 | } catch (NumberFormatException nfe) { |
| 650 | return defaultValue; |
| 651 | } |
| 652 | } |
| 653 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 654 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 655 | public UserInfo createUser(String name, int flags) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 656 | checkManageUsersPermission("Only the system can create users"); |
Amith Yamasani | faea76f | 2012-09-11 10:59:48 -0700 | [diff] [blame] | 657 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 658 | final long ident = Binder.clearCallingIdentity(); |
| 659 | final UserInfo userInfo; |
| 660 | try { |
| 661 | synchronized (mInstallLock) { |
| 662 | synchronized (mPackagesLock) { |
| 663 | if (isUserLimitReachedLocked()) return null; |
| 664 | int userId = getNextAvailableIdLocked(); |
| 665 | userInfo = new UserInfo(userId, name, null, flags); |
| 666 | File userPath = new File(mBaseUserPath, Integer.toString(userId)); |
| 667 | userInfo.serialNumber = mNextSerialNumber++; |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 668 | long now = System.currentTimeMillis(); |
| 669 | userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 670 | userInfo.partial = true; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 671 | mUsers.put(userId, userInfo); |
| 672 | writeUserListLocked(); |
| 673 | writeUserLocked(userInfo); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 674 | mPm.createNewUserLILPw(userId, userPath); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 675 | userInfo.partial = false; |
| 676 | writeUserLocked(userInfo); |
| 677 | updateUserIdsLocked(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 678 | } |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 679 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 680 | if (userInfo != null) { |
| 681 | Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED); |
| 682 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id); |
| 683 | mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 684 | android.Manifest.permission.MANAGE_USERS); |
| 685 | } |
| 686 | } finally { |
| 687 | Binder.restoreCallingIdentity(ident); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 688 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 689 | return userInfo; |
| 690 | } |
| 691 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 692 | /** |
| 693 | * Removes a user and all data directories created for that user. This method should be called |
| 694 | * after the user's processes have been terminated. |
| 695 | * @param id the user's id |
| 696 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 697 | public boolean removeUser(int userHandle) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 698 | checkManageUsersPermission("Only the system can remove users"); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 699 | final UserInfo user; |
| 700 | synchronized (mPackagesLock) { |
| 701 | user = mUsers.get(userHandle); |
| 702 | if (userHandle == 0 || user == null) { |
| 703 | return false; |
| 704 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 705 | mRemovingUserIds.add(userHandle); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame^] | 706 | // Set this to a partially created user, so that the user will be purged |
| 707 | // on next startup, in case the runtime stops now before stopping and |
| 708 | // removing the user completely. |
| 709 | user.partial = true; |
| 710 | writeUserLocked(user); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | int res; |
| 714 | try { |
| 715 | res = ActivityManagerNative.getDefault().stopUser(userHandle, |
| 716 | new IStopUserCallback.Stub() { |
| 717 | @Override |
| 718 | public void userStopped(int userId) { |
| 719 | finishRemoveUser(userId); |
| 720 | } |
| 721 | @Override |
| 722 | public void userStopAborted(int userId) { |
| 723 | } |
| 724 | }); |
| 725 | } catch (RemoteException e) { |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | return res == ActivityManager.USER_OP_SUCCESS; |
| 730 | } |
| 731 | |
| 732 | void finishRemoveUser(int userHandle) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 733 | synchronized (mInstallLock) { |
| 734 | synchronized (mPackagesLock) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 735 | removeUserStateLocked(userHandle); |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
Amith Yamasani | 0cd867c | 2012-08-22 16:45:47 -0700 | [diff] [blame] | 738 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 739 | // Let other services shutdown any activity |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 740 | long ident = Binder.clearCallingIdentity(); |
| 741 | try { |
| 742 | Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED); |
| 743 | addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); |
| 744 | mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, |
| 745 | android.Manifest.permission.MANAGE_USERS); |
| 746 | } finally { |
| 747 | Binder.restoreCallingIdentity(ident); |
| 748 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 751 | private void removeUserStateLocked(int userHandle) { |
| 752 | // Cleanup package manager settings |
| 753 | mPm.cleanUpUserLILPw(userHandle); |
| 754 | |
| 755 | // Remove this user from the list |
| 756 | mUsers.remove(userHandle); |
| 757 | mRemovingUserIds.remove(userHandle); |
| 758 | // Remove user file |
| 759 | AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); |
| 760 | userFile.delete(); |
| 761 | // Update the user list |
| 762 | writeUserListLocked(); |
| 763 | updateUserIdsLocked(); |
| 764 | removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle)); |
| 765 | } |
| 766 | |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 767 | private void removeDirectoryRecursive(File parent) { |
| 768 | if (parent.isDirectory()) { |
| 769 | String[] files = parent.list(); |
| 770 | for (String filename : files) { |
| 771 | File child = new File(parent, filename); |
| 772 | removeDirectoryRecursive(child); |
| 773 | } |
| 774 | } |
| 775 | parent.delete(); |
| 776 | } |
| 777 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 778 | @Override |
| 779 | public int getUserSerialNumber(int userHandle) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 780 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 781 | if (!exists(userHandle)) return -1; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 782 | return getUserInfoLocked(userHandle).serialNumber; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public int getUserHandle(int userSerialNumber) { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 788 | synchronized (mPackagesLock) { |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 789 | for (int userId : mUserIds) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 790 | if (getUserInfoLocked(userId).serialNumber == userSerialNumber) return userId; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 791 | } |
| 792 | // Not found |
| 793 | return -1; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 797 | /** |
| 798 | * Caches the list of user ids in an array, adjusting the array size when necessary. |
| 799 | */ |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 800 | private void updateUserIdsLocked() { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 801 | int num = 0; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 802 | for (int i = 0; i < mUsers.size(); i++) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 803 | if (!mUsers.valueAt(i).partial) { |
| 804 | num++; |
| 805 | } |
| 806 | } |
| 807 | int[] newUsers = new int[num]; |
| 808 | for (int i = 0; i < mUsers.size(); i++) { |
| 809 | if (!mUsers.valueAt(i).partial) { |
| 810 | newUsers[i] = mUsers.keyAt(i); |
| 811 | } |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 812 | } |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 813 | mUserIds = newUsers; |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 817 | * Make a note of the last started time of a user. |
| 818 | * @param userId the user that was just foregrounded |
| 819 | */ |
| 820 | public void userForeground(int userId) { |
| 821 | synchronized (mPackagesLock) { |
| 822 | UserInfo user = mUsers.get(userId); |
| 823 | long now = System.currentTimeMillis(); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 824 | if (user == null || user.partial) { |
| 825 | Slog.w(LOG_TAG, "userForeground: unknown user #" + userId); |
| 826 | return; |
| 827 | } |
| 828 | if (now > EPOCH_PLUS_30_YEARS) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 829 | user.lastLoggedInTime = now; |
| 830 | writeUserLocked(user); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /** |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 836 | * 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] | 837 | * TODO: May not be a good idea to recycle ids, in case it results in confusion |
| 838 | * for data and battery stats collection, or unexpected cross-talk. |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 839 | * @return |
| 840 | */ |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 841 | private int getNextAvailableIdLocked() { |
Dianne Hackborn | 4428e17 | 2012-08-24 17:43:05 -0700 | [diff] [blame] | 842 | synchronized (mPackagesLock) { |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 843 | int i = MIN_USER_ID; |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 844 | while (i < Integer.MAX_VALUE) { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 845 | if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.contains(i)) { |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 846 | break; |
| 847 | } |
| 848 | i++; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 849 | } |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 850 | return i; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 851 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 852 | } |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 853 | |
| 854 | @Override |
| 855 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 856 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 857 | != PackageManager.PERMISSION_GRANTED) { |
| 858 | pw.println("Permission Denial: can't dump UserManager from from pid=" |
| 859 | + Binder.getCallingPid() |
| 860 | + ", uid=" + Binder.getCallingUid() |
| 861 | + " without permission " |
| 862 | + android.Manifest.permission.DUMP); |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | long now = System.currentTimeMillis(); |
| 867 | StringBuilder sb = new StringBuilder(); |
| 868 | synchronized (mPackagesLock) { |
| 869 | pw.println("Users:"); |
| 870 | for (int i = 0; i < mUsers.size(); i++) { |
| 871 | UserInfo user = mUsers.valueAt(i); |
| 872 | if (user == null) continue; |
Amith Yamasani | 634cf31 | 2012-10-04 17:34:21 -0700 | [diff] [blame] | 873 | pw.print(" "); pw.print(user); pw.print(" serialNo="); pw.print(user.serialNumber); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 874 | if (mRemovingUserIds.contains(mUsers.keyAt(i))) pw.print(" <removing> "); |
| 875 | if (user.partial) pw.print(" <partial>"); |
| 876 | pw.println(); |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 877 | pw.print(" Created: "); |
| 878 | if (user.creationTime == 0) { |
| 879 | pw.println("<unknown>"); |
| 880 | } else { |
| 881 | sb.setLength(0); |
| 882 | TimeUtils.formatDuration(now - user.creationTime, sb); |
| 883 | sb.append(" ago"); |
| 884 | pw.println(sb); |
| 885 | } |
| 886 | pw.print(" Last logged in: "); |
| 887 | if (user.lastLoggedInTime == 0) { |
| 888 | pw.println("<unknown>"); |
| 889 | } else { |
| 890 | sb.setLength(0); |
| 891 | TimeUtils.formatDuration(now - user.lastLoggedInTime, sb); |
| 892 | sb.append(" ago"); |
| 893 | pw.println(sb); |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 898 | } |