UserManager.java revision a12fccf57d5ec289793699d9b22ff45daccd3933
1258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/* 2258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Copyright (C) 2012 The Android Open Source Project 3258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 4258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 5258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * you may not use this file except in compliance with the License. 6258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * You may obtain a copy of the License at 7258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 8258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 9258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 10258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Unless required by applicable law or agreed to in writing, software 11258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 12258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * See the License for the specific language governing permissions and 14258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * limitations under the License. 15258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 16258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipackage android.os; 17258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 18a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative; 19258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context; 20df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasaniimport android.content.RestrictionEntry; 21258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 2227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 236794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 24258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log; 25258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 266794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 276794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 28258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system. 32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private static String TAG = "UserManager"; 36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 38258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 39e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 4071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from adding and removing 4171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * accounts. 4271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 4371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 44e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 45e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 46e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 47e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 4871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 49e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 50e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 5171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi 5271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * access points. 5371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 5471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 58e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 5971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 60e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 61e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 6271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from installing applications. 6371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 6471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 68e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 6971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 71e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications. 7371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 7471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 7971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 80e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 8171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 8271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing. 8371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 8471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 856794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * Type: Boolean 866794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #setUserRestrictions(Bundle) 876794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 886794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 89a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 9071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 916794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 92a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 93a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from enabling the 94a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 95a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 96a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 97a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 98a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 99a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 100a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 102a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth. 105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from transferring files over 116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * USB. The default value is <code>false</code>. 117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 122a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 123a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 124a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 125258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 126258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 127258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 128258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mContext = context; 129258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 130258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 131258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 132258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns whether the system supports multiple users. 133258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return true if multiple users can be created, false if it is a single user device. 134e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @hide 135258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1364673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 137258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return getMaxSupportedUsers() > 1; 138258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 139258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1406794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 141258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the user handle for the user that this application is running for. 142258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user handle of the user making this call. 143258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1446794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 145258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public int getUserHandle() { 14679af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 147258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 148258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 149258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1508832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 1518832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 1528832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 153258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 154258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 155258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 156258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 157258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 158258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 159258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user name", re); 160258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return ""; 161258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 162258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 163258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 164e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill /** 165e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 166e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 167a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return whether the user making this call is a goat 168e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 169e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 170e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill return false; 171e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 172df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 173df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 17471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Used to check if the user making this call is a restricted user. Restricted users may have 17571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * application restrictions imposed on them. All apps should default to the most restrictive 17671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * version, unless they have specific restrictions available through a call to 17771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * {@link Context#getApplicationRestrictions()}. 178df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 179df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani public boolean isUserRestricted() { 180df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 18171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 182df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 183df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not check if user restricted ", re); 184df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return false; 185df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 186df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 187df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 188258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 189a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 190a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 191a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 192a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 193a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 194a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 195a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 196a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 197a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 198a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 199a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), false); 200a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 201a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 202a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 203a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 204a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 205a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 206a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 207a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 208a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 209a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 210a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 211a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 212a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 213a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 214a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 215a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), true); 216a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 217a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 218a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 219a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 220a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 221a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 222258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 2231952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 224258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 225258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 226258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 227b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 228258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo getUserInfo(int userHandle) { 229258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 230258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 231258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 232258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user info", re); 233258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 234258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 235258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 236258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 23771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 23871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 23971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 24071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 241e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 242e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 243e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 244e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 24571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 24671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 24771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 24871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 24971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 250e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 251e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 252e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 253e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 254e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani Log.w(TAG, "Could not get user restrictions", re); 255e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return Bundle.EMPTY; 256e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 257e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 258e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 25971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 26071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets all the user-wide restrictions for this user. 261ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 26271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param restrictions the Bundle containing all the restrictions. 26371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 264e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 265e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani setUserRestrictions(restrictions, Process.myUserHandle()); 266e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 267e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 26871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 26971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets all the user-wide restrictions for the specified user. 270ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 27171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param restrictions the Bundle containing all the restrictions. 27271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to set the restrictions. 27371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 274e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 275e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 276e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani mService.setUserRestrictions(restrictions, userHandle.getIdentifier()); 277e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 278e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani Log.w(TAG, "Could not set user restrictions", re); 279e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 280e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 281e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 28271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 28371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 284ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 28571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 28671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 28771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 28871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 28971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani Bundle bundle = getUserRestrictions(); 29071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani bundle.putBoolean(key, value); 29171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani setUserRestrictions(bundle); 29271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 29371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 29471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 29571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 29671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 29771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Requires the {@link android.Manifest.permission#MANAGE_USERS} permission. 29871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 29971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 30071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 30171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 3026794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 3036794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall Bundle bundle = getUserRestrictions(userHandle); 3046794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall bundle.putBoolean(key, value); 3056794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall setUserRestrictions(bundle, userHandle); 3066794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 3076794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 308258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 309a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @hide 310a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 311a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 312a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @param restrictionKey the string key representing the restriction 313a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 314a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 315a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall return getUserRestrictions().getBoolean(restrictionKey, false); 316a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 317a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 318a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 31933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 320b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 321b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 32233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 323b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 324b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 32533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 32633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 32733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 32833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 32933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 33033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 33133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 33233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 33333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 33433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 33533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 33633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 33733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 33833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 33933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 34033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 34133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn int ident = getUserHandle((int)serialNumber); 34233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 34333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 34433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 34533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 346258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Creates a user with the specified name and options. 3471952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 348258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 349258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 350258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 351258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 352258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 353258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 354258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 355258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 356258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 357258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 358258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.createUser(name, flags); 359258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 360258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not create a user", re); 361258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 362258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 363258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 364258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 365258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 366b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 367b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 368b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 369b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 370b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 371b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 372b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 373b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 374258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns information for all users on this device. 3751952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 376258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the list of users that were created. 377258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 378258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 379258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 380258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 381920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 382920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 383920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani Log.w(TAG, "Could not get user list", re); 384920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return null; 385920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 386920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 387920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 388920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 389920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * Returns information for all users on this device. 390920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 391920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @param excludeDying specify if the list should exclude users being removed. 392920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 393920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 394920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 395920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani public List<UserInfo> getUsers(boolean excludeDying) { 396920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 397920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 399258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user list", re); 400258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 401258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 402258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 403258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 404258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 405258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 4061952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 407258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 408258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 409258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public boolean removeUser(int userHandle) { 411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 413258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 414258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not remove user ", re); 415258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return false; 416258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 417258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 418258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 419258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 420258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 4211952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 422258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 423258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 424258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 425258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 426258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 427258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void setUserName(int userHandle, String name) { 428258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 429258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 430258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 431258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user name ", re); 432258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 433258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 434258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 435258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 436e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 437258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 438e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 439258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 440258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 441e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public void setUserIcon(int userHandle, Bitmap icon) { 442258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 443e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 444258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 445258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user icon ", re); 446258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 448258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 449258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 4503b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 4513b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 452e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 4533b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 4543b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 455e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public Bitmap getUserIcon(int userHandle) { 4563b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 4573b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani return mService.getUserIcon(userHandle); 4583b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 459e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani Log.w(TAG, "Could not get the user icon ", re); 4603b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani return null; 4613b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 4623b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 4633b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 4643b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 465258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Enable or disable the use of a guest account. If disabled, the existing guest account 466258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * will be wiped. 4671952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 468258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param enable whether to enable a guest account. 469258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 470258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 471258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void setGuestEnabled(boolean enable) { 472258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 473258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setGuestEnabled(enable); 474258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 475258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not change guest account availability to " + enable); 476258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 477258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 478258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 479258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 480258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Checks if a guest user is enabled for this device. 4811952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 482258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return whether a guest user is enabled 483258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 484258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 485258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public boolean isGuestEnabled() { 486258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 487258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.isGuestEnabled(); 488258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 489258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not retrieve guest enabled state"); 490258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return false; 491258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 492258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 493258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 494258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 495258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Wipes all the data for a user, but doesn't remove the user. 4961952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 497258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle 498258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 499258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 500258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void wipeUser(int userHandle) { 501258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 502258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.wipeUser(userHandle); 503258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 504258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not wipe user " + userHandle); 505258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 506258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 507258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 508258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 509258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 510258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 512a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 513258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 51427bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 515ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 516ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 51727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 51827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 519258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 5202a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 5212a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 5222a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 5232a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 5242a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 5252a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 5262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 5272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 5282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserSerialNumber(int userHandle) { 5292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 5302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 5312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 5322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get serial number for user " + userHandle); 5332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 5342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 5352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 5362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 5372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 5382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 5392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 5402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 5412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 5422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 5432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 5442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 5452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 5462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserHandle(int userSerialNumber) { 5472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 5482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 5492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 5502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); 5512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 5522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 5532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 5546794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 555df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 556df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 557df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 558df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 559df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani public List<RestrictionEntry> getApplicationRestrictions(String packageName, UserHandle user) { 560df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 561df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return mService.getApplicationRestrictions(packageName, user.getIdentifier()); 562df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 563df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); 564df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 565df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return null; 566df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 567df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 568df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 569df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 570df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 571df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani public void setApplicationRestrictions(String packageName, List<RestrictionEntry> entries, 572df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 573df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 574df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani mService.setApplicationRestrictions(packageName, entries, user.getIdentifier()); 575df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 576df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); 577df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 578df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 579258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 580