Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | package android.os; |
| 17 | |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 18 | import android.app.ActivityManagerNative; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.pm.UserInfo; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 23 | import android.graphics.Canvas; |
| 24 | import android.graphics.Bitmap.Config; |
| 25 | import android.graphics.Rect; |
| 26 | import android.graphics.drawable.BitmapDrawable; |
| 27 | import android.graphics.drawable.Drawable; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 30 | import com.android.internal.R; |
| 31 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 32 | import java.util.ArrayList; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 33 | import java.util.List; |
| 34 | |
| 35 | /** |
| 36 | * Manages users and user details on a multi-user system. |
| 37 | */ |
| 38 | public class UserManager { |
| 39 | |
| 40 | private static String TAG = "UserManager"; |
| 41 | private final IUserManager mService; |
| 42 | private final Context mContext; |
| 43 | |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 44 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 45 | * Key for user restrictions. Specifies if a user is disallowed from adding and removing |
| 46 | * accounts. |
| 47 | * The default value is <code>false</code>. |
| 48 | * <p/> |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 49 | * Type: Boolean |
| 50 | * @see #setUserRestrictions(Bundle) |
| 51 | * @see #getUserRestrictions() |
| 52 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 53 | public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 56 | * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi |
| 57 | * access points. |
| 58 | * The default value is <code>false</code>. |
| 59 | * <p/> |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 60 | * Type: Boolean |
| 61 | * @see #setUserRestrictions(Bundle) |
| 62 | * @see #getUserRestrictions() |
| 63 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 64 | public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 67 | * Key for user restrictions. Specifies if a user is disallowed from installing applications. |
| 68 | * The default value is <code>false</code>. |
| 69 | * <p/> |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 70 | * Type: Boolean |
| 71 | * @see #setUserRestrictions(Bundle) |
| 72 | * @see #getUserRestrictions() |
| 73 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 74 | public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 77 | * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications. |
| 78 | * The default value is <code>false</code>. |
| 79 | * <p/> |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 80 | * Type: Boolean |
| 81 | * @see #setUserRestrictions(Bundle) |
| 82 | * @see #getUserRestrictions() |
| 83 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 84 | public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 85 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing. |
| 88 | * The default value is <code>false</code>. |
| 89 | * <p/> |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 90 | * Type: Boolean |
| 91 | * @see #setUserRestrictions(Bundle) |
| 92 | * @see #getUserRestrictions() |
| 93 | */ |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 94 | public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 95 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 96 | /** |
| 97 | * Key for user restrictions. Specifies if a user is disallowed from enabling the |
| 98 | * "Unknown Sources" setting, that allows installation of apps from unknown sources. |
| 99 | * The default value is <code>false</code>. |
| 100 | * <p/> |
| 101 | * Type: Boolean |
| 102 | * @see #setUserRestrictions(Bundle) |
| 103 | * @see #getUserRestrictions() |
| 104 | */ |
| 105 | public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; |
| 106 | |
| 107 | /** |
| 108 | * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth. |
| 109 | * The default value is <code>false</code>. |
| 110 | * <p/> |
| 111 | * Type: Boolean |
| 112 | * @see #setUserRestrictions(Bundle) |
| 113 | * @see #getUserRestrictions() |
| 114 | */ |
| 115 | public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; |
| 116 | |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 117 | /** |
| 118 | * Key for user restrictions. Specifies if a user is disallowed from transferring files over |
| 119 | * USB. The default value is <code>false</code>. |
| 120 | * <p/> |
| 121 | * Type: Boolean |
| 122 | * @see #setUserRestrictions(Bundle) |
| 123 | * @see #getUserRestrictions() |
| 124 | */ |
| 125 | public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; |
| 126 | |
Emily Bernier | b223f73 | 2013-04-11 15:46:36 -0400 | [diff] [blame] | 127 | /** |
| 128 | * Key for user restrictions. Specifies if a user is disallowed from configuring user |
| 129 | * credentials. The default value is <code>false</code>. |
| 130 | * <p/> |
| 131 | * Type: Boolean |
| 132 | * @see #setUserRestrictions(Bundle) |
| 133 | * @see #getUserRestrictions() |
| 134 | */ |
| 135 | public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; |
| 136 | |
| 137 | /** |
| 138 | * Key for user restrictions. Specifies if a user is disallowed from removing users. |
| 139 | * The default value is <code>false</code>. |
| 140 | * <p/> |
| 141 | * Type: Boolean |
| 142 | * @see #setUserRestrictions(Bundle) |
| 143 | * @see #getUserRestrictions() |
| 144 | */ |
| 145 | public static final String DISALLOW_REMOVE_USER = "no_remove_user"; |
| 146 | |
Julia Reynolds | d46d0f9 | 2014-04-23 15:23:24 -0400 | [diff] [blame] | 147 | /** |
| 148 | * Key for user restrictions. Specifies if a user is disallowed from enabling or |
| 149 | * accessing debugging features. The default value is <code>false</code>. |
| 150 | * <p/> |
| 151 | * Type: Boolean |
| 152 | * @see #setUserRestrictions(Bundle) |
| 153 | * @see #getUserRestrictions() |
| 154 | */ |
| 155 | public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; |
| 156 | |
| 157 | /** |
| 158 | * Key for user restrictions. Specifies if a user is disallowed from configuring VPN. |
| 159 | * The default value is <code>false</code>. |
| 160 | * <p/> |
| 161 | * Type: Boolean |
| 162 | * @see #setUserRestrictions(Bundle) |
| 163 | * @see #getUserRestrictions() |
| 164 | */ |
| 165 | public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; |
| 166 | |
| 167 | /** |
| 168 | * Key for user restrictions. Specifies if a user is disallowed from configuring Tethering |
| 169 | * & portable hotspots. The default value is <code>false</code>. |
| 170 | * <p/> |
| 171 | * Type: Boolean |
| 172 | * @see #setUserRestrictions(Bundle) |
| 173 | * @see #getUserRestrictions() |
| 174 | */ |
| 175 | public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; |
| 176 | |
| 177 | /** |
| 178 | * Key for user restrictions. Specifies if a user is disallowed from factory resetting |
| 179 | * from Settings. |
| 180 | * The default value is <code>false</code>. |
| 181 | * <p> |
| 182 | * @see #setUserRestrictions(Bundle) |
| 183 | * @see #getUserRestrictions() |
| 184 | */ |
| 185 | public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; |
| 186 | |
| 187 | /** |
| 188 | * Key for user restrictions. Specifies if a user is disallowed from adding new users and |
| 189 | * profiles. The default value is <code>false</code>. |
| 190 | * <p> |
| 191 | * Type: Boolean |
| 192 | * @see #setUserRestrictions(Bundle) |
| 193 | * @see #getUserRestrictions() |
| 194 | */ |
| 195 | public static final String DISALLOW_ADD_USER = "no_add_user"; |
| 196 | |
| 197 | /** |
| 198 | * Key for user restrictions. Specifies if a user is disallowed from disabling application |
| 199 | * verification. The default value is <code>false</code>. |
| 200 | * <p> |
| 201 | * Type: Boolean |
| 202 | * @see #setUserRestrictions(Bundle) |
| 203 | * @see #getUserRestrictions() |
| 204 | */ |
| 205 | public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; |
| 206 | |
| 207 | /** |
| 208 | * Key for user restrictions. Specifies if a user is disallowed from configuring cell |
| 209 | * broadcasts. The default value is <code>false</code>. |
| 210 | * <p> |
| 211 | * Type: Boolean |
| 212 | * @see #setUserRestrictions(Bundle) |
| 213 | * @see #getUserRestrictions() |
| 214 | */ |
| 215 | public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; |
| 216 | |
| 217 | /** |
| 218 | * Key for user restrictions. Specifies if a user is disallowed from configuring mobile |
| 219 | * networks. The default value is <code>false</code>. |
| 220 | * <p> |
| 221 | * Type: Boolean |
| 222 | * @see #setUserRestrictions(Bundle) |
| 223 | * @see #getUserRestrictions() |
| 224 | */ |
| 225 | public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; |
| 226 | |
| 227 | /** |
| 228 | * Key for user restrictions. Specifies if a user is disallowed from configuring |
| 229 | * applications in Settings. The default value is <code>false</code>. |
| 230 | * <p> |
| 231 | * Type: Boolean |
| 232 | * @see #setUserRestrictions(Bundle) |
| 233 | * @see #getUserRestrictions() |
| 234 | */ |
| 235 | public static final String DISALLOW_CONFIG_APPS = "no_config_apps"; |
| 236 | |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 237 | /** |
| 238 | * Key for user restrictions. Specifies if a user is disallowed from mounting |
| 239 | * physical external media. The default value is <code>false</code>. |
| 240 | * <p/> |
| 241 | * Type: Boolean |
| 242 | * @see #setUserRestrictions(Bundle) |
| 243 | * @see #getUserRestrictions() |
| 244 | */ |
| 245 | public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; |
| 246 | |
| 247 | /** |
| 248 | * Key for user restrictions. Specifies if a user is disallowed from adjusting microphone |
| 249 | * volume. |
| 250 | * The default value is <code>false</code>. |
| 251 | * <p/> |
| 252 | * Type: Boolean |
| 253 | * @see #setUserRestrictions(Bundle) |
| 254 | * @see #getUserRestrictions() |
| 255 | */ |
| 256 | public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; |
| 257 | |
| 258 | /** |
| 259 | * Key for user restrictions. Specifies if a user is disallowed from adjusting the master |
| 260 | * volume. |
| 261 | * The default value is <code>false</code>. |
| 262 | * <p/> |
| 263 | * Type: Boolean |
| 264 | * @see #setUserRestrictions(Bundle) |
| 265 | * @see #getUserRestrictions() |
| 266 | */ |
| 267 | public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; |
| 268 | |
Amith Yamasani | 9f6c25f | 2014-05-16 14:49:15 -0700 | [diff] [blame] | 269 | /** |
| 270 | * Key for user restrictions. Specifies that the user is not allowed to send or receive |
| 271 | * phone calls or text messages. Emergency calls may still be permitted. |
| 272 | * The default value is <code>false</code>. |
| 273 | * <p/> |
| 274 | * Type: Boolean |
| 275 | * @see #setUserRestrictions(Bundle) |
| 276 | * @see #getUserRestrictions() |
| 277 | */ |
| 278 | public static final String DISALLOW_TELEPHONY = "no_telephony"; |
| 279 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 280 | /** @hide */ |
| 281 | public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; |
| 282 | /** @hide */ |
| 283 | public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; |
| 284 | /** @hide */ |
| 285 | public static final int PIN_VERIFICATION_SUCCESS = -1; |
| 286 | |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 287 | private static UserManager sInstance = null; |
| 288 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 289 | /** @hide */ |
Amith Yamasani | 27db468 | 2013-03-30 17:07:47 -0700 | [diff] [blame] | 290 | public synchronized static UserManager get(Context context) { |
| 291 | if (sInstance == null) { |
| 292 | sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 293 | } |
| 294 | return sInstance; |
| 295 | } |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 296 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 297 | /** @hide */ |
| 298 | public UserManager(Context context, IUserManager service) { |
| 299 | mService = service; |
| 300 | mContext = context; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Returns whether the system supports multiple users. |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 305 | * @return true if multiple users can be created by user, false if it is a single user device. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 306 | * @hide |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 307 | */ |
Jeff Sharkey | 4673e7e | 2012-09-19 13:14:30 -0700 | [diff] [blame] | 308 | public static boolean supportsMultipleUsers() { |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 309 | return getMaxSupportedUsers() > 1 |
| 310 | && SystemProperties.getBoolean("fw.show_multiuserui", |
| 311 | Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 314 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 315 | * Returns the user handle for the user that the calling process is running on. |
| 316 | * |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 317 | * @return the user handle of the user making this call. |
| 318 | * @hide |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 319 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 320 | public int getUserHandle() { |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 321 | return UserHandle.myUserId(); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
Dianne Hackborn | 8832c18 | 2012-09-17 17:20:24 -0700 | [diff] [blame] | 325 | * Returns the user name of the user making this call. This call is only |
| 326 | * available to applications on the system image; it requires the |
| 327 | * MANAGE_USERS permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 328 | * @return the user name |
| 329 | */ |
| 330 | public String getUserName() { |
| 331 | try { |
| 332 | return mService.getUserInfo(getUserHandle()).name; |
| 333 | } catch (RemoteException re) { |
| 334 | Log.w(TAG, "Could not get user name", re); |
| 335 | return ""; |
| 336 | } |
| 337 | } |
| 338 | |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 339 | /** |
| 340 | * Used to determine whether the user making this call is subject to |
| 341 | * teleportations. |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 342 | * @return whether the user making this call is a goat |
Dan Morrill | e4ab16a | 2012-09-20 20:25:55 -0700 | [diff] [blame] | 343 | */ |
| 344 | public boolean isUserAGoat() { |
| 345 | return false; |
| 346 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 347 | |
| 348 | /** |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 349 | * Used to check if the user making this call is linked to another user. Linked users may have |
Amith Yamasani | 46bc4eb | 2013-04-12 13:26:50 -0700 | [diff] [blame] | 350 | * a reduced number of available apps, app restrictions and account restrictions. |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 351 | * @return whether the user making this call is a linked user |
Amith Yamasani | 2555daf | 2013-04-25 13:39:27 -0700 | [diff] [blame] | 352 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 353 | */ |
Amith Yamasani | e137590 | 2013-04-13 16:48:35 -0700 | [diff] [blame] | 354 | public boolean isLinkedUser() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 355 | try { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 356 | return mService.isRestricted(); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 357 | } catch (RemoteException re) { |
Amith Yamasani | 46bc4eb | 2013-04-12 13:26:50 -0700 | [diff] [blame] | 358 | Log.w(TAG, "Could not check if user is limited ", re); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | } |
| 362 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 363 | /** |
Dianne Hackborn | a8a9bd6 | 2012-10-09 15:36:59 -0700 | [diff] [blame] | 364 | * Return whether the given user is actively running. This means that |
| 365 | * the user is in the "started" state, not "stopped" -- it is currently |
| 366 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 367 | * etc. A started user may be either the current foreground user or a |
| 368 | * background user; the result here does not distinguish between the two. |
| 369 | * @param user The user to retrieve the running state for. |
| 370 | */ |
| 371 | public boolean isUserRunning(UserHandle user) { |
| 372 | try { |
| 373 | return ActivityManagerNative.getDefault().isUserRunning( |
| 374 | user.getIdentifier(), false); |
| 375 | } catch (RemoteException e) { |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Return whether the given user is actively running <em>or</em> stopping. |
| 382 | * This is like {@link #isUserRunning(UserHandle)}, but will also return |
| 383 | * true if the user had been running but is in the process of being stopped |
| 384 | * (but is not yet fully stopped, and still running some code). |
| 385 | * @param user The user to retrieve the running state for. |
| 386 | */ |
| 387 | public boolean isUserRunningOrStopping(UserHandle user) { |
| 388 | try { |
| 389 | return ActivityManagerNative.getDefault().isUserRunning( |
| 390 | user.getIdentifier(), true); |
| 391 | } catch (RemoteException e) { |
| 392 | return false; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 397 | * Returns the UserInfo object describing a specific user. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 398 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 399 | * @param userHandle the user handle of the user whose information is being requested. |
| 400 | * @return the UserInfo object for a specific user. |
| 401 | * @hide |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 402 | */ |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 403 | public UserInfo getUserInfo(int userHandle) { |
| 404 | try { |
| 405 | return mService.getUserInfo(userHandle); |
| 406 | } catch (RemoteException re) { |
| 407 | Log.w(TAG, "Could not get user info", re); |
| 408 | return null; |
| 409 | } |
| 410 | } |
| 411 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 412 | /** |
| 413 | * Returns the user-wide restrictions imposed on this user. |
| 414 | * @return a Bundle containing all the restrictions. |
| 415 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 416 | public Bundle getUserRestrictions() { |
| 417 | return getUserRestrictions(Process.myUserHandle()); |
| 418 | } |
| 419 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 420 | /** |
| 421 | * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. |
| 422 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 423 | * @return a Bundle containing all the restrictions. |
| 424 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 425 | public Bundle getUserRestrictions(UserHandle userHandle) { |
| 426 | try { |
| 427 | return mService.getUserRestrictions(userHandle.getIdentifier()); |
| 428 | } catch (RemoteException re) { |
| 429 | Log.w(TAG, "Could not get user restrictions", re); |
| 430 | return Bundle.EMPTY; |
| 431 | } |
| 432 | } |
| 433 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Sets all the user-wide restrictions for this user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 436 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 437 | * @param restrictions the Bundle containing all the restrictions. |
| 438 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 439 | public void setUserRestrictions(Bundle restrictions) { |
| 440 | setUserRestrictions(restrictions, Process.myUserHandle()); |
| 441 | } |
| 442 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 443 | /** |
| 444 | * Sets all the user-wide restrictions for the specified user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 445 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 446 | * @param restrictions the Bundle containing all the restrictions. |
| 447 | * @param userHandle the UserHandle of the user for whom to set the restrictions. |
| 448 | */ |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 449 | public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { |
| 450 | try { |
| 451 | mService.setUserRestrictions(restrictions, userHandle.getIdentifier()); |
| 452 | } catch (RemoteException re) { |
| 453 | Log.w(TAG, "Could not set user restrictions", re); |
| 454 | } |
| 455 | } |
| 456 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 457 | /** |
| 458 | * Sets the value of a specific restriction. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 459 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 460 | * @param key the key of the restriction |
| 461 | * @param value the value for the restriction |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 462 | */ |
| 463 | public void setUserRestriction(String key, boolean value) { |
| 464 | Bundle bundle = getUserRestrictions(); |
| 465 | bundle.putBoolean(key, value); |
| 466 | setUserRestrictions(bundle); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * @hide |
| 471 | * Sets the value of a specific restriction on a specific user. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 472 | * Requires the MANAGE_USERS permission. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 473 | * @param key the key of the restriction |
| 474 | * @param value the value for the restriction |
| 475 | * @param userHandle the user whose restriction is to be changed. |
| 476 | */ |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 477 | public void setUserRestriction(String key, boolean value, UserHandle userHandle) { |
| 478 | Bundle bundle = getUserRestrictions(userHandle); |
| 479 | bundle.putBoolean(key, value); |
| 480 | setUserRestrictions(bundle, userHandle); |
| 481 | } |
| 482 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 483 | /** |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 484 | * @hide |
| 485 | * Returns whether the current user has been disallowed from performing certain actions |
| 486 | * or setting certain settings. |
| 487 | * @param restrictionKey the string key representing the restriction |
| 488 | */ |
| 489 | public boolean hasUserRestriction(String restrictionKey) { |
David Christie | b12ba93 | 2013-09-03 17:15:28 -0700 | [diff] [blame] | 490 | return hasUserRestriction(restrictionKey, Process.myUserHandle()); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * @hide |
| 495 | * Returns whether the given user has been disallowed from performing certain actions |
| 496 | * or setting certain settings. |
| 497 | * @param restrictionKey the string key representing the restriction |
| 498 | * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. |
| 499 | */ |
| 500 | public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { |
| 501 | return getUserRestrictions(userHandle).getBoolean(restrictionKey, false); |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 505 | * Return the serial number for a user. This is a device-unique |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 506 | * number assigned to that user; if the user is deleted and then a new |
| 507 | * user created, the new users will not be given the same serial number. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 508 | * @param user The user whose serial number is to be retrieved. |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 509 | * @return The serial number of the given user; returns -1 if the |
| 510 | * given UserHandle does not exist. |
Dianne Hackborn | 33f9cb8 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 511 | * @see #getUserForSerialNumber(long) |
| 512 | */ |
| 513 | public long getSerialNumberForUser(UserHandle user) { |
| 514 | return getUserSerialNumber(user.getIdentifier()); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Return the user associated with a serial number previously |
| 519 | * returned by {@link #getSerialNumberForUser(UserHandle)}. |
| 520 | * @param serialNumber The serial number of the user that is being |
| 521 | * retrieved. |
| 522 | * @return Return the user associated with the serial number, or null |
| 523 | * if there is not one. |
| 524 | * @see #getSerialNumberForUser(UserHandle) |
| 525 | */ |
| 526 | public UserHandle getUserForSerialNumber(long serialNumber) { |
| 527 | int ident = getUserHandle((int)serialNumber); |
| 528 | return ident >= 0 ? new UserHandle(ident) : null; |
| 529 | } |
| 530 | |
| 531 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 532 | * Creates a user with the specified name and options. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 533 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 534 | * |
| 535 | * @param name the user's name |
| 536 | * @param flags flags that identify the type of user and other properties. |
| 537 | * @see UserInfo |
| 538 | * |
| 539 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 540 | * @hide |
| 541 | */ |
| 542 | public UserInfo createUser(String name, int flags) { |
| 543 | try { |
| 544 | return mService.createUser(name, flags); |
| 545 | } catch (RemoteException re) { |
| 546 | Log.w(TAG, "Could not create a user", re); |
| 547 | return null; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 552 | * Creates a user with the specified name and options as a profile of another user. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 553 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 554 | * |
| 555 | * @param name the user's name |
| 556 | * @param flags flags that identify the type of user and other properties. |
| 557 | * @see UserInfo |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 558 | * @param userHandle new user will be a profile of this use. |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 559 | * |
| 560 | * @return the UserInfo object for the created user, or null if the user could not be created. |
| 561 | * @hide |
| 562 | */ |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 563 | public UserInfo createProfileForUser(String name, int flags, int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 564 | try { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 565 | return mService.createProfileForUser(name, flags, userHandle); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 566 | } catch (RemoteException re) { |
| 567 | Log.w(TAG, "Could not create a user", re); |
| 568 | return null; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 573 | * Sets the user as enabled, if such an user exists. |
| 574 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 575 | * Note that the default is true, it's only that managed profiles might not be enabled. |
| 576 | * |
| 577 | * @param userHandle the id of the profile to enable |
| 578 | * @hide |
| 579 | */ |
| 580 | public void setUserEnabled(int userHandle) { |
| 581 | try { |
| 582 | mService.setUserEnabled(userHandle); |
| 583 | } catch (RemoteException e) { |
| 584 | Log.w(TAG, "Could not enable the profile", e); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | /** |
Dianne Hackborn | b26306a | 2012-10-24 15:22:21 -0700 | [diff] [blame] | 589 | * Return the number of users currently created on the device. |
| 590 | */ |
| 591 | public int getUserCount() { |
| 592 | List<UserInfo> users = getUsers(); |
| 593 | return users != null ? users.size() : 1; |
| 594 | } |
| 595 | |
| 596 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 597 | * Returns information for all users on this device. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 598 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 599 | * @return the list of users that were created. |
| 600 | * @hide |
| 601 | */ |
| 602 | public List<UserInfo> getUsers() { |
| 603 | try { |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 604 | return mService.getUsers(false); |
| 605 | } catch (RemoteException re) { |
| 606 | Log.w(TAG, "Could not get user list", re); |
| 607 | return null; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 612 | * Returns list of the profiles of userHandle including |
| 613 | * userHandle itself. |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 614 | * Note that it this returns both enabled and not enabled profiles. See |
| 615 | * {@link #getUserProfiles()} if you need only the enabled ones. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 616 | * |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 617 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
| 618 | * @param userHandle profiles of this user will be returned. |
| 619 | * @return the list of profiles. |
| 620 | * @hide |
| 621 | */ |
| 622 | public List<UserInfo> getProfiles(int userHandle) { |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 623 | try { |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 624 | return mService.getProfiles(userHandle, false /* enabledOnly */); |
Kenny Guy | a52dc3e | 2014-02-11 15:33:14 +0000 | [diff] [blame] | 625 | } catch (RemoteException re) { |
| 626 | Log.w(TAG, "Could not get user list", re); |
| 627 | return null; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 632 | * Returns a list of UserHandles for profiles associated with the user that the calling process |
| 633 | * is running on, including the user itself. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 634 | * |
| 635 | * @return A non-empty list of UserHandles associated with the calling user. |
| 636 | */ |
| 637 | public List<UserHandle> getUserProfiles() { |
| 638 | ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 639 | List<UserInfo> users = new ArrayList<UserInfo>(); |
| 640 | try { |
Alexandra Gherghina | f2e7b3f | 2014-04-30 17:01:03 +0000 | [diff] [blame] | 641 | users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); |
Alexandra Gherghina | 385124d | 2014-04-03 13:37:39 +0100 | [diff] [blame] | 642 | } catch (RemoteException re) { |
| 643 | Log.w(TAG, "Could not get user list", re); |
| 644 | return null; |
| 645 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 646 | for (UserInfo info : users) { |
| 647 | UserHandle userHandle = new UserHandle(info.id); |
| 648 | profiles.add(userHandle); |
| 649 | } |
| 650 | return profiles; |
| 651 | } |
| 652 | |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 653 | /** |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 654 | * Returns the parent of the profile which this method is called from |
| 655 | * or null if called from a user that is not a profile. |
| 656 | * |
| 657 | * @hide |
| 658 | */ |
| 659 | public UserInfo getProfileParent(int userHandle) { |
| 660 | try { |
| 661 | return mService.getProfileParent(userHandle); |
| 662 | } catch (RemoteException re) { |
| 663 | Log.w(TAG, "Could not get profile parent", re); |
| 664 | return null; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | /** |
Amith Yamasani | 7dda265 | 2014-04-11 14:57:12 -0700 | [diff] [blame] | 669 | * If the target user is a managed profile of the calling user or the caller |
| 670 | * is itself a managed profile, then this returns a badged copy of the given |
| 671 | * icon to be able to distinguish it from the original icon. |
| 672 | * <P> |
| 673 | * If the original drawable is not a BitmapDrawable, then the original |
| 674 | * drawable is returned. |
| 675 | * </P> |
| 676 | * |
| 677 | * @param icon The icon to badge. |
| 678 | * @param user The target user. |
| 679 | * @return A drawable that combines the original icon and a badge as |
| 680 | * determined by the system. |
| 681 | */ |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 682 | public Drawable getBadgedDrawableForUser(Drawable icon, UserHandle user) { |
| 683 | int badgeResId = getBadgeResIdForUser(user.getIdentifier()); |
| 684 | if (badgeResId == 0) { |
| 685 | return icon; |
| 686 | } else { |
| 687 | Drawable badgeIcon = mContext.getPackageManager() |
| 688 | .getDrawable("system", badgeResId, null); |
| 689 | return getMergedDrawable(icon, badgeIcon); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | private int getBadgeResIdForUser(int userHandle) { |
| 694 | // Return the framework-provided badge. |
Jessica Hummel | be81c80 | 2014-04-22 15:49:22 +0100 | [diff] [blame] | 695 | List<UserInfo> userProfiles = getProfiles(getUserHandle()); |
Amith Yamasani | 5abdbb6 | 2014-04-08 17:23:46 -0700 | [diff] [blame] | 696 | for (UserInfo user : userProfiles) { |
| 697 | if (user.id == userHandle |
| 698 | && user.isManagedProfile()) { |
| 699 | return com.android.internal.R.drawable.ic_corp_badge; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 700 | } |
| 701 | } |
Amith Yamasani | 5abdbb6 | 2014-04-08 17:23:46 -0700 | [diff] [blame] | 702 | return 0; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | private Drawable getMergedDrawable(Drawable icon, Drawable badge) { |
| 706 | final int width = icon.getIntrinsicWidth(); |
| 707 | final int height = icon.getIntrinsicHeight(); |
| 708 | Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); |
| 709 | Canvas canvas = new Canvas(bitmap); |
| 710 | icon.setBounds(0, 0, width, height); |
| 711 | icon.draw(canvas); |
| 712 | badge.setBounds(0, 0, width, height); |
| 713 | badge.draw(canvas); |
| 714 | BitmapDrawable merged = new BitmapDrawable(bitmap); |
| 715 | if (icon instanceof BitmapDrawable) { |
| 716 | merged.setTargetDensity(((BitmapDrawable) icon).getBitmap().getDensity()); |
| 717 | } |
| 718 | return merged; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Returns information for all users on this device. Requires |
| 723 | * {@link android.Manifest.permission#MANAGE_USERS} permission. |
Emily Bernier | 394a6cd | 2014-05-07 12:49:20 -0400 | [diff] [blame] | 724 | * |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 725 | * @param excludeDying specify if the list should exclude users being |
| 726 | * removed. |
Amith Yamasani | 920ace0 | 2012-09-20 22:15:37 -0700 | [diff] [blame] | 727 | * @return the list of users that were created. |
| 728 | * @hide |
| 729 | */ |
| 730 | public List<UserInfo> getUsers(boolean excludeDying) { |
| 731 | try { |
| 732 | return mService.getUsers(excludeDying); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 733 | } catch (RemoteException re) { |
| 734 | Log.w(TAG, "Could not get user list", re); |
| 735 | return null; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Removes a user and all associated data. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 741 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 742 | * @param userHandle the integer handle of the user, where 0 is the primary user. |
| 743 | * @hide |
| 744 | */ |
| 745 | public boolean removeUser(int userHandle) { |
| 746 | try { |
| 747 | return mService.removeUser(userHandle); |
| 748 | } catch (RemoteException re) { |
| 749 | Log.w(TAG, "Could not remove user ", re); |
| 750 | return false; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Updates the user's name. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 756 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 757 | * |
| 758 | * @param userHandle the user's integer handle |
| 759 | * @param name the new name for the user |
| 760 | * @hide |
| 761 | */ |
| 762 | public void setUserName(int userHandle, String name) { |
| 763 | try { |
| 764 | mService.setUserName(userHandle, name); |
| 765 | } catch (RemoteException re) { |
| 766 | Log.w(TAG, "Could not set the user name ", re); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 771 | * Sets the user's photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 772 | * @param userHandle the user for whom to change the photo. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 773 | * @param icon the bitmap to set as the photo. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 774 | * @hide |
| 775 | */ |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 776 | public void setUserIcon(int userHandle, Bitmap icon) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 777 | try { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 778 | mService.setUserIcon(userHandle, icon); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 779 | } catch (RemoteException re) { |
| 780 | Log.w(TAG, "Could not set the user icon ", re); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | /** |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 785 | * Returns a file descriptor for the user's photo. PNG data can be read from this file. |
| 786 | * @param userHandle the user whose photo we want to read. |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 787 | * @return a {@link Bitmap} of the user's photo, or null if there's no photo. |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 788 | * @hide |
| 789 | */ |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 790 | public Bitmap getUserIcon(int userHandle) { |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 791 | try { |
| 792 | return mService.getUserIcon(userHandle); |
| 793 | } catch (RemoteException re) { |
Amith Yamasani | e928d7d | 2012-09-17 21:46:51 -0700 | [diff] [blame] | 794 | Log.w(TAG, "Could not get the user icon ", re); |
Amith Yamasani | 3b49f07 | 2012-09-17 10:21:43 -0700 | [diff] [blame] | 795 | return null; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 800 | * Enable or disable the use of a guest account. If disabled, the existing guest account |
| 801 | * will be wiped. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 802 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 803 | * @param enable whether to enable a guest account. |
| 804 | * @hide |
| 805 | */ |
| 806 | public void setGuestEnabled(boolean enable) { |
| 807 | try { |
| 808 | mService.setGuestEnabled(enable); |
| 809 | } catch (RemoteException re) { |
| 810 | Log.w(TAG, "Could not change guest account availability to " + enable); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Checks if a guest user is enabled for this device. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 816 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 817 | * @return whether a guest user is enabled |
| 818 | * @hide |
| 819 | */ |
| 820 | public boolean isGuestEnabled() { |
| 821 | try { |
| 822 | return mService.isGuestEnabled(); |
| 823 | } catch (RemoteException re) { |
| 824 | Log.w(TAG, "Could not retrieve guest enabled state"); |
| 825 | return false; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Wipes all the data for a user, but doesn't remove the user. |
Amith Yamasani | 19526374 | 2012-08-21 15:40:12 -0700 | [diff] [blame] | 831 | * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 832 | * @param userHandle |
| 833 | * @hide |
| 834 | */ |
| 835 | public void wipeUser(int userHandle) { |
| 836 | try { |
| 837 | mService.wipeUser(userHandle); |
| 838 | } catch (RemoteException re) { |
| 839 | Log.w(TAG, "Could not wipe user " + userHandle); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Returns the maximum number of users that can be created on this device. A return value |
| 845 | * of 1 means that it is a single user device. |
| 846 | * @hide |
Maggie Benthall | a12fccf | 2013-03-14 18:02:12 -0400 | [diff] [blame] | 847 | * @return a value greater than or equal to 1 |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 848 | */ |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 849 | public static int getMaxSupportedUsers() { |
Amith Yamasani | ff54920 | 2012-10-12 12:44:49 -0700 | [diff] [blame] | 850 | // Don't allow multiple users on certain builds |
| 851 | if (android.os.Build.ID.startsWith("JVP")) return 1; |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 852 | return SystemProperties.getInt("fw.max_users", |
| 853 | Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 854 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 855 | |
| 856 | /** |
Kenny Guy | 1a44753 | 2014-02-20 21:55:32 +0000 | [diff] [blame] | 857 | * Returns true if the user switcher should be shown, this will be if there |
| 858 | * are multiple users that aren't managed profiles. |
| 859 | * @hide |
| 860 | * @return true if user switcher should be shown. |
| 861 | */ |
| 862 | public boolean isUserSwitcherEnabled() { |
| 863 | List<UserInfo> users = getUsers(true); |
| 864 | if (users == null) { |
| 865 | return false; |
| 866 | } |
| 867 | int switchableUserCount = 0; |
| 868 | for (UserInfo user : users) { |
| 869 | if (user.supportsSwitchTo()) { |
| 870 | ++switchableUserCount; |
| 871 | } |
| 872 | } |
| 873 | return switchableUserCount > 1; |
| 874 | } |
| 875 | |
| 876 | /** |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 877 | * Returns a serial number on this device for a given userHandle. User handles can be recycled |
| 878 | * when deleting and creating users, but serial numbers are not reused until the device is wiped. |
| 879 | * @param userHandle |
| 880 | * @return a serial number associated with that user, or -1 if the userHandle is not valid. |
| 881 | * @hide |
| 882 | */ |
| 883 | public int getUserSerialNumber(int userHandle) { |
| 884 | try { |
| 885 | return mService.getUserSerialNumber(userHandle); |
| 886 | } catch (RemoteException re) { |
| 887 | Log.w(TAG, "Could not get serial number for user " + userHandle); |
| 888 | } |
| 889 | return -1; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Returns a userHandle on this device for a given user serial number. User handles can be |
| 894 | * recycled when deleting and creating users, but serial numbers are not reused until the device |
| 895 | * is wiped. |
| 896 | * @param userSerialNumber |
| 897 | * @return the userHandle associated with that user serial number, or -1 if the serial number |
| 898 | * is not valid. |
| 899 | * @hide |
| 900 | */ |
| 901 | public int getUserHandle(int userSerialNumber) { |
| 902 | try { |
| 903 | return mService.getUserHandle(userSerialNumber); |
| 904 | } catch (RemoteException re) { |
| 905 | Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); |
| 906 | } |
| 907 | return -1; |
| 908 | } |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 909 | |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 910 | /** |
| 911 | * Returns a Bundle containing any saved application restrictions for this user, for the |
| 912 | * given package name. Only an application with this package name can call this method. |
| 913 | * @param packageName the package name of the calling application |
| 914 | * @return a Bundle with the restrictions as key/value pairs, or null if there are no |
| 915 | * saved restrictions. The values can be of type Boolean, String or String[], depending |
| 916 | * on the restriction type, as defined by the application. |
| 917 | */ |
| 918 | public Bundle getApplicationRestrictions(String packageName) { |
| 919 | try { |
| 920 | return mService.getApplicationRestrictions(packageName); |
| 921 | } catch (RemoteException re) { |
| 922 | Log.w(TAG, "Could not get application restrictions for package " + packageName); |
| 923 | } |
| 924 | return null; |
| 925 | } |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 926 | |
| 927 | /** |
| 928 | * @hide |
| 929 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 930 | public Bundle getApplicationRestrictions(String packageName, UserHandle user) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 931 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 932 | return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 933 | } catch (RemoteException re) { |
| 934 | Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); |
| 935 | } |
| 936 | return null; |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * @hide |
| 941 | */ |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 942 | public void setApplicationRestrictions(String packageName, Bundle restrictions, |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 943 | UserHandle user) { |
| 944 | try { |
Amith Yamasani | 7e99bc0 | 2013-04-16 18:24:51 -0700 | [diff] [blame] | 945 | mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 946 | } catch (RemoteException re) { |
| 947 | Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); |
| 948 | } |
| 949 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 950 | |
| 951 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 952 | * Sets a new challenge PIN for restrictions. This is only for use by pre-installed |
| 953 | * apps and requires the MANAGE_USERS permission. |
| 954 | * @param newPin the PIN to use for challenge dialogs. |
| 955 | * @return Returns true if the challenge PIN was set successfully. |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 956 | */ |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 957 | public boolean setRestrictionsChallenge(String newPin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 958 | try { |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 959 | return mService.setRestrictionsChallenge(newPin); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 960 | } catch (RemoteException re) { |
| 961 | Log.w(TAG, "Could not change restrictions pin"); |
| 962 | } |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * @hide |
| 968 | * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before |
| 969 | * allowing the user to enter the PIN. |
| 970 | * @return Returns a positive number (including zero) for how many milliseconds before |
| 971 | * you can accept another PIN, when the input is null or the input doesn't match the saved PIN. |
| 972 | * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns |
| 973 | * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set. |
| 974 | */ |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 975 | public int checkRestrictionsChallenge(String pin) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 976 | try { |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 977 | return mService.checkRestrictionsChallenge(pin); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 978 | } catch (RemoteException re) { |
| 979 | Log.w(TAG, "Could not check restrictions pin"); |
| 980 | } |
| 981 | return PIN_VERIFICATION_FAILED_INCORRECT; |
| 982 | } |
| 983 | |
| 984 | /** |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 985 | * @hide |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 986 | * Checks whether the user has restrictions that are PIN-protected. An application that |
| 987 | * participates in restrictions can check if the owner has requested a PIN challenge for |
| 988 | * any restricted operations. If there is a PIN in effect, the application should launch |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 989 | * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}. |
| 990 | * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 991 | * @return whether a restrictions PIN is in effect. |
| 992 | */ |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 993 | public boolean hasRestrictionsChallenge() { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 994 | try { |
Amith Yamasani | d304af6 | 2013-09-05 09:30:23 -0700 | [diff] [blame] | 995 | return mService.hasRestrictionsChallenge(); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 996 | } catch (RemoteException re) { |
| 997 | Log.w(TAG, "Could not change restrictions pin"); |
| 998 | } |
| 999 | return false; |
| 1000 | } |
Amith Yamasani | 1a7472e | 2013-07-02 11:17:30 -0700 | [diff] [blame] | 1001 | |
| 1002 | /** @hide */ |
| 1003 | public void removeRestrictions() { |
| 1004 | try { |
| 1005 | mService.removeRestrictions(); |
| 1006 | } catch (RemoteException re) { |
| 1007 | Log.w(TAG, "Could not change restrictions pin"); |
| 1008 | } |
| 1009 | } |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 1010 | } |