UserManager.java revision 1a447535cef7e3739d5f763dfe13e568568b9789
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; 20258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 2127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 226794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 23258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log; 24258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 256794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 266794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 27258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 28258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 29258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 30258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system. 31258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 32258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 34258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private static String TAG = "UserManager"; 35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 36258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 37258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 38e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 3971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from adding and removing 4071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * accounts. 4171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 4271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 43e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 44e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 45e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 46e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 4771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 48e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 49e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 5071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from changing Wi-Fi 5171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * access points. 5271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 5371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 54e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 55e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 56e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 57e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 5871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 59e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 60e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 6171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from installing applications. 6271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 6371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 66e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 67e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 6871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 69e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 70e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 7171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from uninstalling applications. 7271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 7371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * Type: Boolean 75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #setUserRestrictions(Bundle) 76e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 7871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 79e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 8171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Key for user restrictions. Specifies if a user is disallowed from toggling location sharing. 8271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 8371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * <p/> 846794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * Type: Boolean 856794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #setUserRestrictions(Bundle) 866794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 876794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 88a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 8971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 906794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 91a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 92a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from enabling the 93a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 94a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 95a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 96a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 97a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 98a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 99a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 100a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 101a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 102a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 103a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth. 104a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 105a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 106a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 107a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 108a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 109a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 110a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 111a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 112a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 113a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Key for user restrictions. Specifies if a user is disallowed from transferring files over 114a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * USB. The default value is <code>false</code>. 115a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * <p/> 116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Type: Boolean 117a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #setUserRestrictions(Bundle) 118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 120a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 121a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 122b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 123b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * Key for user restrictions. Specifies if a user is disallowed from configuring user 124b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * credentials. The default value is <code>false</code>. 125b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * <p/> 126b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * Type: Boolean 127b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #setUserRestrictions(Bundle) 128b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 129b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 130b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 131b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 132b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 133b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * Key for user restrictions. Specifies if a user is disallowed from removing users. 134b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * The default value is <code>false</code>. 135b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * <p/> 136b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * Type: Boolean 137b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #setUserRestrictions(Bundle) 138b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 139b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 140b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 141b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 142655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 143655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 144655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 145655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 146655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 147655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_SUCCESS = -1; 148655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 14927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani private static UserManager sInstance = null; 15027db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani 1517e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** @hide */ 15227db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani public synchronized static UserManager get(Context context) { 15327db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani if (sInstance == null) { 15427db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani sInstance = (UserManager) context.getSystemService(Context.USER_SERVICE); 15527db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 15627db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani return sInstance; 15727db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 158a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 159258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 160258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 161258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 162258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mContext = context; 163258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 164258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 165258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 166258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns whether the system supports multiple users. 1671a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if multiple users can be created by user, false if it is a single user device. 168e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @hide 169258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1704673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 1711a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return getMaxSupportedUsers() > 1 1721a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy && SystemProperties.getBoolean("fw.show_multiuserui", 1731a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 174258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 175258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1766794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 177258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the user handle for the user that this application is running for. 178258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user handle of the user making this call. 179258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1806794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 181258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public int getUserHandle() { 18279af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 183258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 184258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 185258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1868832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 1878832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 1888832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 189258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 190258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 191258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 192258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 193258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 194258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 195258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user name", re); 196258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return ""; 197258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 198258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 199258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 200e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill /** 201e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 202e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 203a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return whether the user making this call is a goat 204e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 205e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 206e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill return false; 207e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 208df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 209df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 210e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * Used to check if the user making this call is linked to another user. Linked users may have 21146bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani * a reduced number of available apps, app restrictions and account restrictions. 212e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * @return whether the user making this call is a linked user 2132555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani * @hide 214df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 215e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani public boolean isLinkedUser() { 216df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 21771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 218df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 21946bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani Log.w(TAG, "Could not check if user is limited ", re); 220df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return false; 221df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 222df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 223df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 224258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 225a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 226a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 227a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 228a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 229a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 230a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 231a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 232a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 233a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 234a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 235a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), false); 236a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 237a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 238a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 239a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 240a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 241a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 242a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 243a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 244a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 245a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 246a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 247a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 248a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 249a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 250a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 251a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), true); 252a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 253a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 254a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 255a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 256a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 257a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 258258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 2591952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 260258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 261258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 262258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 263b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 264258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo getUserInfo(int userHandle) { 265258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 266258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 267258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 268258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user info", re); 269258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 270258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 271258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 272258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 27371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 27471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 27571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 27671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 277e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 278e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 279e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 280e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 28171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 28271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 28371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 28471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 28571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 286e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 287e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 288e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 289e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 290e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani Log.w(TAG, "Could not get user restrictions", re); 291e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return Bundle.EMPTY; 292e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 293e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 294e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 29571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 29671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets all the user-wide restrictions for this user. 297ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 29871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param restrictions the Bundle containing all the restrictions. 29971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 300e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 301e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani setUserRestrictions(restrictions, Process.myUserHandle()); 302e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 303e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 30471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 30571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets all the user-wide restrictions for the specified user. 306ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 30771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param restrictions the Bundle containing all the restrictions. 30871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to set the restrictions. 30971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 310e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 311e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 312e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani mService.setUserRestrictions(restrictions, userHandle.getIdentifier()); 313e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 314e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani Log.w(TAG, "Could not set user restrictions", re); 315e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 316e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 317e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 31871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 31971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 320ca050adc13b48c58c978255dd5ce6d9654549cb0Amith Yamasani * Requires the MANAGE_USERS permission. 32171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 32271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 32371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 32471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 32571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani Bundle bundle = getUserRestrictions(); 32671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani bundle.putBoolean(key, value); 32771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani setUserRestrictions(bundle); 32871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 32971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 33071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 33171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 33271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 33371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Requires the {@link android.Manifest.permission#MANAGE_USERS} permission. 33471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 33571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 33671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 33771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 3386794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 3396794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall Bundle bundle = getUserRestrictions(userHandle); 3406794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall bundle.putBoolean(key, value); 3416794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall setUserRestrictions(bundle, userHandle); 3426794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 3436794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 344258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 345a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @hide 346a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 347a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 348a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @param restrictionKey the string key representing the restriction 349a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 350a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 351b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return hasUserRestriction(restrictionKey, Process.myUserHandle()); 352b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie } 353b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie 354b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie /** 355b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @hide 356b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * Returns whether the given user has been disallowed from performing certain actions 357b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * or setting certain settings. 358b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param restrictionKey the string key representing the restriction 359b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 360b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie */ 361b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 362b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return getUserRestrictions(userHandle).getBoolean(restrictionKey, false); 363a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 364a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 365a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 36633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 367b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 368b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 36933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 370b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 371b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 37233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 37333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 37433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 37533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 37633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 37733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 37833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 37933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 38033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 38133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 38233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 38333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 38433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 38533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 38633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 38733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 38833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn int ident = getUserHandle((int)serialNumber); 38933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 39033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 39133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 39233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 393258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Creates a user with the specified name and options. 3941952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 395258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 396258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 397258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 398258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 399258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 400258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 401258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 402258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 403258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 404258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 405258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.createUser(name, flags); 406258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 407258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not create a user", re); 408258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 409258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 410258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 411258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 412258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 413a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Creates a user with the specified name and options. 414a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 415a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 416a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param name the user's name 417a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param flags flags that identify the type of user and other properties. 418a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @see UserInfo 419a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param relatedUserId new user will be related to this user id. 420a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 421a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @return the UserInfo object for the created user, or null if the user could not be created. 422a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 423a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 424a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy public UserInfo createRelatedUser(String name, int flags, int relatedUserId) { 425a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 426a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return mService.createRelatedUser(name, flags, relatedUserId); 427a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 428a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy Log.w(TAG, "Could not create a user", re); 429a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return null; 430a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 431a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 432a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 433a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 434b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 435b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 436b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 437b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 438b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 439b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 440b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 441b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 442258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns information for all users on this device. 4431952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 444258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the list of users that were created. 445258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 446258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 447258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 448258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 449920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 450920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 451920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani Log.w(TAG, "Could not get user list", re); 452920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return null; 453920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 454920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 455920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 456920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 457a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Returns information for all users related to userId 458a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 459a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param userHandle users related to this user id will be returned. 460a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @return the list of related users. 461a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 462a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 463a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy public List<UserInfo> getRelatedUsers(int userHandle) { 464a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 465a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return mService.getRelatedUsers(userHandle); 466a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 467a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy Log.w(TAG, "Could not get user list", re); 468a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return null; 469a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 470a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 471a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 472a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 473920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * Returns information for all users on this device. 474920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 475920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @param excludeDying specify if the list should exclude users being removed. 476920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 477920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 478920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 479920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani public List<UserInfo> getUsers(boolean excludeDying) { 480920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 481920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 482258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 483258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user list", re); 484258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 485258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 486258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 487258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 488258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 489258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 4901952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 491258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 492258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 493258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 494258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public boolean removeUser(int userHandle) { 495258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 496258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 497258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 498258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not remove user ", re); 499258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return false; 500258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 501258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 502258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 503258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 504258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 5051952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 506258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 507258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 508258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 509258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 510258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 511258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void setUserName(int userHandle, String name) { 512258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 513258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 514258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 515258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user name ", re); 516258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 517258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 518258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 519258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 520e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 521258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 522e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 523258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 524258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 525e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public void setUserIcon(int userHandle, Bitmap icon) { 526258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 527e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 528258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 529258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user icon ", re); 530258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 531258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 532258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 533258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 5343b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 5353b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 536e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 5373b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 5383b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 539e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public Bitmap getUserIcon(int userHandle) { 5403b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 5413b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani return mService.getUserIcon(userHandle); 5423b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 543e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani Log.w(TAG, "Could not get the user icon ", re); 5443b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani return null; 5453b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 5463b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 5473b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 5483b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 549258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Enable or disable the use of a guest account. If disabled, the existing guest account 550258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * will be wiped. 5511952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param enable whether to enable a guest account. 553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void setGuestEnabled(boolean enable) { 556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setGuestEnabled(enable); 558258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 559258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not change guest account availability to " + enable); 560258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 561258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 562258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 563258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 564258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Checks if a guest user is enabled for this device. 5651952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 566258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return whether a guest user is enabled 567258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 568258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 569258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public boolean isGuestEnabled() { 570258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 571258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.isGuestEnabled(); 572258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 573258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not retrieve guest enabled state"); 574258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return false; 575258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 576258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 577258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 578258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 579258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Wipes all the data for a user, but doesn't remove the user. 5801952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 581258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle 582258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 583258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 584258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void wipeUser(int userHandle) { 585258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 586258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.wipeUser(userHandle); 587258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 588258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not wipe user " + userHandle); 589258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 590258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 591258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 592258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 593258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 594258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 595258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 596a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 597258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 59827bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 599ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 600ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 60127bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 60227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 603258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 6042a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 6052a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 6061a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * Returns true if the user switcher should be shown, this will be if there 6071a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * are multiple users that aren't managed profiles. 6081a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @hide 6091a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if user switcher should be shown. 6101a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy */ 6111a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy public boolean isUserSwitcherEnabled() { 6121a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy List<UserInfo> users = getUsers(true); 6131a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (users == null) { 6141a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return false; 6151a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 6161a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy int switchableUserCount = 0; 6171a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy for (UserInfo user : users) { 6181a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (user.supportsSwitchTo()) { 6191a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy ++switchableUserCount; 6201a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 6211a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 6221a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return switchableUserCount > 1; 6231a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 6241a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy 6251a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy /** 6262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 6272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 6282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 6292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 6302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 6312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 6322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserSerialNumber(int userHandle) { 6332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 6342a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 6352a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 6362a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get serial number for user " + userHandle); 6372a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 6382a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 6392a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 6402a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 6412a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 6422a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 6432a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 6442a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 6452a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 6462a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 6472a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 6482a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 6492a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 6502a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserHandle(int userSerialNumber) { 6512a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 6522a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 6532a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 6542a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); 6552a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 6562a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 6572a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 6586794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 6597e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** 6607e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * Returns a Bundle containing any saved application restrictions for this user, for the 6617e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * given package name. Only an application with this package name can call this method. 6627e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @param packageName the package name of the calling application 6637e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @return a Bundle with the restrictions as key/value pairs, or null if there are no 6647e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * saved restrictions. The values can be of type Boolean, String or String[], depending 6657e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * on the restriction type, as defined by the application. 6667e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani */ 6677e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName) { 6687e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani try { 6697e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictions(packageName); 6707e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } catch (RemoteException re) { 6717e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani Log.w(TAG, "Could not get application restrictions for package " + packageName); 6727e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 6737e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return null; 6747e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 675df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 676df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 677df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 678df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 6797e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 680df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 6817e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 682df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 683df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); 684df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 685df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return null; 686df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 687df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 688df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 689df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 690df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 6917e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public void setApplicationRestrictions(String packageName, Bundle restrictions, 692df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 693df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 6947e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 695df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 696df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); 697df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 698df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 699655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 700655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 701d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 702d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * apps and requires the MANAGE_USERS permission. 703d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @param newPin the PIN to use for challenge dialogs. 704d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @return Returns true if the challenge PIN was set successfully. 705655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 706d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean setRestrictionsChallenge(String newPin) { 707655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani try { 708d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani return mService.setRestrictionsChallenge(newPin); 709655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } catch (RemoteException re) { 710655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani Log.w(TAG, "Could not change restrictions pin"); 711655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 712655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 713655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 714655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 715655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 716655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * @hide 717655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * @param pin The PIN to verify, or null to get the number of milliseconds to wait for before 718655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * allowing the user to enter the PIN. 719655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * @return Returns a positive number (including zero) for how many milliseconds before 720655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * you can accept another PIN, when the input is null or the input doesn't match the saved PIN. 721655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * Returns {@link #PIN_VERIFICATION_SUCCESS} if the input matches the saved PIN. Returns 722655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * {@link #PIN_VERIFICATION_FAILED_NOT_SET} if there is no PIN set. 723655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 724d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public int checkRestrictionsChallenge(String pin) { 725655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani try { 726d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani return mService.checkRestrictionsChallenge(pin); 727655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } catch (RemoteException re) { 728655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani Log.w(TAG, "Could not check restrictions pin"); 729655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 730655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return PIN_VERIFICATION_FAILED_INCORRECT; 731655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 732655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 733655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 734d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @hide 735655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * Checks whether the user has restrictions that are PIN-protected. An application that 736655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * participates in restrictions can check if the owner has requested a PIN challenge for 737655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * any restricted operations. If there is a PIN in effect, the application should launch 738d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * the PIN challenge activity {@link android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE}. 739d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @see android.content.Intent#ACTION_RESTRICTIONS_CHALLENGE 740655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani * @return whether a restrictions PIN is in effect. 741655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 742d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean hasRestrictionsChallenge() { 743655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani try { 744d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani return mService.hasRestrictionsChallenge(); 745655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } catch (RemoteException re) { 746655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani Log.w(TAG, "Could not change restrictions pin"); 747655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 748655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 749655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 7501a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani 7511a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani /** @hide */ 7521a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani public void removeRestrictions() { 7531a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani try { 7541a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani mService.removeRestrictions(); 7551a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani } catch (RemoteException re) { 7561a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani Log.w(TAG, "Could not change restrictions pin"); 7571a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani } 7581a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani } 759258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 760