UserManager.java revision 07387fedfafa72bcb68defd801eef82f1f494d7c
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 1802cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolovimport android.accounts.AccountManager; 197cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chenimport android.annotation.Nullable; 200e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasaniimport android.annotation.SystemApi; 21409297da182267465adbc21cfb75a23e8d678117Dianne Hackbornimport android.app.ActivityManager; 22a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackbornimport android.app.ActivityManagerNative; 23cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolovimport android.app.admin.DevicePolicyManager; 24068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onukiimport android.content.ComponentName; 25258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.Context; 26258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.content.pm.UserInfo; 2727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkeyimport android.content.res.Resources; 286794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport android.graphics.Bitmap; 291bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport android.graphics.BitmapFactory; 304f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.Rect; 314f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport android.graphics.drawable.Drawable; 321e9c21871e81642669079cd290ef47818a3165bdAmith Yamasaniimport android.provider.Settings; 33258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport android.util.Log; 341c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monkimport android.view.WindowManager.LayoutParams; 35258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 366794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthallimport com.android.internal.R; 376794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 381bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roosimport java.io.IOException; 394f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasaniimport java.util.ArrayList; 40258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasaniimport java.util.List; 41258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 42258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani/** 43258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Manages users and user details on a multi-user system. 44258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 45258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasanipublic class UserManager { 46258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 47258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private static String TAG = "UserManager"; 48258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final IUserManager mService; 49258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani private final Context mContext; 50258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 51e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 5253019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Specifies if a user is disallowed from adding and removing accounts, unless they are 5353019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * {@link android.accounts.AccountManager#addAccountExplicitly programmatically} added by 5453019287fd4fed9837363cff4de87100d85c2b81Fyodor Kupolov * Authenticator. 5571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 5626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 5726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 5826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 59068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 60068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 61e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 62e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 6371e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts"; 64e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 65e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 6626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from changing Wi-Fi 672cb384f42569f36e19ecee60da259d69048fdd85Julia Reynolds * access points. The default value is <code>false</code>. 68150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect in a managed profile. 6926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 7026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 7126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 72068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 73068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 74e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 75e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 7671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_CONFIG_WIFI = "no_config_wifi"; 77e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 78e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 7926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from installing applications. 8071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 8126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 8226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 8326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 84068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 85068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 86e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 87e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 8871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_INSTALL_APPS = "no_install_apps"; 89e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 90e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani /** 9126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from uninstalling applications. 9271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 9326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 9426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 9526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 96068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 97068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 98e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani * @see #getUserRestrictions() 99e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani */ 10071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps"; 101e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 10271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 103150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * Specifies if a user is disallowed from turning on location sharing. 10471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * The default value is <code>false</code>. 105150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>In a managed profile, location sharing always reflects the primary user's setting, but 106150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * can be overridden and forced off by setting this restriction to true in the managed profile. 10726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 10826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 10926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 110068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 111068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 1126794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall * @see #getUserRestrictions() 1136794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 11471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public static final String DISALLOW_SHARE_LOCATION = "no_share_location"; 1156794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 116a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 11726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling the 118a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * "Unknown Sources" setting, that allows installation of apps from unknown sources. 119a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 12026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 12126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 12226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 123068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 124068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 125a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 126a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 127a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources"; 128a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 129a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 13026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring bluetooth. 1311c4c442e4540b16aed7acc345aea26ab101efbf8Nicolas Prevot * This does <em>not</em> restrict the user from turning bluetooth on or off. 132a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * The default value is <code>false</code>. 133150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect in a managed profile. 13426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 13526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 13626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 137068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 138068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 139a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 140a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 141a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; 142a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 143a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 14426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from transferring files over 145c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * USB. This can only be set by device owners and profile owners on the primary user. 146c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 14726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 14826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 14926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 150068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 151068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 152a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @see #getUserRestrictions() 153a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 154a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer"; 155a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 156b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 15726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring user 158b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * credentials. The default value is <code>false</code>. 15926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 16026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 16126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 162068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 163068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 164b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 165b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 166b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; 167b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 168b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier /** 169150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on the primary user this specifies if the user can remove other users. 170150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * When set on a secondary user, this specifies if the user can remove itself. 171150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * This restriction has no effect on managed profiles. 172150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * The default value is <code>false</code>. 17326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 17426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 17526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 176068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 177068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 178b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier * @see #getUserRestrictions() 179b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier */ 180b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier public static final String DISALLOW_REMOVE_USER = "no_remove_user"; 181b223f73a69f76f5e32a0bca267f945f464776f9dEmily Bernier 182d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 18326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from enabling or 184d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * accessing debugging features. The default value is <code>false</code>. 18526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 18626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 18726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 188068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 189068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 190d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 191d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 192d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_DEBUGGING_FEATURES = "no_debugging_features"; 193d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 194d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 19526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring VPN. 196d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * The default value is <code>false</code>. 197298f98fa234f353267ddc9c75d58e8cc542c25f1Nicolas Prevot * This restriction has an effect in a managed profile only from 1980e3de6cacaffcfeda4d6353be61e2f1f9ed80705Dianne Hackborn * {@link android.os.Build.VERSION_CODES#M} 19926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 20026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 20126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 202068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 203068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 204d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 205d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 206d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_VPN = "no_config_vpn"; 207d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 208d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 20926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring Tethering 210c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * & portable hotspots. This can only be set by device owners and profile owners on the 211c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 21226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 21326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 21426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 215068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 216068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 217d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 218d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 219d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_TETHERING = "no_config_tethering"; 220d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 221d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 222e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * Specifies if a user is disallowed from resetting network settings 223e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * from Settings. This can only be set by device owners and profile owners on the primary user. 224e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * The default value is <code>false</code>. 225e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * <p/>This restriction has no effect on secondary users and managed profiles since only the 226e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * primary user can reset the network settings of the device. 227e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * 228e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * <p/>Key for user restrictions. 229e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * <p/>Type: Boolean 230068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 231068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 232e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott * @see #getUserRestrictions() 233e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott */ 234e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott public static final String DISALLOW_NETWORK_RESET = "no_network_reset"; 235e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott 236e3e314df4d52881225326d426a76e3e7f1bc40d3Stuart Scott /** 23726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from factory resetting 238c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * from Settings. This can only be set by device owners and profile owners on the primary user. 239c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 240150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect on secondary users and managed profiles since only the 241150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can factory reset the device. 24226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 24326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 24426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 245068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 246068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 247d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 248d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 249d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_FACTORY_RESET = "no_factory_reset"; 250d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 251d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 25226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adding new users and 253c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * profiles. This can only be set by device owners and profile owners on the primary user. 254c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 255150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect on secondary users and managed profiles since only the 256150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can add other users. 25726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 25826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 25926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 260068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 261068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 262d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 263d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 264d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_ADD_USER = "no_add_user"; 265d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 266d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 26726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from disabling application 268d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * verification. The default value is <code>false</code>. 26926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 27026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 27126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 272068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 273068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 274d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 275d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 276d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String ENSURE_VERIFY_APPS = "ensure_verify_apps"; 277d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 278d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 27926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring cell 280c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * broadcasts. This can only be set by device owners and profile owners on the primary user. 281c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 282150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect on secondary users and managed profiles since only the 283150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure cell broadcasts. 28426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 28526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 28626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 287068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 288068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 289d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 290d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 291d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; 292d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 293d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 29426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from configuring mobile 295c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * networks. This can only be set by device owners and profile owners on the primary user. 296c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 297150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect on secondary users and managed profiles since only the 298150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * primary user can configure mobile networks. 29926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 30026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 30126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 302068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 303068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 304d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 305d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 306d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds public static final String DISALLOW_CONFIG_MOBILE_NETWORKS = "no_config_mobile_networks"; 307d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 308d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds /** 30926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from modifying 310c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * applications in Settings or launchers. The following actions will not be allowed when this 311c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * restriction is enabled: 312c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>uninstalling apps</li> 313c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>disabling apps</li> 314c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app caches</li> 315c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app data</li> 316c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>force stopping apps</li> 317c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <li>clearing app defaults</li> 318c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * <p> 319c617f815453b6e70a0165924907e69a0f993e651Julia Reynolds * The default value is <code>false</code>. 32026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 32126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 32226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 323068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 324068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 325d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds * @see #getUserRestrictions() 326d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds */ 32736fbc8d6453da438a8ab83352ff1bcfcba5f25b5Julia Reynolds public static final String DISALLOW_APPS_CONTROL = "no_control_apps"; 328d46d0f9dcd72dfaa93a57d07d896def6ce53bbaeJulia Reynolds 329394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 33026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from mounting 331c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * physical external media. This can only be set by device owners and profile owners on the 332c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * primary user. The default value is <code>false</code>. 33326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 33426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 33526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 336068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 337068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 338394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 339394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 340394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_MOUNT_PHYSICAL_MEDIA = "no_physical_media"; 341394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 342394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 34326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting microphone 344c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the microphone will be muted. This can only be set by device owners 345c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 34626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 34726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 34826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 349068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 350068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 351394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 352394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 353394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_UNMUTE_MICROPHONE = "no_unmute_microphone"; 354394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 355394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier /** 35626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if a user is disallowed from adjusting the master 357c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * volume. If set, the master volume will be muted. This can only be set by device owners 358c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * and profile owners on the primary user. The default value is <code>false</code>. 35926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 36026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 36126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 362068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 363068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 364394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * @see #getUserRestrictions() 365394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier */ 366394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier public static final String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; 367394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier 3689f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani /** 36926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to make outgoing 370390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * phone calls. Emergency calls are still permitted. 371390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * The default value is <code>false</code>. 372150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * <p/>This restriction has no effect on managed profiles since call intents are normally 373150514bd03312ab0a890cc040019cfbc73eb077cAmith Yamasani * forwarded to the primary user. 37426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 37526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 37626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 377068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 378068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 379390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani * @see #getUserRestrictions() 380390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani */ 381390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; 382390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani 383390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani /** 38426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that the user is not allowed to send or receive 385c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * SMS messages. The default value is <code>false</code>. 38626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 38726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 38826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 389068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 390068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 3919f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani * @see #getUserRestrictions() 3929f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani */ 393390989da1967f9d385212cd2e22a50589ce69046Amith Yamasani public static final String DISALLOW_SMS = "no_sms"; 3949f6c25f57e26f3e2f9c744547a139d14b7d3db5cAmith Yamasani 3951c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk /** 3962cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * Specifies if the user is not allowed to have fun. In some cases, the 3972cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * device owner may wish to prevent the user from experiencing amusement or 3982cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * joy while using the device. The default value is <code>false</code>. 3992cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * 4002cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * <p/>Key for user restrictions. 4012cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * <p/>Type: Boolean 402068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 403068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4042cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey * @see #getUserRestrictions() 4052cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey */ 4062cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey public static final String DISALLOW_FUN = "no_fun"; 4072cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey 4082cc03e5606ad7cd473283898400506d5ac2237baJeff Sharkey /** 40926af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies that windows besides app windows should not be 4101c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * created. This will block the creation of the following types of windows. 4111c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_TOAST}</li> 4121c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PHONE}</li> 4131c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_PRIORITY_PHONE}</li> 4141c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ALERT}</li> 4151c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_ERROR}</li> 4161c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * <li>{@link LayoutParams#TYPE_SYSTEM_OVERLAY}</li> 4171c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * 418c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * <p>This can only be set by device owners and profile owners on the primary user. 419c34dc7cdeb5cae8ca4c731838aafe90ed4c9a2b8Amith Yamasani * The default value is <code>false</code>. 42026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 42126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 42226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 423068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 424068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 4251c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk * @see #getUserRestrictions() 4261c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk */ 4271c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk public static final String DISALLOW_CREATE_WINDOWS = "no_create_windows"; 4281c7c319bb89b9988bfd12afc3e8d89449fd163fcJason Monk 429f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot /** 43026af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if what is copied in the clipboard of this profile can 431f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * be pasted in related profiles. Does not restrict if the clipboard of related profiles can be 432f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * pasted in this profile. 433f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * The default value is <code>false</code>. 43426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 43526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 43626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 437068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 438068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 439f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot * @see #getUserRestrictions() 440f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot */ 441f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot public static final String DISALLOW_CROSS_PROFILE_COPY_PASTE = "no_cross_profile_copy_paste"; 442f1939901d2ed0480069f0b23be64f122fce93995Nicolas Prevot 44326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani /** 44426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * Specifies if the user is not allowed to use NFC to beam out data from apps. 44526af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * The default value is <code>false</code>. 44626af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * 44726af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Key for user restrictions. 44826af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * <p/>Type: Boolean 449068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 450068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 45126af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani * @see #getUserRestrictions() 45226af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani */ 45326af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani public static final String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; 45426af829fd70609cf073b56e54e1f78faf83a5e8bAmith Yamasani 45553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse /** 456f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * Hidden user restriction to disallow access to wallpaper manager APIs. This user restriction 457f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * is always set for managed profiles. 458f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @hide 459068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 460068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 461f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz * @see #getUserRestrictions() 462f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz */ 463f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz public static final String DISALLOW_WALLPAPER = "no_wallpaper"; 464f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz 465f3ece36535d4999cf2bfd2175a33da6c3cdf298eBenjamin Franz /** 466bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * Specifies if the user is not allowed to reboot the device into safe boot mode. 467bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * This can only be set by device owners and profile owners on the primary user. 468bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * The default value is <code>false</code>. 469bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * 470bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * <p/>Key for user restrictions. 471bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * <p/>Type: Boolean 472068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 473068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 474bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz * @see #getUserRestrictions() 475bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz */ 476bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz public static final String DISALLOW_SAFE_BOOT = "no_safe_boot"; 477bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz 478bff46bac807ae8a9ebdc22c449a8d4f78711b4d2Benjamin Franz /** 479b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * Specifies if a user is not allowed to record audio. This restriction is always enabled for 480b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * background users. The default value is <code>false</code>. 481b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * 482068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 483068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 484b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @see #getUserRestrictions() 485b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov * @hide 486b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov */ 487b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov public static final String DISALLOW_RECORD_AUDIO = "no_record_audio"; 488b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov 489b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov /** 490759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * Specifies if a user is not allowed to use the camera. 491759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * 492759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 493759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 494759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @see #getUserRestrictions() 495759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki * @hide 496759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki */ 497759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki public static final String DISALLOW_CAMERA = "no_camera"; 498759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki 499759a763f5f03fda86b96d238faedb870fbee24ecMakoto Onuki /** 500f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * Allows apps in the parent profile to handle web links from the managed profile. 501f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot * 5029edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * This user restriction has an effect only in a managed profile. 5039edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * If set: 5049edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * Intent filters of activities in the parent profile with action 5059edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * {@link android.content.Intent#ACTION_VIEW}, 5069edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * category {@link android.content.Intent#CATEGORY_BROWSABLE}, scheme http or https, and which 5079edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * define a host can handle intents from the managed profile. 5089edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * The default value is <code>false</code>. 5099edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * 5109edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * <p/>Key for user restrictions. 5119edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * <p/>Type: Boolean 512068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#addUserRestriction(ComponentName, String) 513068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) 5149edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot * @see #getUserRestrictions() 5159edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot */ 516f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot public static final String ALLOW_PARENT_PROFILE_APP_LINKING 517f0029c1ddb2875583e62c6a3f96d288e21f2efe2Nicolas Prevot = "allow_parent_profile_app_linking"; 5189edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot 5199edbda18df025527e18614cf0c45d538a27af30fNicolas Prevot /** 52053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Application restriction key that is used to indicate the pending arrival 52153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * of real restrictions for the app. 52253d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 52353d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p> 52453d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * Applications that support restrictions should check for the presence of this key. 52553d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * A <code>true</code> value indicates that restrictions may be applied in the near 52653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * future but are not available yet. It is the responsibility of any 52753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * management application that sets this flag to update it when the final 52853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * restrictions are enforced. 52953d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * 53053d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p/>Key for application restrictions. 53153d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse * <p/>Type: Boolean 532b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#setApplicationRestrictions( 533b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String, Bundle) 534b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * @see android.app.admin.DevicePolicyManager#getApplicationRestrictions( 535b14ed95647ff7c38869550606396d5b784eeece1Nicolas Prevot * android.content.ComponentName, String) 53653d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse */ 53753d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse public static final String KEY_RESTRICTIONS_PENDING = "restrictions_pending"; 53853d63dcd04da3c1d5187b29f6530c2dcac9d516cSander Alewijnse 539655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 540655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3; 541655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 542655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_FAILED_NOT_SET = -2; 543655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** @hide */ 544655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani public static final int PIN_VERIFICATION_SUCCESS = -1; 545655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 5467e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** @hide */ 547c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani public static UserManager get(Context context) { 548c0688301de5feea94c8456b3b9b42c41d0045f03Amith Yamasani return (UserManager) context.getSystemService(Context.USER_SERVICE); 54927db46850b708070452c0ce49daf5f79503fbde6Amith Yamasani } 550a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 551258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** @hide */ 552258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserManager(Context context, IUserManager service) { 553258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService = service; 554258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mContext = context; 555258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 556258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 557258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 558258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns whether the system supports multiple users. 5591a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if multiple users can be created by user, false if it is a single user device. 560e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @hide 561258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 5624673e7ea8d1f869910a9c0f9c211d4d27ad50b41Jeff Sharkey public static boolean supportsMultipleUsers() { 5631a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return getMaxSupportedUsers() > 1 5641a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy && SystemProperties.getBoolean("fw.show_multiuserui", 5651a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); 566258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 567258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 5686794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall /** 5697cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @hide 5707cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * @return Whether the device is running with split system user. It means the system user and 5717cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * primary user are two separate users. Previously system user and primary user are combined as 5727cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen * a single owner user. see @link {android.os.UserHandle#USER_OWNER} 5737cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen */ 5747cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public static boolean isSplitSystemUser() { 5757cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen return SystemProperties.getBoolean("ro.fw.system_user_split", false); 5767cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen } 5777cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen 5787cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen /** 5795760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Returns the user handle for the user that this process is running under. 580be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 5815760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return the user handle of this process. 582258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 5836794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall */ 584258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public int getUserHandle() { 58579af1dd54c16cde063152922b42c96d72ae9eca8Dianne Hackborn return UserHandle.myUserId(); 586258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 587258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 588258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 5898832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * Returns the user name of the user making this call. This call is only 5908832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * available to applications on the system image; it requires the 5918832c18d8b63367929c2d394c9c508f56003d400Dianne Hackborn * MANAGE_USERS permission. 592258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the user name 593258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 594258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public String getUserName() { 595258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 596258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(getUserHandle()).name; 597258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 598258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user name", re); 599258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return ""; 600258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 601258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 602258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 60367a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn /** 604e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * Used to determine whether the user making this call is subject to 605e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill * teleportations. 60667a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 607955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can 60867a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * now automatically identify goats using advanced goat recognition technology.</p> 60967a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * 61067a101aa3006aa2011a9d9edaacb2fa6f6f31140Dianne Hackborn * @return Returns true if the user making this call is a goat. 611e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill */ 612e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill public boolean isUserAGoat() { 613988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell return mContext.getPackageManager() 614988ae30ff7729ac0e9a44ee665c7e00f1961e7cdAdam Powell .isPackageAvailable("com.coffeestainstudios.goatsimulator"); 615e4ab16ad98b183afbf7a21ad7314372de41a8b57Dan Morrill } 616df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 617df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 61870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Used to check if this process is running under the primary user. The primary user 61970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * is the first human user on a device. 62070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 62170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return whether this process is running under the primary user. 62270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 62370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 62470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen public boolean isPrimaryUser() { 62570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen UserInfo user = getUserInfo(UserHandle.myUserId()); 62670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return user != null ? user.isPrimary() : false; 62770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 62870f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 62970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 6305760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * Used to check if this process is running under the system user. The system user 6315760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * is the initial user that is implicitly created on first boot and hosts most of the 6325760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * system services. 6335760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * 6345760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani * @return whether this process is running under the system user. 6355760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani */ 6365760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani public boolean isSystemUser() { 63770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return UserHandle.myUserId() == UserHandle.USER_SYSTEM; 6385760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani } 6392b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 6405760e1786bcc2feac9d1c2c784520aa4d6cf8cb8Amith Yamasani /** 641462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * @hide 642462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * Returns whether the caller is running as an admin user. There can be more than one admin 643462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani * user. 644462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani */ 645462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani public boolean isAdminUser() { 6462b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return isUserAdmin(UserHandle.myUserId()); 6472b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen } 6482b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen 6492b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen /** 6502b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * @hide 6512b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * Returns whether the provided user is an admin user. There can be more than one admin 6522b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen * user. 6532b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen */ 6542b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen public boolean isUserAdmin(int userId) { 6552b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen UserInfo user = getUserInfo(userId); 6562b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen return user != null && user.isAdmin(); 657462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani } 658462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani 659462ac3a2aa5e1c974d056dc7221805e2b8ac7823Amith Yamasani /** 660e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * Used to check if the user making this call is linked to another user. Linked users may have 66146bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani * a reduced number of available apps, app restrictions and account restrictions. 662e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani * @return whether the user making this call is a linked user 6632555dafce87e60fae28d71913730abf73e40fcd7Amith Yamasani * @hide 664df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 665e1375908a5f05e5c926e95049970c4505e4dfad9Amith Yamasani public boolean isLinkedUser() { 666df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 66771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani return mService.isRestricted(); 668df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 66946bc4ebb87232b39d7b02ac0135c8ccf2c33f233Amith Yamasani Log.w(TAG, "Could not check if user is limited ", re); 670df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return false; 671df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 672df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 673df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 674258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 6751c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * Checks if specified user can have restricted profile. 6761c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov * @hide 6771c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov */ 6781c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov public boolean canHaveRestrictedProfile(int userId) { 6791c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov try { 6801c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov return mService.canHaveRestrictedProfile(userId); 6811c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } catch (RemoteException re) { 6821c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov Log.w(TAG, "Could not check if user can have restricted profile", re); 6831c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov return false; 6841c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 6851c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov } 6861c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov 6871c36315a36962321dfe870b07e28b04a1d6777e9Fyodor Kupolov /** 6881e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Checks if the calling app is running as a guest user. 6891e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @return whether the caller is a guest user. 6901e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 6911e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 6921e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public boolean isGuestUser() { 6931e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 6941e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return user != null ? user.isGuest() : false; 6951e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 6961e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 6971e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani /** 6980e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Checks if the calling app is running in a managed profile. 6990e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 7000e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * 7010e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @return whether the caller is in a managed profile. 7020e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani * @hide 7030e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani */ 7040e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani @SystemApi 7050e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani public boolean isManagedProfile() { 7060e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani UserInfo user = getUserInfo(UserHandle.myUserId()); 7070e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani return user != null ? user.isManagedProfile() : false; 7080e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani } 7090e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani 7100e8d7d63ba439cc0604af7055679dae3d30fdc48Amith Yamasani /** 711a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running. This means that 712a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * the user is in the "started" state, not "stopped" -- it is currently 713a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * allowed to run code through scheduled alarms, receiving broadcasts, 714a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * etc. A started user may be either the current foreground user or a 715a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * background user; the result here does not distinguish between the two. 716a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 717a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 718a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunning(UserHandle user) { 719a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 720a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 721a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), false); 722a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 723a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 724a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 725a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 726a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 727a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 728a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * Return whether the given user is actively running <em>or</em> stopping. 729a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * This is like {@link #isUserRunning(UserHandle)}, but will also return 730a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * true if the user had been running but is in the process of being stopped 731a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * (but is not yet fully stopped, and still running some code). 732a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn * @param user The user to retrieve the running state for. 733a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn */ 734a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn public boolean isUserRunningOrStopping(UserHandle user) { 735a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn try { 736a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return ActivityManagerNative.getDefault().isUserRunning( 737a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn user.getIdentifier(), true); 738a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } catch (RemoteException e) { 739a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn return false; 740a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 741a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn } 742a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn 743a8a9bd65bf5865d83ef44f54552ca39522bfbcf0Dianne Hackborn /** 744258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the UserInfo object describing a specific user. 7451952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 746258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user handle of the user whose information is being requested. 747258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for a specific user. 748258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 749b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 750258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo getUserInfo(int userHandle) { 751258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 752258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.getUserInfo(userHandle); 753258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 754258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user info", re); 755258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 756258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 757258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 758258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 75971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 76071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on this user. 76171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 76271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 763e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions() { 764e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return getUserRestrictions(Process.myUserHandle()); 765e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 766e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 76771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 76871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Returns the user-wide restrictions imposed on the user specified by <code>userHandle</code>. 76971e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 77071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @return a Bundle containing all the restrictions. 77171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 772e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public Bundle getUserRestrictions(UserHandle userHandle) { 773e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani try { 774e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return mService.getUserRestrictions(userHandle.getIdentifier()); 775e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } catch (RemoteException re) { 776e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani Log.w(TAG, "Could not get user restrictions", re); 777e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani return Bundle.EMPTY; 778e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 779e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 780e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 78171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 782a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 783a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 78471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 785a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 7863d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 787e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions) { 788068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 789e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 790e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 79171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 792a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * This will no longer work. Device owners and profile owners should use 793a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki * {@link DevicePolicyManager#addUserRestriction(ComponentName, String)} instead. 79471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 795a3c1250a2fc36e7315b377b1babe9d03ae41721aMakoto Onuki // System apps should use UserManager.setUserRestriction() instead. 7963d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 797e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani public void setUserRestrictions(Bundle restrictions, UserHandle userHandle) { 798068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki throw new UnsupportedOperationException("This method is no longer supported"); 799e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani } 800e4cf73437a18c1444055f88a1fcc0d146ec23ac5Amith Yamasani 80171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 80271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction. 803be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 80471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 80571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 8063d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 8073d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 8083d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 8093d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 81071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 8113d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 81271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani public void setUserRestriction(String key, boolean value) { 813068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki setUserRestriction(key, value, Process.myUserHandle()); 81471e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani } 81571e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani 81671e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani /** 81771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @hide 81871e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * Sets the value of a specific restriction on a specific user. 819be46532c9fbebf3ab6498c1b78013a33f620cd31Amith Yamasani * Requires the MANAGE_USERS permission. 82071e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param key the key of the restriction 82171e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param value the value for the restriction 82271e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani * @param userHandle the user whose restriction is to be changed. 8233d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * @deprecated use {@link android.app.admin.DevicePolicyManager#addUserRestriction( 8243d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} or 8253d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * {@link android.app.admin.DevicePolicyManager#clearUserRestriction( 8263d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds * android.content.ComponentName, String)} instead. 82771e6c697e54a43d357cc25d87a446d140f17396aAmith Yamasani */ 8283d9eb78fe91ab2479eb38443aed588e10421e31bJulia Reynolds @Deprecated 8296794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall public void setUserRestriction(String key, boolean value, UserHandle userHandle) { 830b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov try { 831b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov mService.setUserRestriction(key, value, userHandle.getIdentifier()); 832b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } catch (RemoteException re) { 833b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov Log.w(TAG, "Could not set user restriction", re); 834b501330a1b6ef14ff512a5727f7a01bc423d6fbbFyodor Kupolov } 8356794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall } 8366794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 837258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 838a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * Returns whether the current user has been disallowed from performing certain actions 839a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * or setting certain settings. 8402b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * 8412b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @param restrictionKey The string key representing the restriction. 8422b2cf72f10f13d9314a1c53386188ed48e12d47cJulia Reynolds * @return {@code true} if the current user has the given restriction, {@code false} otherwise. 843a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall */ 844a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall public boolean hasUserRestriction(String restrictionKey) { 845b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie return hasUserRestriction(restrictionKey, Process.myUserHandle()); 846b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie } 847b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie 848b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie /** 849b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @hide 850b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * Returns whether the given user has been disallowed from performing certain actions 851b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * or setting certain settings. 852b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param restrictionKey the string key representing the restriction 853b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie * @param userHandle the UserHandle of the user for whom to retrieve the restrictions. 854b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie */ 855b12ba933f3db9280edcb6a3591741d29c109a4e2David Christie public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) { 8568cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani try { 8578cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani return mService.hasUserRestriction(restrictionKey, 8588cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani userHandle.getIdentifier()); 8598cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } catch (RemoteException re) { 8608cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani Log.w(TAG, "Could not check user restrictions", re); 8618cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani return false; 8628cd28b57ed732656d002d97879e15c5695b54fffAmith Yamasani } 863a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall } 864a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall 865a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall /** 86633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the serial number for a user. This is a device-unique 867b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * number assigned to that user; if the user is deleted and then a new 868b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * user created, the new users will not be given the same serial number. 86933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param user The user whose serial number is to be retrieved. 870b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * @return The serial number of the given user; returns -1 if the 871b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * given UserHandle does not exist. 87233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getUserForSerialNumber(long) 87333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 87433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public long getSerialNumberForUser(UserHandle user) { 87533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return getUserSerialNumber(user.getIdentifier()); 87633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 87733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 87833f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 87933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * Return the user associated with a serial number previously 88033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * returned by {@link #getSerialNumberForUser(UserHandle)}. 88133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @param serialNumber The serial number of the user that is being 88233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * retrieved. 88333f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @return Return the user associated with the serial number, or null 88433f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * if there is not one. 88533f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn * @see #getSerialNumberForUser(UserHandle) 88633f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn */ 88733f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn public UserHandle getUserForSerialNumber(long serialNumber) { 888ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov int ident = getUserHandle((int) serialNumber); 88933f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn return ident >= 0 ? new UserHandle(ident) : null; 89033f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn } 89133f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn 89233f9cb8cf01e0a6288eb5b9ce724c56aa4e1e382Dianne Hackborn /** 893cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * Creates a user with the specified name and options. For non-admin users, default user 894cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen * restrictions are going to be applied. 8951952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 896258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 897258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the user's name 898258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param flags flags that identify the type of user and other properties. 899258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @see UserInfo 900258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 901258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the UserInfo object for the created user, or null if the user could not be created. 902258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 903258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 904258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public UserInfo createUser(String name, int flags) { 905cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen UserInfo user = null; 906258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 907cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen user = mService.createUser(name, flags); 908cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen if (user != null && !user.isAdmin()) { 909068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_SMS, true, user.id); 910068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_OUTGOING_CALLS, true, user.id); 911cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen } 912258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 913258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not create a user", re); 914258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 915cfe64c8afa9f30d8874c72440c3992e79fdb60c9Xiaohui Chen return user; 916258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 917258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 918258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 9191e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * Creates a guest user and configures it. 9201e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param context an application context 9211e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @param name the name to set for the user 9221e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani * @hide 9231e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani */ 9241e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani public UserInfo createGuest(Context context, String name) { 925068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki UserInfo guest = null; 926068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki try { 927068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki guest = mService.createUser(name, UserInfo.FLAG_GUEST); 928068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki if (guest != null) { 929068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.putStringForUser(context.getContentResolver(), 930068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id); 931068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki 932068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_SMS, true, guest.id); 933068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki mService.setUserRestriction(DISALLOW_INSTALL_UNKNOWN_SOURCES, true, guest.id); 934bf3a9465483976dcd5692b619b47132c2b95f73eAmith Yamasani } 935068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki } catch (RemoteException re) { 936068c54a5be697c3df4657dcda33cd17c4b547710Makoto Onuki Log.w(TAG, "Could not create a user", re); 9371e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 9381e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani return guest; 9391e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani } 9401e9c21871e81642669079cd290ef47818a3165bdAmith Yamasani 941aa6634eaca707f7cbf5f5a1d75b90d8d775d254bAmith Yamasani /** 9422a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Creates a user with the specified name and options as a profile of another user. 943a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 944a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 945a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param name the user's name 946a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @param flags flags that identify the type of user and other properties. 947a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @see UserInfo 9482a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle new user will be a profile of this use. 949a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * 950a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @return the UserInfo object for the created user, or null if the user could not be created. 951a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy * @hide 952a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy */ 9532a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy public UserInfo createProfileForUser(String name, int flags, int userHandle) { 954a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 9552a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy return mService.createProfileForUser(name, flags, userHandle); 956a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 957a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy Log.w(TAG, "Could not create a user", re); 958a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return null; 959a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 960a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 961a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 962a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 96302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * Creates a restricted profile with the specified name. This method also sets necessary 96402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov * restrictions and adds shared accounts. 96506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * 96606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @param name profile's name 96706a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @return UserInfo object for the created user, or null if the user could not be created. 96806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov * @hide 96906a484adb93c6c969321147b07112684383305f6Fyodor Kupolov */ 97006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov public UserInfo createRestrictedProfile(String name) { 97106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov try { 97202cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle parentUserHandle = Process.myUserHandle(); 97302cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserInfo user = mService.createRestrictedProfile(name, 97402cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov parentUserHandle.getIdentifier()); 97502cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov if (user != null) { 97602cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov AccountManager.get(mContext).addSharedAccountsFromParentUser(parentUserHandle, 97702cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov UserHandle.of(user.id)); 97806a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 97902cb6e773b323a0d54b21f43460a23f668b7727cFyodor Kupolov return user; 98006a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } catch (RemoteException e) { 98106a484adb93c6c969321147b07112684383305f6Fyodor Kupolov Log.w(TAG, "Could not create a restricted profile", e); 98206a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 98306a484adb93c6c969321147b07112684383305f6Fyodor Kupolov return null; 98406a484adb93c6c969321147b07112684383305f6Fyodor Kupolov } 98506a484adb93c6c969321147b07112684383305f6Fyodor Kupolov 98606a484adb93c6c969321147b07112684383305f6Fyodor Kupolov /** 9871df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @hide 9881df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * Marks the guest user for deletion to allow a new guest to be created before deleting 9891df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * the current user who is a guest. 9901df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @param userHandle 9911df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani * @return 9921df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani */ 9931df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani public boolean markGuestForDeletion(int userHandle) { 9941df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani try { 9951df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani return mService.markGuestForDeletion(userHandle); 9961df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } catch (RemoteException re) { 9971df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani Log.w(TAG, "Could not mark guest for deletion", re); 9981df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani return false; 9991df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 10001df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani } 10011df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani 10021df1473008c24487701c5bc15f39ed9f9697f421Amith Yamasani /** 1003df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Sets the user as enabled, if such an user exists. 1004df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1005df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * Note that the default is true, it's only that managed profiles might not be enabled. 1006df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * 1007df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @param userHandle the id of the profile to enable 1008df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina * @hide 1009df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina */ 1010df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina public void setUserEnabled(int userHandle) { 1011df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina try { 1012df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina mService.setUserEnabled(userHandle); 1013df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } catch (RemoteException e) { 1014df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina Log.w(TAG, "Could not enable the profile", e); 1015df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1016df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina } 1017df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina 1018df35d570ed25257c6782e632ab1bae5e1603855aAlexandra Gherghina /** 1019b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn * Return the number of users currently created on the device. 1020b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn */ 1021b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn public int getUserCount() { 1022b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn List<UserInfo> users = getUsers(); 1023b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn return users != null ? users.size() : 1; 1024b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn } 1025b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn 1026b26306ad5277097b3abb345112b24d9a142fb299Dianne Hackborn /** 1027258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns information for all users on this device. 10281952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1029258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @return the list of users that were created. 1030258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1031258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1032258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public List<UserInfo> getUsers() { 1033258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1034920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(false); 1035920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } catch (RemoteException re) { 1036920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani Log.w(TAG, "Could not get user list", re); 1037920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return null; 1038920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1039920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani } 1040920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani 1041920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani /** 104270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Returns information for Primary user. 104370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 104470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * 104570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @return the Primary user, null if not found. 104670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen * @hide 104770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen */ 10487cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen public @Nullable UserInfo getPrimaryUser() { 104970f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen try { 105070f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return mService.getPrimaryUser(); 105170f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } catch (RemoteException re) { 105270f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen Log.w(TAG, "Could not get Primary user", re); 105370f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen return null; 105470f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 105570f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen } 105670f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen 105770f6c38644a4a6e28c016c265e6987bf00dd61f1Xiaohui Chen /** 105895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS 105995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * permission. 106095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * 106195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @return true if more users can be added, false if limit has been reached. 106295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani * @hide 106395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani */ 106495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani public boolean canAddMoreUsers() { 106595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final List<UserInfo> users = getUsers(true); 106695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani final int totalUserCount = users.size(); 106795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani int aliveUserCount = 0; 106895ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani for (int i = 0; i < totalUserCount; i++) { 106995ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani UserInfo user = users.get(i); 107095ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani if (!user.isGuest()) { 107195ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani aliveUserCount++; 107295ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 107395ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 107495ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani return aliveUserCount < getMaxSupportedUsers(); 107595ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani } 107695ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani 107795ab7849444125387dc88088bb5197ee463d8c17Amith Yamasani /** 107872434b7088591828082dd952496d523ef3622de2Nicolas Prevot * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS 107972434b7088591828082dd952496d523ef3622de2Nicolas Prevot * permission. 108007387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * if allowedToRemoveOne is true and if the user already has a managed profile, then return if 108107387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot * we could add a new managed profile to this user after removing the existing one. 108272434b7088591828082dd952496d523ef3622de2Nicolas Prevot * 108372434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @return true if more managed profiles can be added, false if limit has been reached. 108472434b7088591828082dd952496d523ef3622de2Nicolas Prevot * @hide 108572434b7088591828082dd952496d523ef3622de2Nicolas Prevot */ 108607387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot public boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne) { 108772434b7088591828082dd952496d523ef3622de2Nicolas Prevot try { 108807387fedfafa72bcb68defd801eef82f1f494d7cNicolas Prevot return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne); 108972434b7088591828082dd952496d523ef3622de2Nicolas Prevot } catch (RemoteException re) { 109072434b7088591828082dd952496d523ef3622de2Nicolas Prevot Log.w(TAG, "Could not check if we can add more managed profiles", re); 109172434b7088591828082dd952496d523ef3622de2Nicolas Prevot return false; 109272434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 109372434b7088591828082dd952496d523ef3622de2Nicolas Prevot } 109472434b7088591828082dd952496d523ef3622de2Nicolas Prevot 109572434b7088591828082dd952496d523ef3622de2Nicolas Prevot /** 10962a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Returns list of the profiles of userHandle including 10972a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * userHandle itself. 10984f7e2e334e4ca5f1a67baf4bdd40cd080b954161Amith Yamasani * Note that this returns both enabled and not enabled profiles. See 10997f75da2405cd910854448bb3801f776e036f926aRuben Brunk * {@link #getEnabledProfiles(int)} if you need only the enabled ones. 11004f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 11012a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 11022a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @param userHandle profiles of this user will be returned. 11032a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @return the list of profiles. 11042a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy * @hide 11052a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy */ 11062a764949c943681a4d25a17a0b203a0127a4a486Kenny Guy public List<UserInfo> getProfiles(int userHandle) { 1107a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy try { 1108385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina return mService.getProfiles(userHandle, false /* enabledOnly */); 1109a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } catch (RemoteException re) { 1110a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy Log.w(TAG, "Could not get user list", re); 1111a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy return null; 1112a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1113a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy } 1114a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy 1115a52dc3eb40777b055c0ca8d7885bd2c9577bcd1aKenny Guy /** 1116fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1117fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param userId one of the two user ids to check. 1118fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @param otherUserId one of the two user ids to check. 1119fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @return true if the two user ids are in the same profile group. 1120fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen * @hide 1121fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen */ 1122fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen public boolean isSameProfileGroup(int userId, int otherUserId) { 1123fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen try { 1124fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen return mService.isSameProfileGroup(userId, otherUserId); 1125fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } catch (RemoteException re) { 1126fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen Log.w(TAG, "Could not get user list", re); 1127fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen return false; 1128fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1129fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen } 1130fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen 1131fd5b77444edaec88895344a629d071ecf352cf36Xiaohui Chen /** 11327f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Returns list of the profiles of userHandle including 11337f75da2405cd910854448bb3801f776e036f926aRuben Brunk * userHandle itself. 11347f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Note that this returns only enabled. 11357f75da2405cd910854448bb3801f776e036f926aRuben Brunk * 11367f75da2405cd910854448bb3801f776e036f926aRuben Brunk * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 11377f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @param userHandle profiles of this user will be returned. 11387f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @return the list of profiles. 11397f75da2405cd910854448bb3801f776e036f926aRuben Brunk * @hide 11407f75da2405cd910854448bb3801f776e036f926aRuben Brunk */ 11417f75da2405cd910854448bb3801f776e036f926aRuben Brunk public List<UserInfo> getEnabledProfiles(int userHandle) { 11427f75da2405cd910854448bb3801f776e036f926aRuben Brunk try { 11437f75da2405cd910854448bb3801f776e036f926aRuben Brunk return mService.getProfiles(userHandle, true /* enabledOnly */); 11447f75da2405cd910854448bb3801f776e036f926aRuben Brunk } catch (RemoteException re) { 11457f75da2405cd910854448bb3801f776e036f926aRuben Brunk Log.w(TAG, "Could not get user list", re); 11467f75da2405cd910854448bb3801f776e036f926aRuben Brunk return null; 11477f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 11487f75da2405cd910854448bb3801f776e036f926aRuben Brunk } 11497f75da2405cd910854448bb3801f776e036f926aRuben Brunk 11507f75da2405cd910854448bb3801f776e036f926aRuben Brunk /** 1151be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns a list of UserHandles for profiles associated with the user that the calling process 1152be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * is running on, including the user itself. 11534f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * 11544f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @return A non-empty list of UserHandles associated with the calling user. 11554f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani */ 11564f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani public List<UserHandle> getUserProfiles() { 11574f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani ArrayList<UserHandle> profiles = new ArrayList<UserHandle>(); 11582b45f8a6ce623012b2fc6237acd1bdc6ebe2c85cXiaohui Chen List<UserInfo> users; 1159385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina try { 1160f2e7b3f56ae0ea9f49b5c50413b9be71d5249d6dAlexandra Gherghina users = mService.getProfiles(UserHandle.myUserId(), true /* enabledOnly */); 1161385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } catch (RemoteException re) { 1162385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina Log.w(TAG, "Could not get user list", re); 1163385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina return null; 1164385124d8cee38dee00d4fac31e8fbe46fb30565bAlexandra Gherghina } 11654f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani for (UserInfo info : users) { 11664f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani UserHandle userHandle = new UserHandle(info.id); 11674f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani profiles.add(userHandle); 11684f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 11694f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani return profiles; 11704f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 11714f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 11727dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani /** 1173c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * Returns the device credential owner id of the profile from 1174c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * which this method is called, or userHandle if called from a user that 1175c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * is not a profile. 1176c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * 1177c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales * @hide 1178c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales */ 1179c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales public int getCredentialOwnerProfile(int userHandle) { 1180c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales try { 1181c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales return mService.getCredentialOwnerProfile(userHandle); 1182c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } catch (RemoteException re) { 1183c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales Log.w(TAG, "Could not get credential owner", re); 1184c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales return -1; 1185c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1186c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales } 1187c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales 1188c5548c02fe0aa768ebfce88ac09393dabe61ec06Andres Morales /** 1189be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * Returns the parent of the profile which this method is called from 1190be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * or null if called from a user that is not a profile. 1191be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * 1192be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel * @hide 1193be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel */ 1194be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel public UserInfo getProfileParent(int userHandle) { 1195be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel try { 1196be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel return mService.getProfileParent(userHandle); 1197be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } catch (RemoteException re) { 1198be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel Log.w(TAG, "Could not get profile parent", re); 1199be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel return null; 1200be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1201be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel } 1202be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel 1203be81c800ae6216e30b6008b4c73172b36531c405Jessica Hummel /** 12047dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * If the target user is a managed profile of the calling user or the caller 12057dda2657be1fcc808566dab3482df9d643ceb0f5Amith Yamasani * is itself a managed profile, then this returns a badged copy of the given 1206c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * icon to be able to distinguish it from the original icon. For badging an 1207c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * arbitrary drawable use {@link #getBadgedDrawableForUser( 1208c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}. 1209c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1210c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 1211c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading 1212c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1213c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1214c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1215c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param icon The icon to badge. 1216c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1217c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original icon and a badge as 1218c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1219c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1220c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1221c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedIconForUser(Drawable icon, UserHandle user) { 1222c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedIcon(icon, user); 1223c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav } 1224c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav 1225c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav /** 1226c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the target user is a managed profile of the calling user or the caller 1227c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is itself a managed profile, then this returns a badged copy of the given 1228c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable allowing the user to distinguish it from the original drawable. 1229c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * The caller can specify the location in the bounds of the drawable to be 1230c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badged where the badge should be applied as well as the density of the 1231c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * badge to be used. 1232c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * <p> 1233c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * If the original drawable is a BitmapDrawable and the backing bitmap is 1234c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading 1235c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * is performed in place and the original drawable is returned. 1236c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * </p> 1237c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * 1238c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgedDrawable The drawable to badge. 1239c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param user The target user. 1240c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeLocation Where in the bounds of the badged drawable to place 1241c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the badge. If not provided, the badge is applied on top of the entire 1242c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * drawable being badged. 1243c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @param badgeDensity The optional desired density for the badge as per 1244c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * {@link android.util.DisplayMetrics#densityDpi}. If not provided, 1245c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * the density of the display is used. 1246c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * @return A drawable that combines the original drawable and a badge as 1247c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav * determined by the system. 1248c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1249c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav */ 1250c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav public Drawable getBadgedDrawableForUser(Drawable badgedDrawable, UserHandle user, 1251c71c42fdb2ee54a419dc8eb0a5f4f82532b16c0cSvetoslav Rect badgeLocation, int badgeDensity) { 1252c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedDrawableForDensity(badgedDrawable, user, 1253c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav badgeLocation, badgeDensity); 12544f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 12554f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 1256701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy /** 1257701ea7cf86b7d408b8d3bc1aab054be0333e1f26Kenny Guy * If the target user is a managed profile of the calling user or the caller 1258f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * is itself a managed profile, then this returns a copy of the label with 1259f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * badging for accessibility services like talkback. E.g. passing in "Email" 1260f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * and it might return "Work Email" for Email in the work profile. 1261f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * 1262f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param label The label to change. 1263f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @param user The target user. 1264f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * @return A label that combines the original label and a badge as 1265f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy * determined by the system. 1266c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav * @removed 1267f7ecf7c80520c017255cb350d183f0b62022349bKenny Guy */ 1268237aecd18d0edf56c038761f570758c310c9e6dfKenny Guy public CharSequence getBadgedLabelForUser(CharSequence label, UserHandle user) { 1269c7d62f02b8acfd0a6b31f8544ec2c07e780fe4bbSvetoslav return mContext.getPackageManager().getUserBadgedLabel(label, user); 12704f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani } 12714f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani 12724f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani /** 12734f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * Returns information for all users on this device. Requires 12744f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * {@link android.Manifest.permission#MANAGE_USERS} permission. 1275394a6cdd987fed79bd040f39e2d3e47d4484bab4Emily Bernier * 12764f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * @param excludeDying specify if the list should exclude users being 12774f58263d02f296430a9653126d28501e95c7bb6cAmith Yamasani * removed. 1278920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @return the list of users that were created. 1279920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani * @hide 1280920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani */ 1281920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani public List<UserInfo> getUsers(boolean excludeDying) { 1282920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani try { 1283920ace0bbc2d4133dbec991d2636c99a57d6245eAmith Yamasani return mService.getUsers(excludeDying); 1284258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1285258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not get user list", re); 1286258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return null; 1287258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1288258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1289258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1290258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1291258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Removes a user and all associated data. 12921952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1293258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the integer handle of the user, where 0 is the primary user. 1294258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1295258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1296258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public boolean removeUser(int userHandle) { 1297258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1298258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return mService.removeUser(userHandle); 1299258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1300258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not remove user ", re); 1301258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani return false; 1302258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1303258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1304258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1305258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1306258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Updates the user's name. 13071952637425eece18aa1ce3d80d4b49086ef3bcf7Amith Yamasani * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. 1308258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * 1309258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user's integer handle 1310258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param name the new name for the user 1311258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1312258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1313258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani public void setUserName(int userHandle, String name) { 1314258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1315258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani mService.setUserName(userHandle, name); 1316258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1317258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user name ", re); 1318258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1319258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1320258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1321258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 1322e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * Sets the user's photo. 1323258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @param userHandle the user for whom to change the photo. 1324e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @param icon the bitmap to set as the photo. 1325258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1326258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 1327e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public void setUserIcon(int userHandle, Bitmap icon) { 1328258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani try { 1329e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani mService.setUserIcon(userHandle, icon); 1330258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } catch (RemoteException re) { 1331258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani Log.w(TAG, "Could not set the user icon ", re); 1332258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1333258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 1334258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani 1335258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani /** 13363b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * Returns a file descriptor for the user's photo. PNG data can be read from this file. 13373b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @param userHandle the user whose photo we want to read. 1338e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani * @return a {@link Bitmap} of the user's photo, or null if there's no photo. 133964d4dca63f65e4c7d4a829c85ff6670bdd34e2ebAlexandra Gherghina * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. 13403b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani * @hide 13413b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani */ 1342e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani public Bitmap getUserIcon(int userHandle) { 13433b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani try { 13441bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos ParcelFileDescriptor fd = mService.getUserIcon(userHandle); 13451bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos if (fd != null) { 13461bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 13471bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); 13481bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } finally { 13491bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos try { 13501bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos fd.close(); 13511bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } catch (IOException e) { 13521bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 13531bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 13541bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos } 13553b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } catch (RemoteException re) { 1356e928d7d95dbb64627e6ff3a0572190c555b59d96Amith Yamasani Log.w(TAG, "Could not get the user icon ", re); 13573b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 13581bdff9139fd412b36d5d2d783574b6418fcb198aAdrian Roos return null; 13593b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani } 13603b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani 13613b49f07a452e0a77c1d22db2065255689a461d31Amith Yamasani /** 1362258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * Returns the maximum number of users that can be created on this device. A return value 1363258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * of 1 means that it is a single user device. 1364258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani * @hide 1365a12fccf57d5ec289793699d9b22ff45daccd3933Maggie Benthall * @return a value greater than or equal to 1 1366258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani */ 136727bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey public static int getMaxSupportedUsers() { 1368ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani // Don't allow multiple users on certain builds 1369ff54920ed222a2bd6abe618743a5a3e9fe10bd4bAmith Yamasani if (android.os.Build.ID.startsWith("JVP")) return 1; 1370409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn // Svelte devices don't get multi-user. 1371409297da182267465adbc21cfb75a23e8d678117Dianne Hackborn if (ActivityManager.isLowRamDeviceStatic()) return 1; 137227bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey return SystemProperties.getInt("fw.max_users", 137327bd34d9d9fe99f11b80aa0bbdb402fb47ef4158Jeff Sharkey Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)); 1374258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani } 13752a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 13762a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 1377cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * Returns true if the user switcher should be shown, this will be if device supports multi-user 1378cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov * and there are at least 2 users available that are not managed profiles. 13791a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @hide 13801a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy * @return true if user switcher should be shown. 13811a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy */ 13821a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy public boolean isUserSwitcherEnabled() { 1383cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov if (!supportsMultipleUsers()) { 1384cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov return false; 1385cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov } 13861a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy List<UserInfo> users = getUsers(true); 13871a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy if (users == null) { 13881a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy return false; 13891a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 13901a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy int switchableUserCount = 0; 13911a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy for (UserInfo user : users) { 13927cb69df507f5f7956c52a2868a0d6e89aec6dde2Xiaohui Chen if (user.supportsSwitchToByUser()) { 13931a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy ++switchableUserCount; 13941a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 13951a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 1396cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class) 1397cd86ebf1c965c191f46b6480145c9d217a7d841eFyodor Kupolov .getGuestUserDisabled(null); 1398a596ff87cd899640334512371456b8481ba21b4aAmith Yamasani return switchableUserCount > 1 || guestEnabled; 13991a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy } 14001a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy 14011a447535cef7e3739d5f763dfe13e568568b9789Kenny Guy /** 14022a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a serial number on this device for a given userHandle. User handles can be recycled 14032a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * when deleting and creating users, but serial numbers are not reused until the device is wiped. 14042a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userHandle 14052a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return a serial number associated with that user, or -1 if the userHandle is not valid. 14062a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 14072a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 14082a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserSerialNumber(int userHandle) { 14092a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 14102a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserSerialNumber(userHandle); 14112a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 14122a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get serial number for user " + userHandle); 14132a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 14142a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 14152a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 14162a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani 14172a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani /** 14182a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * Returns a userHandle on this device for a given user serial number. User handles can be 14192a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * recycled when deleting and creating users, but serial numbers are not reused until the device 14202a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is wiped. 14212a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @param userSerialNumber 14222a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @return the userHandle associated with that user serial number, or -1 if the serial number 14232a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * is not valid. 14242a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani * @hide 14252a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani */ 14262a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani public int getUserHandle(int userSerialNumber) { 14272a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani try { 14282a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return mService.getUserHandle(userSerialNumber); 14292a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } catch (RemoteException re) { 14302a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani Log.w(TAG, "Could not get userHandle for user " + userSerialNumber); 14312a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 14322a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani return -1; 14332a00329c6d55c6cd9166e01963d7410e95d80d21Amith Yamasani } 14346794458f8626c3be27eac3db3a5c89d94f132675Maggie Benthall 14357e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani /** 14367e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * Returns a Bundle containing any saved application restrictions for this user, for the 14377e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * given package name. Only an application with this package name can call this method. 14387e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @param packageName the package name of the calling application 14397e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * @return a Bundle with the restrictions as key/value pairs, or null if there are no 14407e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * saved restrictions. The values can be of type Boolean, String or String[], depending 14417e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani * on the restriction type, as defined by the application. 14427e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani */ 14437e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName) { 14447e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani try { 14457e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictions(packageName); 14467e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } catch (RemoteException re) { 14477e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani Log.w(TAG, "Could not get application restrictions for package " + packageName); 14487e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 14497e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return null; 14507e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani } 1451df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 1452df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 1453df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 1454df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 14557e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public Bundle getApplicationRestrictions(String packageName, UserHandle user) { 1456df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 14577e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani return mService.getApplicationRestrictionsForUser(packageName, user.getIdentifier()); 1458df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 1459df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not get application restrictions for user " + user.getIdentifier()); 1460df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1461df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani return null; 1462df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1463df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani 1464df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani /** 1465df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * @hide 1466df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */ 14677e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani public void setApplicationRestrictions(String packageName, Bundle restrictions, 1468df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani UserHandle user) { 1469df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani try { 14707e99bc02c8e2f44dd92d70bfa6e654297e5286d8Amith Yamasani mService.setApplicationRestrictions(packageName, restrictions, user.getIdentifier()); 1471df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } catch (RemoteException re) { 1472df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani Log.w(TAG, "Could not set application restrictions for user " + user.getIdentifier()); 1473df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1474df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani } 1475655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani 1476655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani /** 1477d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * Sets a new challenge PIN for restrictions. This is only for use by pre-installed 1478d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * apps and requires the MANAGE_USERS permission. 1479d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @param newPin the PIN to use for challenge dialogs. 1480d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani * @return Returns true if the challenge PIN was set successfully. 1481ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * @deprecated The restrictions PIN functionality is no longer provided by the system. 1482ef24909d84db9d5aefb825ee1556089fcdcc1678Fyodor Kupolov * This method is preserved for backwards compatibility reasons and always returns false. 1483655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani */ 1484d304af69891483aad808356af1ac5f00e90c8edfAmith Yamasani public boolean setRestrictionsChallenge(String newPin) { 1485655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani return false; 1486655d0e2029e6ae77a47e922dce4c4989818b8dd1Amith Yamasani } 14871a7472e7220a2b027464fb4a2281550f784a2ca3Amith Yamasani 1488e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 1489e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 1490e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Set restrictions that should apply to any future guest user that's created. 1491e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 1492e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public void setDefaultGuestRestrictions(Bundle restrictions) { 1493e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 1494e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani mService.setDefaultGuestRestrictions(restrictions); 1495e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 1496e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani Log.w(TAG, "Could not set guest restrictions"); 1497e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1498e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1499e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani 1500e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani /** 1501e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * @hide 1502e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani * Gets the default guest restrictions. 1503e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani */ 1504e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani public Bundle getDefaultGuestRestrictions() { 1505e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani try { 1506e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani return mService.getDefaultGuestRestrictions(); 1507e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } catch (RemoteException re) { 1508e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani Log.w(TAG, "Could not set guest restrictions"); 1509e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1510e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani return new Bundle(); 1511e4afaa3a3d7c2885b82fe43f51bcf04e036f7462Amith Yamasani } 1512ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov 1513ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov /** 1514ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * Returns creation time of the user or of a managed profile associated with the calling user. 1515ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @param userHandle user handle of the user or a managed profile associated with the 1516ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * calling user. 1517ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov * @return creation time in milliseconds since Epoch time. 1518ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov */ 1519385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov public long getUserCreationTime(UserHandle userHandle) { 1520ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov try { 1521385de624aa990266ffbaf70711ac8a330569429eFyodor Kupolov return mService.getUserCreationTime(userHandle.getIdentifier()); 1522ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } catch (RemoteException re) { 1523ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov Log.w(TAG, "Could not get user creation time", re); 1524ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov return 0; 1525ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 1526ff7233e2e3df4965b9ecadabfd78bb991fd1e102Fyodor Kupolov } 1527258848d2ae04f447ff1c18023fa76b139fcc0862Amith Yamasani} 1528