Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
| 20 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 22 | import android.app.Activity; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 23 | import android.app.admin.IDevicePolicyManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 26 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
| 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 31 | import android.net.ProxyInfo; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 32 | import android.os.Bundle; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 33 | import android.os.Handler; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 34 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 35 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 36 | import android.os.RemoteException; |
| 37 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 38 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 39 | import android.os.UserManager; |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 40 | import android.provider.Settings; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 41 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 42 | import android.util.Log; |
| 43 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 44 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 45 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 46 | import org.xmlpull.v1.XmlPullParserException; |
| 47 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 48 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 49 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 50 | import java.net.InetSocketAddress; |
| 51 | import java.net.Proxy; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 52 | import java.security.cert.CertificateException; |
| 53 | import java.security.cert.CertificateFactory; |
| 54 | import java.security.cert.X509Certificate; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 55 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 56 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 57 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Public interface for managing policies enforced on a device. Most clients |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 61 | * of this class must have published a {@link DeviceAdminReceiver} that the user |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | * has currently enabled. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 63 | * |
| 64 | * <div class="special reference"> |
| 65 | * <h3>Developer Guides</h3> |
| 66 | * <p>For more information about managing policies for device adminstration, read the |
| 67 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
| 68 | * developer guide.</p> |
| 69 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 70 | */ |
| 71 | public class DevicePolicyManager { |
| 72 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 73 | |
| 74 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 75 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 76 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 77 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 79 | mService = IDevicePolicyManager.Stub.asInterface( |
| 80 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 81 | } |
| 82 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 83 | /** @hide */ |
| 84 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 85 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 86 | return me.mService != null ? me : null; |
| 87 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 88 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 89 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 90 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 91 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 92 | * <p>A managed profile allows data separation for example for the usage of a |
| 93 | * device as a personal and corporate device. The user which provisioning is started from and |
| 94 | * the managed profile share a launcher. |
| 95 | * |
| 96 | * <p>This intent will typically be sent by a mobile device management application (mdm). |
| 97 | * Provisioning adds a managed profile and sets the mdm as the profile owner who has full |
| 98 | * control over the profile |
| 99 | * |
| 100 | * <p>This intent must contain the extras {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} |
| 101 | * {@link #EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME} and {@link #EXTRA_DEVICE_ADMIN}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 102 | * |
| 103 | * <p> When managed provisioning has completed, an intent of the type |
| 104 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 105 | * managed profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 106 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 107 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 108 | * previous state. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 109 | * |
| 110 | * <p>Input: Nothing.</p> |
| 111 | * <p>Output: Nothing</p> |
| 112 | */ |
| 113 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 114 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Jessica Hummel | 03dd220 | 2014-03-13 16:05:26 +0000 | [diff] [blame] | 115 | = "android.app.action.ACTION_PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 116 | |
| 117 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 118 | * A String extra holding the package name of the mobile device management application that |
| 119 | * will be set as the profile owner or device owner. |
| 120 | * |
| 121 | * <p>If an application starts provisioning directly via an intent with action |
| 122 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 123 | * application that started provisioning. The package will be set as profile owner in that case. |
| 124 | * |
| 125 | * <p>This package is set as device owner when device owner provisioning is started by an Nfc |
| 126 | * message containing an Nfc record with MIME type {@link #PROVISIONING_NFC_MIME_TYPE}. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 127 | */ |
| 128 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 129 | = "android.app.extra.deviceAdminPackageName"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * A String extra holding the default name of the profile that is created during managed profile |
| 133 | * provisioning. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 134 | * |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 135 | * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} |
| 136 | */ |
| 137 | public static final String EXTRA_PROVISIONING_DEFAULT_MANAGED_PROFILE_NAME |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 138 | = "android.app.extra.defaultManagedProfileName"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
Jessica Hummel | edb7ae7 | 2014-06-26 12:55:38 +0100 | [diff] [blame] | 141 | * A String extra that, holds the email address of the account which a managed profile is |
| 142 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 143 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Jessica Hummel | edb7ae7 | 2014-06-26 12:55:38 +0100 | [diff] [blame] | 144 | * |
| 145 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 146 | * contains this extra, it is forwarded in the |
| 147 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 148 | * device management application that was set as the profile owner during provisioning. |
| 149 | * It is usually used to avoid that the user has to enter their email address twice. |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 150 | */ |
| 151 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 152 | = "android.app.extra.ManagedProfileEmailAddress"; |
| 153 | |
| 154 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 155 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 156 | * will be set to. |
| 157 | * |
| 158 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 159 | * provisioning via an Nfc bump. |
| 160 | */ |
| 161 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
| 162 | = "android.app.extra.timeZone"; |
| 163 | |
| 164 | /** |
| 165 | * A Long extra holding the local time {@link android.app.AlarmManager} that the device |
| 166 | * will be set to. |
| 167 | * |
| 168 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 169 | * provisioning via an Nfc bump. |
| 170 | */ |
| 171 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
| 172 | = "android.app.extra.localTime"; |
| 173 | |
| 174 | /** |
| 175 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 176 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 177 | * |
| 178 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 179 | * provisioning via an Nfc bump. |
| 180 | */ |
| 181 | public static final String EXTRA_PROVISIONING_LOCALE |
| 182 | = "android.app.extra.locale"; |
| 183 | |
| 184 | /** |
| 185 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 186 | * owner provisioning for downloading the mobile device management application. |
| 187 | * |
| 188 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 189 | * provisioning via an Nfc bump. |
| 190 | */ |
| 191 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
| 192 | = "android.app.extra.wifiSsid"; |
| 193 | |
| 194 | /** |
| 195 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 196 | * is hidden or not. |
| 197 | * |
| 198 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 199 | * provisioning via an Nfc bump. |
| 200 | */ |
| 201 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
| 202 | = "android.app.extra.wifiHidden"; |
| 203 | |
| 204 | /** |
| 205 | * A String extra indicating the security type of the wifi network in |
| 206 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 207 | * |
| 208 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 209 | * provisioning via an Nfc bump. |
| 210 | */ |
| 211 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
| 212 | = "android.app.extra.wifiSecurityType"; |
| 213 | |
| 214 | /** |
| 215 | * A String extra holding the password of the wifi network in |
| 216 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 217 | * |
| 218 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 219 | * provisioning via an Nfc bump. |
| 220 | */ |
| 221 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
| 222 | = "android.app.extra.wifiPassword"; |
| 223 | |
| 224 | /** |
| 225 | * A String extra holding the proxy host for the wifi network in |
| 226 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 227 | * |
| 228 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 229 | * provisioning via an Nfc bump. |
| 230 | */ |
| 231 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
| 232 | = "android.app.extra.wifiProxyHost"; |
| 233 | |
| 234 | /** |
| 235 | * An int extra holding the proxy port for the wifi network in |
| 236 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 237 | * |
| 238 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 239 | * provisioning via an Nfc bump. |
| 240 | */ |
| 241 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
| 242 | = "android.app.extra.wifiProxyPort"; |
| 243 | |
| 244 | /** |
| 245 | * A String extra holding the proxy bypass for the wifi network in |
| 246 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 247 | * |
| 248 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 249 | * provisioning via an Nfc bump. |
| 250 | */ |
| 251 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
| 252 | = "android.app.extra.wifiProxyBypassHosts"; |
| 253 | |
| 254 | /** |
| 255 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 256 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 257 | * |
| 258 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 259 | * provisioning via an Nfc bump. |
| 260 | */ |
| 261 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
| 262 | = "android.app.extra.wifiPacUrl"; |
| 263 | |
| 264 | /** |
| 265 | * A String extra holding a url that specifies the download location of the device admin |
| 266 | * package. When not provided it is assumed that the device admin package is already installed. |
| 267 | * |
| 268 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 269 | * provisioning via an Nfc bump. |
| 270 | */ |
| 271 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
| 272 | = "android.app.extra.deviceAdminPackageDownloadLocation"; |
| 273 | |
| 274 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 275 | * A String extra holding a http cookie header which should be used in the http request to the |
| 276 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 277 | * |
| 278 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 279 | * provisioning via an Nfc bump. |
| 280 | */ |
| 281 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
| 282 | = "android.app.extra.deviceAdminPackageDownloadCookieHeader"; |
| 283 | |
| 284 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 285 | * A String extra holding the SHA-1 checksum of the file at download location specified in |
| 286 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. If this doesn't match |
| 287 | * the file at the download location an error will be shown to the user and the user will be |
| 288 | * asked to factory reset the device. |
| 289 | * |
| 290 | * <p>Use in an Nfc record with {@link #PROVISIONING_NFC_MIME_TYPE} that starts device owner |
| 291 | * provisioning via an Nfc bump. |
| 292 | */ |
| 293 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
| 294 | = "android.app.extra.deviceAdminPackageChecksum"; |
| 295 | |
| 296 | /** |
| 297 | * This MIME type is used for starting the Device Owner provisioning. |
| 298 | * |
| 299 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 300 | * A device owner has full control over the device. The device owner can not be modified by the |
| 301 | * user and the only way of resetting the device is if the device owner app calls a factory |
| 302 | * reset. |
| 303 | * |
| 304 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 305 | * employee or client. |
| 306 | * |
| 307 | * <p> The Nfc message should be send to an unprovisioned device. |
| 308 | * |
| 309 | * <p>The Nfc record must contain a serialized {@link java.util.Properties} object which |
| 310 | * contains the following properties: |
| 311 | * <ul> |
| 312 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 313 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 314 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 315 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}</li> |
| 316 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 317 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 318 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 319 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 320 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 321 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 322 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 323 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 324 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 325 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
| 326 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul> |
| 327 | * |
| 328 | * <p> When device owner provisioning has completed, an intent of the type |
| 329 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
| 330 | * device owner. |
| 331 | * |
| 332 | * <p> |
| 333 | * If provisioning fails, the device is factory reset. |
| 334 | * |
| 335 | * <p>Input: Nothing.</p> |
| 336 | * <p>Output: Nothing</p> |
| 337 | */ |
| 338 | public static final String PROVISIONING_NFC_MIME_TYPE |
| 339 | = "application/com.android.managedprovisioning"; |
| 340 | |
| 341 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 342 | * Activity action: ask the user to add a new device administrator to the system. |
| 343 | * The desired policy is the ComponentName of the policy in the |
| 344 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 345 | * bring the user through adding the device administrator to the system (or |
| 346 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 347 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 348 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 349 | * field to provide the user with additional explanation (in addition |
| 350 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 351 | * |
| 352 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 353 | * user intervention). However, if your administrator has been updated and is requesting |
| 354 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 355 | * will not be available to the updated administrator until the user has accepted the new list. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 356 | */ |
| 357 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 358 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 359 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 360 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 361 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 362 | * @hide |
| 363 | * Activity action: ask the user to add a new device administrator as the profile owner |
| 364 | * for this user. Only system privileged apps that have MANAGE_USERS and MANAGE_DEVICE_ADMINS |
| 365 | * permission can call this API. |
| 366 | * |
| 367 | * <p>The ComponentName of the profile owner admin is pass in {@link #EXTRA_DEVICE_ADMIN} extra |
| 368 | * field. This will invoke a UI to bring the user through adding the profile owner admin |
| 369 | * to remotely control restrictions on the user. |
| 370 | * |
| 371 | * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the |
| 372 | * result of whether or not the user approved the action. If approved, the result will |
| 373 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 374 | * as a profile owner. |
| 375 | * |
| 376 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 377 | * field to provide the user with additional explanation (in addition |
| 378 | * to your component's description) about what is being added. |
| 379 | * |
| 380 | * <p>If there is already a profile owner active or the caller doesn't have the required |
| 381 | * permissions, the operation will return a failure result. |
| 382 | */ |
| 383 | @SystemApi |
| 384 | public static final String ACTION_SET_PROFILE_OWNER |
| 385 | = "android.app.action.SET_PROFILE_OWNER"; |
| 386 | |
| 387 | /** |
| 388 | * @hide |
| 389 | * Name of the profile owner admin that controls the user. |
| 390 | */ |
| 391 | @SystemApi |
| 392 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 393 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 394 | |
| 395 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 396 | * Activity action: send when any policy admin changes a policy. |
| 397 | * This is generally used to find out when a new policy is in effect. |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 398 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 399 | * @hide |
| 400 | */ |
| 401 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 402 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 403 | |
| 404 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 405 | * The ComponentName of the administrator component. |
| 406 | * |
| 407 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 408 | */ |
| 409 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 410 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 411 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 412 | * An optional CharSequence providing additional explanation for why the |
| 413 | * admin is being added. |
| 414 | * |
| 415 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 416 | */ |
| 417 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 418 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 419 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 420 | * Activity action: have the user enter a new password. This activity should |
| 421 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 422 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 423 | * enter a new password that meets the current requirements. You can use |
| 424 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 425 | * have the user select a new password in order to meet the current |
| 426 | * constraints. Upon being resumed from this activity, you can check the new |
| 427 | * password characteristics to see if they are sufficient. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 428 | */ |
| 429 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 430 | public static final String ACTION_SET_NEW_PASSWORD |
| 431 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 432 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 433 | /** |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 434 | * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from a |
| 435 | * managed profile to its parent. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 436 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 437 | public static int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 438 | |
| 439 | /** |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 440 | * Flag used by {@link #addCrossProfileIntentFilter} to allow access of certain intents from the |
| 441 | * parent to its managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 442 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 443 | public static int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 444 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 445 | /** |
| 446 | * Return true if the given administrator component is currently |
| 447 | * active (enabled) in the system. |
| 448 | */ |
| 449 | public boolean isAdminActive(ComponentName who) { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 450 | return isAdminActiveAsUser(who, UserHandle.myUserId()); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * @see #isAdminActive(ComponentName) |
| 455 | * @hide |
| 456 | */ |
| 457 | public boolean isAdminActiveAsUser(ComponentName who, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 458 | if (mService != null) { |
| 459 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 460 | return mService.isAdminActive(who, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 461 | } catch (RemoteException e) { |
| 462 | Log.w(TAG, "Failed talking with device policy service", e); |
| 463 | } |
| 464 | } |
| 465 | return false; |
| 466 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 467 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 468 | /** |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 469 | * Return a list of all currently active device administrator's component |
| 470 | * names. Note that if there are no administrators than null may be |
| 471 | * returned. |
| 472 | */ |
| 473 | public List<ComponentName> getActiveAdmins() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 474 | return getActiveAdminsAsUser(UserHandle.myUserId()); |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * @see #getActiveAdmins() |
| 479 | * @hide |
| 480 | */ |
| 481 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 482 | if (mService != null) { |
| 483 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 484 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 485 | } catch (RemoteException e) { |
| 486 | Log.w(TAG, "Failed talking with device policy service", e); |
| 487 | } |
| 488 | } |
| 489 | return null; |
| 490 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 491 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 492 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 493 | * Used by package administration code to determine if a package can be stopped |
| 494 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 495 | * @hide |
| 496 | */ |
| 497 | public boolean packageHasActiveAdmins(String packageName) { |
| 498 | if (mService != null) { |
| 499 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 500 | return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 501 | } catch (RemoteException e) { |
| 502 | Log.w(TAG, "Failed talking with device policy service", e); |
| 503 | } |
| 504 | } |
| 505 | return false; |
| 506 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 507 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 508 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 509 | * Remove a current administration component. This can only be called |
| 510 | * by the application that owns the administration component; if you |
| 511 | * try to remove someone else's component, a security exception will be |
| 512 | * thrown. |
| 513 | */ |
| 514 | public void removeActiveAdmin(ComponentName who) { |
| 515 | if (mService != null) { |
| 516 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 517 | mService.removeActiveAdmin(who, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 518 | } catch (RemoteException e) { |
| 519 | Log.w(TAG, "Failed talking with device policy service", e); |
| 520 | } |
| 521 | } |
| 522 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 523 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 524 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 525 | * Returns true if an administrator has been granted a particular device policy. This can |
| 526 | * be used to check if the administrator was activated under an earlier set of policies, |
| 527 | * but requires additional policies after an upgrade. |
| 528 | * |
| 529 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 530 | * an active administrator, or an exception will be thrown. |
| 531 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 532 | */ |
| 533 | public boolean hasGrantedPolicy(ComponentName admin, int usesPolicy) { |
| 534 | if (mService != null) { |
| 535 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 536 | return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 537 | } catch (RemoteException e) { |
| 538 | Log.w(TAG, "Failed talking with device policy service", e); |
| 539 | } |
| 540 | } |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 545 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 546 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 547 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 548 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 549 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 550 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 551 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 552 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 553 | * recognition technology. This implies technologies that can recognize the identity of |
| 554 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 555 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 556 | */ |
| 557 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 558 | |
| 559 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 560 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 561 | * of password, but doesn't care what it is. Note that quality constants |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 562 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 563 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 564 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 565 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 566 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 567 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 568 | * password containing at least numeric characters. Note that quality |
| 569 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 570 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 571 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 572 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 573 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 574 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 575 | * password containing at least numeric characters with no repeating (4444) |
| 576 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 577 | * constants are ordered so that higher values are more restrictive. |
| 578 | */ |
| 579 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 580 | |
| 581 | /** |
| 582 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 583 | * password containing at least alphabetic (or other symbol) characters. |
| 584 | * Note that quality constants are ordered so that higher values are more |
| 585 | * restrictive. |
| 586 | */ |
| 587 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 588 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 591 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 592 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 593 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 594 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 595 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 596 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 597 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 598 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 599 | * password containing at least a letter, a numerical digit and a special |
| 600 | * symbol, by default. With this password quality, passwords can be |
| 601 | * restricted to contain various sets of characters, like at least an |
| 602 | * uppercase letter, etc. These are specified using various methods, |
| 603 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 604 | * that quality constants are ordered so that higher values are more |
| 605 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 606 | */ |
| 607 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 608 | |
| 609 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 610 | * Called by an application that is administering the device to set the |
| 611 | * password restrictions it is imposing. After setting this, the user |
| 612 | * will not be able to enter a new password that is not at least as |
| 613 | * restrictive as what has been set. Note that the current password |
| 614 | * will remain until the user has set a new one, so the change does not |
| 615 | * take place immediately. To prompt the user for a new password, use |
| 616 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 617 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 618 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 619 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 620 | * the user's preference, and any other considerations) is the one that |
| 621 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 622 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 623 | * <p>The calling device admin must have requested |
| 624 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 625 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 626 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 627 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 628 | * @param quality The new desired quality. One of |
| 629 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 630 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 631 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 632 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 633 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 634 | public void setPasswordQuality(ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 635 | if (mService != null) { |
| 636 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 637 | mService.setPasswordQuality(admin, quality, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 638 | } catch (RemoteException e) { |
| 639 | Log.w(TAG, "Failed talking with device policy service", e); |
| 640 | } |
| 641 | } |
| 642 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 643 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 644 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 645 | * Retrieve the current minimum password quality for all admins of this user |
| 646 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 647 | * @param admin The name of the admin component to check, or null to aggregate |
| 648 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 649 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 650 | public int getPasswordQuality(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 651 | return getPasswordQuality(admin, UserHandle.myUserId()); |
| 652 | } |
| 653 | |
| 654 | /** @hide per-user version */ |
| 655 | public int getPasswordQuality(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 656 | if (mService != null) { |
| 657 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 658 | return mService.getPasswordQuality(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 659 | } catch (RemoteException e) { |
| 660 | Log.w(TAG, "Failed talking with device policy service", e); |
| 661 | } |
| 662 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 663 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 664 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 665 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 666 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 667 | * Called by an application that is administering the device to set the |
| 668 | * minimum allowed password length. After setting this, the user |
| 669 | * will not be able to enter a new password that is not at least as |
| 670 | * restrictive as what has been set. Note that the current password |
| 671 | * will remain until the user has set a new one, so the change does not |
| 672 | * take place immediately. To prompt the user for a new password, use |
| 673 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 674 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 675 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 676 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 677 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 678 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 679 | * <p>The calling device admin must have requested |
| 680 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 681 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 682 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 683 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 684 | * @param length The new desired minimum password length. A value of 0 |
| 685 | * means there is no restriction. |
| 686 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 687 | public void setPasswordMinimumLength(ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 688 | if (mService != null) { |
| 689 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 690 | mService.setPasswordMinimumLength(admin, length, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 691 | } catch (RemoteException e) { |
| 692 | Log.w(TAG, "Failed talking with device policy service", e); |
| 693 | } |
| 694 | } |
| 695 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 696 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 697 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 698 | * Retrieve the current minimum password length for all admins of this |
| 699 | * user and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 700 | * @param admin The name of the admin component to check, or null to aggregate |
| 701 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 702 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 703 | public int getPasswordMinimumLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 704 | return getPasswordMinimumLength(admin, UserHandle.myUserId()); |
| 705 | } |
| 706 | |
| 707 | /** @hide per-user version */ |
| 708 | public int getPasswordMinimumLength(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 709 | if (mService != null) { |
| 710 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 711 | return mService.getPasswordMinimumLength(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 712 | } catch (RemoteException e) { |
| 713 | Log.w(TAG, "Failed talking with device policy service", e); |
| 714 | } |
| 715 | } |
| 716 | return 0; |
| 717 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 718 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 719 | /** |
| 720 | * Called by an application that is administering the device to set the |
| 721 | * minimum number of upper case letters required in the password. After |
| 722 | * setting this, the user will not be able to enter a new password that is |
| 723 | * not at least as restrictive as what has been set. Note that the current |
| 724 | * password will remain until the user has set a new one, so the change does |
| 725 | * not take place immediately. To prompt the user for a new password, use |
| 726 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 727 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 728 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 729 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 730 | * <p> |
| 731 | * The calling device admin must have requested |
| 732 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 733 | * this method; if it has not, a security exception will be thrown. |
| 734 | * |
| 735 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 736 | * with. |
| 737 | * @param length The new desired minimum number of upper case letters |
| 738 | * required in the password. A value of 0 means there is no |
| 739 | * restriction. |
| 740 | */ |
| 741 | public void setPasswordMinimumUpperCase(ComponentName admin, int length) { |
| 742 | if (mService != null) { |
| 743 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 744 | mService.setPasswordMinimumUpperCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 745 | } catch (RemoteException e) { |
| 746 | Log.w(TAG, "Failed talking with device policy service", e); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | /** |
| 752 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 753 | * password for all admins of this user and its profiles or a particular one. |
| 754 | * This is the same value as set by |
| 755 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 756 | * and only applies when the password quality is |
| 757 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 758 | * |
| 759 | * @param admin The name of the admin component to check, or null to |
| 760 | * aggregate all admins. |
| 761 | * @return The minimum number of upper case letters required in the |
| 762 | * password. |
| 763 | */ |
| 764 | public int getPasswordMinimumUpperCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 765 | return getPasswordMinimumUpperCase(admin, UserHandle.myUserId()); |
| 766 | } |
| 767 | |
| 768 | /** @hide per-user version */ |
| 769 | public int getPasswordMinimumUpperCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 770 | if (mService != null) { |
| 771 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 772 | return mService.getPasswordMinimumUpperCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 773 | } catch (RemoteException e) { |
| 774 | Log.w(TAG, "Failed talking with device policy service", e); |
| 775 | } |
| 776 | } |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Called by an application that is administering the device to set the |
| 782 | * minimum number of lower case letters required in the password. After |
| 783 | * setting this, the user will not be able to enter a new password that is |
| 784 | * not at least as restrictive as what has been set. Note that the current |
| 785 | * password will remain until the user has set a new one, so the change does |
| 786 | * not take place immediately. To prompt the user for a new password, use |
| 787 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 788 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 789 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 790 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 791 | * <p> |
| 792 | * The calling device admin must have requested |
| 793 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 794 | * this method; if it has not, a security exception will be thrown. |
| 795 | * |
| 796 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 797 | * with. |
| 798 | * @param length The new desired minimum number of lower case letters |
| 799 | * required in the password. A value of 0 means there is no |
| 800 | * restriction. |
| 801 | */ |
| 802 | public void setPasswordMinimumLowerCase(ComponentName admin, int length) { |
| 803 | if (mService != null) { |
| 804 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 805 | mService.setPasswordMinimumLowerCase(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 806 | } catch (RemoteException e) { |
| 807 | Log.w(TAG, "Failed talking with device policy service", e); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 814 | * password for all admins of this user and its profiles or a particular one. |
| 815 | * This is the same value as set by |
| 816 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 817 | * and only applies when the password quality is |
| 818 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 819 | * |
| 820 | * @param admin The name of the admin component to check, or null to |
| 821 | * aggregate all admins. |
| 822 | * @return The minimum number of lower case letters required in the |
| 823 | * password. |
| 824 | */ |
| 825 | public int getPasswordMinimumLowerCase(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 826 | return getPasswordMinimumLowerCase(admin, UserHandle.myUserId()); |
| 827 | } |
| 828 | |
| 829 | /** @hide per-user version */ |
| 830 | public int getPasswordMinimumLowerCase(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 831 | if (mService != null) { |
| 832 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 833 | return mService.getPasswordMinimumLowerCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 834 | } catch (RemoteException e) { |
| 835 | Log.w(TAG, "Failed talking with device policy service", e); |
| 836 | } |
| 837 | } |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Called by an application that is administering the device to set the |
| 843 | * minimum number of letters required in the password. After setting this, |
| 844 | * the user will not be able to enter a new password that is not at least as |
| 845 | * restrictive as what has been set. Note that the current password will |
| 846 | * remain until the user has set a new one, so the change does not take |
| 847 | * place immediately. To prompt the user for a new password, use |
| 848 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 849 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 850 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 851 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 852 | * <p> |
| 853 | * The calling device admin must have requested |
| 854 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 855 | * this method; if it has not, a security exception will be thrown. |
| 856 | * |
| 857 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 858 | * with. |
| 859 | * @param length The new desired minimum number of letters required in the |
| 860 | * password. A value of 0 means there is no restriction. |
| 861 | */ |
| 862 | public void setPasswordMinimumLetters(ComponentName admin, int length) { |
| 863 | if (mService != null) { |
| 864 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 865 | mService.setPasswordMinimumLetters(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 866 | } catch (RemoteException e) { |
| 867 | Log.w(TAG, "Failed talking with device policy service", e); |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 874 | * admins or a particular one. This is the same value as |
| 875 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 876 | * and only applies when the password quality is |
| 877 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 878 | * |
| 879 | * @param admin The name of the admin component to check, or null to |
| 880 | * aggregate all admins. |
| 881 | * @return The minimum number of letters required in the password. |
| 882 | */ |
| 883 | public int getPasswordMinimumLetters(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 884 | return getPasswordMinimumLetters(admin, UserHandle.myUserId()); |
| 885 | } |
| 886 | |
| 887 | /** @hide per-user version */ |
| 888 | public int getPasswordMinimumLetters(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 889 | if (mService != null) { |
| 890 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 891 | return mService.getPasswordMinimumLetters(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 892 | } catch (RemoteException e) { |
| 893 | Log.w(TAG, "Failed talking with device policy service", e); |
| 894 | } |
| 895 | } |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Called by an application that is administering the device to set the |
| 901 | * minimum number of numerical digits required in the password. After |
| 902 | * setting this, the user will not be able to enter a new password that is |
| 903 | * not at least as restrictive as what has been set. Note that the current |
| 904 | * password will remain until the user has set a new one, so the change does |
| 905 | * not take place immediately. To prompt the user for a new password, use |
| 906 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 907 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 908 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 909 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 910 | * <p> |
| 911 | * The calling device admin must have requested |
| 912 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 913 | * this method; if it has not, a security exception will be thrown. |
| 914 | * |
| 915 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 916 | * with. |
| 917 | * @param length The new desired minimum number of numerical digits required |
| 918 | * in the password. A value of 0 means there is no restriction. |
| 919 | */ |
| 920 | public void setPasswordMinimumNumeric(ComponentName admin, int length) { |
| 921 | if (mService != null) { |
| 922 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 923 | mService.setPasswordMinimumNumeric(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 924 | } catch (RemoteException e) { |
| 925 | Log.w(TAG, "Failed talking with device policy service", e); |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 932 | * for all admins of this user and its profiles or a particular one. |
| 933 | * This is the same value as set by |
| 934 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 935 | * and only applies when the password quality is |
| 936 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 937 | * |
| 938 | * @param admin The name of the admin component to check, or null to |
| 939 | * aggregate all admins. |
| 940 | * @return The minimum number of numerical digits required in the password. |
| 941 | */ |
| 942 | public int getPasswordMinimumNumeric(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 943 | return getPasswordMinimumNumeric(admin, UserHandle.myUserId()); |
| 944 | } |
| 945 | |
| 946 | /** @hide per-user version */ |
| 947 | public int getPasswordMinimumNumeric(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 948 | if (mService != null) { |
| 949 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 950 | return mService.getPasswordMinimumNumeric(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 951 | } catch (RemoteException e) { |
| 952 | Log.w(TAG, "Failed talking with device policy service", e); |
| 953 | } |
| 954 | } |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * Called by an application that is administering the device to set the |
| 960 | * minimum number of symbols required in the password. After setting this, |
| 961 | * the user will not be able to enter a new password that is not at least as |
| 962 | * restrictive as what has been set. Note that the current password will |
| 963 | * remain until the user has set a new one, so the change does not take |
| 964 | * place immediately. To prompt the user for a new password, use |
| 965 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 966 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 967 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 968 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 969 | * <p> |
| 970 | * The calling device admin must have requested |
| 971 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 972 | * this method; if it has not, a security exception will be thrown. |
| 973 | * |
| 974 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 975 | * with. |
| 976 | * @param length The new desired minimum number of symbols required in the |
| 977 | * password. A value of 0 means there is no restriction. |
| 978 | */ |
| 979 | public void setPasswordMinimumSymbols(ComponentName admin, int length) { |
| 980 | if (mService != null) { |
| 981 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 982 | mService.setPasswordMinimumSymbols(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 983 | } catch (RemoteException e) { |
| 984 | Log.w(TAG, "Failed talking with device policy service", e); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 991 | * admins or a particular one. This is the same value as |
| 992 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 993 | * and only applies when the password quality is |
| 994 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 995 | * |
| 996 | * @param admin The name of the admin component to check, or null to |
| 997 | * aggregate all admins. |
| 998 | * @return The minimum number of symbols required in the password. |
| 999 | */ |
| 1000 | public int getPasswordMinimumSymbols(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1001 | return getPasswordMinimumSymbols(admin, UserHandle.myUserId()); |
| 1002 | } |
| 1003 | |
| 1004 | /** @hide per-user version */ |
| 1005 | public int getPasswordMinimumSymbols(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1006 | if (mService != null) { |
| 1007 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1008 | return mService.getPasswordMinimumSymbols(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1009 | } catch (RemoteException e) { |
| 1010 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1011 | } |
| 1012 | } |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1016 | /** |
| 1017 | * Called by an application that is administering the device to set the |
| 1018 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1019 | * required in the password. After setting this, the user will not be able |
| 1020 | * to enter a new password that is not at least as restrictive as what has |
| 1021 | * been set. Note that the current password will remain until the user has |
| 1022 | * set a new one, so the change does not take place immediately. To prompt |
| 1023 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1024 | * setting this value. This constraint is only imposed if the administrator |
| 1025 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1026 | * {@link #setPasswordQuality}. The default value is 0. |
| 1027 | * <p> |
| 1028 | * The calling device admin must have requested |
| 1029 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1030 | * this method; if it has not, a security exception will be thrown. |
| 1031 | * |
| 1032 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1033 | * with. |
| 1034 | * @param length The new desired minimum number of letters required in the |
| 1035 | * password. A value of 0 means there is no restriction. |
| 1036 | */ |
| 1037 | public void setPasswordMinimumNonLetter(ComponentName admin, int length) { |
| 1038 | if (mService != null) { |
| 1039 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1040 | mService.setPasswordMinimumNonLetter(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1041 | } catch (RemoteException e) { |
| 1042 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1049 | * password for all admins of this user and its profiles or a particular one. |
| 1050 | * This is the same value as set by |
| 1051 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1052 | * and only applies when the password quality is |
| 1053 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1054 | * |
| 1055 | * @param admin The name of the admin component to check, or null to |
| 1056 | * aggregate all admins. |
| 1057 | * @return The minimum number of letters required in the password. |
| 1058 | */ |
| 1059 | public int getPasswordMinimumNonLetter(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1060 | return getPasswordMinimumNonLetter(admin, UserHandle.myUserId()); |
| 1061 | } |
| 1062 | |
| 1063 | /** @hide per-user version */ |
| 1064 | public int getPasswordMinimumNonLetter(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1065 | if (mService != null) { |
| 1066 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1067 | return mService.getPasswordMinimumNonLetter(admin, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1068 | } catch (RemoteException e) { |
| 1069 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1070 | } |
| 1071 | } |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1075 | /** |
| 1076 | * Called by an application that is administering the device to set the length |
| 1077 | * of the password history. After setting this, the user will not be able to |
| 1078 | * enter a new password that is the same as any password in the history. Note |
| 1079 | * that the current password will remain until the user has set a new one, so |
| 1080 | * the change does not take place immediately. To prompt the user for a new |
| 1081 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1082 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1083 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1084 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1085 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1086 | * |
| 1087 | * <p> |
| 1088 | * The calling device admin must have requested |
| 1089 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1090 | * method; if it has not, a security exception will be thrown. |
| 1091 | * |
| 1092 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1093 | * with. |
| 1094 | * @param length The new desired length of password history. A value of 0 |
| 1095 | * means there is no restriction. |
| 1096 | */ |
| 1097 | public void setPasswordHistoryLength(ComponentName admin, int length) { |
| 1098 | if (mService != null) { |
| 1099 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1100 | mService.setPasswordHistoryLength(admin, length, UserHandle.myUserId()); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1101 | } catch (RemoteException e) { |
| 1102 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1108 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1109 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1110 | * the device password (for all admins). |
| 1111 | * |
| 1112 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1113 | * For example, to have the password expire 5 days from now, timeout would be |
| 1114 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1115 | * |
| 1116 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1117 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1118 | * <p>The calling device admin must have requested |
| 1119 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1120 | * method; if it has not, a security exception will be thrown. |
| 1121 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1122 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1123 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1124 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1125 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1126 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1127 | * means there is no restriction (unlimited). |
| 1128 | */ |
| 1129 | public void setPasswordExpirationTimeout(ComponentName admin, long timeout) { |
| 1130 | if (mService != null) { |
| 1131 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1132 | mService.setPasswordExpirationTimeout(admin, timeout, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1133 | } catch (RemoteException e) { |
| 1134 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1140 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1141 | * recurring expiration timeout provided in the call to |
| 1142 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
| 1143 | * aggregate of all policy administrators if admin is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1144 | * |
| 1145 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1146 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1147 | */ |
| 1148 | public long getPasswordExpirationTimeout(ComponentName admin) { |
| 1149 | if (mService != null) { |
| 1150 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1151 | return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1152 | } catch (RemoteException e) { |
| 1153 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1154 | } |
| 1155 | } |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Get the current password expiration time for the given admin or an aggregate of |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1161 | * all admins of this user and its profiles if admin is null. If the password is |
| 1162 | * expired, this will return the time since the password expired as a negative number. |
| 1163 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1164 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1165 | * |
| 1166 | * @param admin The name of the admin component to check, or null to aggregate all admins. |
| 1167 | * @return The password expiration time, in ms. |
| 1168 | */ |
| 1169 | public long getPasswordExpiration(ComponentName admin) { |
| 1170 | if (mService != null) { |
| 1171 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1172 | return mService.getPasswordExpiration(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1173 | } catch (RemoteException e) { |
| 1174 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1175 | } |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1181 | * Retrieve the current password history length for all admins of this |
| 1182 | * user and its profiles or a particular one. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1183 | * @param admin The name of the admin component to check, or null to aggregate |
| 1184 | * all admins. |
| 1185 | * @return The length of the password history |
| 1186 | */ |
| 1187 | public int getPasswordHistoryLength(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1188 | return getPasswordHistoryLength(admin, UserHandle.myUserId()); |
| 1189 | } |
| 1190 | |
| 1191 | /** @hide per-user version */ |
| 1192 | public int getPasswordHistoryLength(ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1193 | if (mService != null) { |
| 1194 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1195 | return mService.getPasswordHistoryLength(admin, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1196 | } catch (RemoteException e) { |
| 1197 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1198 | } |
| 1199 | } |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1203 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1204 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1205 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1206 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1207 | * @return Returns the maximum length that the user can enter. |
| 1208 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1209 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1210 | // Kind-of arbitrary. |
| 1211 | return 16; |
| 1212 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1213 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1214 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1215 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1216 | * to meet the policy requirements (quality, minimum length) that have been |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1217 | * requested by the admins of this user and its profiles. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1218 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1219 | * <p>The calling device admin must have requested |
| 1220 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1221 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1222 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1223 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1224 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1225 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1226 | if (mService != null) { |
| 1227 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1228 | return mService.isActivePasswordSufficient(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1229 | } catch (RemoteException e) { |
| 1230 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1231 | } |
| 1232 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1233 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1234 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1235 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1236 | /** |
| 1237 | * Retrieve the number of times the user has failed at entering a |
| 1238 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1239 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1240 | * <p>The calling device admin must have requested |
| 1241 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1242 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1243 | */ |
| 1244 | public int getCurrentFailedPasswordAttempts() { |
| 1245 | if (mService != null) { |
| 1246 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1247 | return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1248 | } catch (RemoteException e) { |
| 1249 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1250 | } |
| 1251 | } |
| 1252 | return -1; |
| 1253 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1254 | |
| 1255 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1256 | * Setting this to a value greater than zero enables a built-in policy |
| 1257 | * that will perform a device wipe after too many incorrect |
| 1258 | * device-unlock passwords have been entered. This built-in policy combines |
| 1259 | * watching for failed passwords and wiping the device, and requires |
| 1260 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1261 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1262 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1263 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1264 | * application only, erasing or revoking credentials, or reporting the |
| 1265 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1266 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1267 | * instead. Do not use this API, because if the maximum count is reached, |
| 1268 | * the device will be wiped immediately, and your callback will not be invoked. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1269 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1270 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1271 | * @param num The number of failed password attempts at which point the |
| 1272 | * device will wipe its data. |
| 1273 | */ |
| 1274 | public void setMaximumFailedPasswordsForWipe(ComponentName admin, int num) { |
| 1275 | if (mService != null) { |
| 1276 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1277 | mService.setMaximumFailedPasswordsForWipe(admin, num, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1278 | } catch (RemoteException e) { |
| 1279 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1283 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1284 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1285 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1286 | * before the device wipes itself, for all admins of this user and its profiles |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1287 | * or a particular one. |
| 1288 | * @param admin The name of the admin component to check, or null to aggregate |
| 1289 | * all admins. |
| 1290 | */ |
| 1291 | public int getMaximumFailedPasswordsForWipe(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1292 | return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId()); |
| 1293 | } |
| 1294 | |
| 1295 | /** @hide per-user version */ |
| 1296 | public int getMaximumFailedPasswordsForWipe(ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1297 | if (mService != null) { |
| 1298 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1299 | return mService.getMaximumFailedPasswordsForWipe(admin, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1300 | } catch (RemoteException e) { |
| 1301 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1302 | } |
| 1303 | } |
| 1304 | return 0; |
| 1305 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1306 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1307 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1308 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1309 | * the password again until the user has entered it. |
| 1310 | */ |
| 1311 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1312 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1313 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1314 | * Force a new device unlock password (the password needed to access the |
| 1315 | * entire device, not for individual accounts) on the user. This takes |
| 1316 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1317 | * The given password must be sufficient for the |
| 1318 | * current password quality and length constraints as returned by |
| 1319 | * {@link #getPasswordQuality(ComponentName)} and |
| 1320 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1321 | * these constraints, then it will be rejected and false returned. Note |
| 1322 | * that the password may be a stronger quality (containing alphanumeric |
| 1323 | * characters when the requested quality is only numeric), in which case |
| 1324 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1325 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1326 | * <p>The calling device admin must have requested |
| 1327 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1328 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1329 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1330 | * Can not be called from a managed profile. |
| 1331 | * |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1332 | * @param password The new password for the user. |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1333 | * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1334 | * @return Returns true if the password was applied, or false if it is |
| 1335 | * not acceptable for the current constraints. |
| 1336 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1337 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1338 | if (mService != null) { |
| 1339 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1340 | return mService.resetPassword(password, flags, UserHandle.myUserId()); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1341 | } catch (RemoteException e) { |
| 1342 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1343 | } |
| 1344 | } |
| 1345 | return false; |
| 1346 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1347 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1348 | /** |
| 1349 | * Called by an application that is administering the device to set the |
| 1350 | * maximum time for user activity until the device will lock. This limits |
| 1351 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1352 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1353 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1354 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1355 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1356 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1357 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1358 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1359 | * A value of 0 means there is no restriction. |
| 1360 | */ |
| 1361 | public void setMaximumTimeToLock(ComponentName admin, long timeMs) { |
| 1362 | if (mService != null) { |
| 1363 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1364 | mService.setMaximumTimeToLock(admin, timeMs, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1365 | } catch (RemoteException e) { |
| 1366 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1367 | } |
| 1368 | } |
| 1369 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1370 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1371 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1372 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1373 | * and its profiles or a particular one. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1374 | * @param admin The name of the admin component to check, or null to aggregate |
| 1375 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1376 | */ |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1377 | public long getMaximumTimeToLock(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1378 | return getMaximumTimeToLock(admin, UserHandle.myUserId()); |
| 1379 | } |
| 1380 | |
| 1381 | /** @hide per-user version */ |
| 1382 | public long getMaximumTimeToLock(ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1383 | if (mService != null) { |
| 1384 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1385 | return mService.getMaximumTimeToLock(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1386 | } catch (RemoteException e) { |
| 1387 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1388 | } |
| 1389 | } |
| 1390 | return 0; |
| 1391 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1392 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1393 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1394 | * Make the device lock immediately, as if the lock screen timeout has |
| 1395 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1396 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1397 | * <p>The calling device admin must have requested |
| 1398 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 1399 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1400 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1401 | public void lockNow() { |
| 1402 | if (mService != null) { |
| 1403 | try { |
| 1404 | mService.lockNow(); |
| 1405 | } catch (RemoteException e) { |
| 1406 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1407 | } |
| 1408 | } |
| 1409 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1410 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1411 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1412 | * Flag for {@link #wipeData(int)}: also erase the device's external |
| 1413 | * storage. |
| 1414 | */ |
| 1415 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 1416 | |
| 1417 | /** |
Paul Quei | 2450a0e | 2013-09-20 09:26:21 +0800 | [diff] [blame] | 1418 | * Ask the user data be wiped. This will cause the device to reboot, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1419 | * erasing all user data while next booting up. External storage such |
Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 1420 | * as SD cards will be also erased if the flag {@link #WIPE_EXTERNAL_STORAGE} |
| 1421 | * is set. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1422 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1423 | * <p>The calling device admin must have requested |
| 1424 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 1425 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1426 | * |
Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 1427 | * @param flags Bit mask of additional options: currently 0 and |
| 1428 | * {@link #WIPE_EXTERNAL_STORAGE} are supported. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1429 | */ |
| 1430 | public void wipeData(int flags) { |
| 1431 | if (mService != null) { |
| 1432 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1433 | mService.wipeData(flags, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1434 | } catch (RemoteException e) { |
| 1435 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1436 | } |
| 1437 | } |
| 1438 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1439 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1440 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1441 | * Called by an application that is administering the device to set the |
| 1442 | * global proxy and exclusion list. |
| 1443 | * <p> |
| 1444 | * The calling device admin must have requested |
| 1445 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 1446 | * this method; if it has not, a security exception will be thrown. |
| 1447 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1448 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
| 1449 | * proxy will be returned. If successful in setting the proxy, null will |
| 1450 | * be returned. |
| 1451 | * The method can be called repeatedly by the device admin alrady setting the |
| 1452 | * proxy to update the proxy and exclusion list. |
| 1453 | * |
| 1454 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1455 | * with. |
| 1456 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1457 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1458 | * @param exclusionList a list of domains to be excluded from the global proxy. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1459 | * @return returns null if the proxy was successfully set, or a {@link ComponentName} |
| 1460 | * of the device admin that sets thew proxy otherwise. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1461 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1462 | */ |
| 1463 | public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec, |
| 1464 | List<String> exclusionList ) { |
| 1465 | if (proxySpec == null) { |
| 1466 | throw new NullPointerException(); |
| 1467 | } |
| 1468 | if (mService != null) { |
| 1469 | try { |
| 1470 | String hostSpec; |
| 1471 | String exclSpec; |
| 1472 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1473 | hostSpec = null; |
| 1474 | exclSpec = null; |
| 1475 | } else { |
| 1476 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1477 | throw new IllegalArgumentException(); |
| 1478 | } |
| 1479 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1480 | String hostName = sa.getHostName(); |
| 1481 | int port = sa.getPort(); |
| 1482 | StringBuilder hostBuilder = new StringBuilder(); |
| 1483 | hostSpec = hostBuilder.append(hostName) |
| 1484 | .append(":").append(Integer.toString(port)).toString(); |
| 1485 | if (exclusionList == null) { |
| 1486 | exclSpec = ""; |
| 1487 | } else { |
| 1488 | StringBuilder listBuilder = new StringBuilder(); |
| 1489 | boolean firstDomain = true; |
| 1490 | for (String exclDomain : exclusionList) { |
| 1491 | if (!firstDomain) { |
| 1492 | listBuilder = listBuilder.append(","); |
| 1493 | } else { |
| 1494 | firstDomain = false; |
| 1495 | } |
| 1496 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1497 | } |
| 1498 | exclSpec = listBuilder.toString(); |
| 1499 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 1500 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 1501 | != android.net.Proxy.PROXY_VALID) |
| 1502 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1503 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1504 | return mService.setGlobalProxy(admin, hostSpec, exclSpec, UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1505 | } catch (RemoteException e) { |
| 1506 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1507 | } |
| 1508 | } |
| 1509 | return null; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 1513 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 1514 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 1515 | * doing something unusual like general internal filtering this may be useful. On |
| 1516 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1517 | * |
| 1518 | * <p>This method requires the caller to be the device owner. |
| 1519 | * |
| 1520 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 1521 | * @see ProxyInfo |
| 1522 | * |
| 1523 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1524 | * with. |
| 1525 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 1526 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1527 | */ |
| 1528 | public void setRecommendedGlobalProxy(ComponentName admin, ProxyInfo proxyInfo) { |
| 1529 | if (mService != null) { |
| 1530 | try { |
| 1531 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 1532 | } catch (RemoteException e) { |
| 1533 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1539 | * Returns the component name setting the global proxy. |
| 1540 | * @return ComponentName object of the device admin that set the global proxy, or |
| 1541 | * null if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1542 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1543 | */ |
| 1544 | public ComponentName getGlobalProxyAdmin() { |
| 1545 | if (mService != null) { |
| 1546 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1547 | return mService.getGlobalProxyAdmin(UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1548 | } catch (RemoteException e) { |
| 1549 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1550 | } |
| 1551 | } |
| 1552 | return null; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1556 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1557 | * indicating that encryption is not supported. |
| 1558 | */ |
| 1559 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1560 | |
| 1561 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1562 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1563 | * indicating that encryption is supported, but is not currently active. |
| 1564 | */ |
| 1565 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1566 | |
| 1567 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1568 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1569 | * indicating that encryption is not currently active, but is currently |
| 1570 | * being activated. This is only reported by devices that support |
| 1571 | * encryption of data and only when the storage is currently |
| 1572 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 1573 | * to become encrypted will never return this value. |
| 1574 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1575 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1576 | |
| 1577 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1578 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1579 | * indicating that encryption is active. |
| 1580 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1581 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1582 | |
| 1583 | /** |
| 1584 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 1585 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 1586 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 1587 | * to check encryption status. However, on some devices this activity may never return, as |
| 1588 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 1589 | */ |
| 1590 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 1591 | public static final String ACTION_START_ENCRYPTION |
| 1592 | = "android.app.action.START_ENCRYPTION"; |
| 1593 | |
| 1594 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1595 | * Widgets are enabled in keyguard |
| 1596 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1597 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1598 | |
| 1599 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1600 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1601 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1602 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 1603 | |
| 1604 | /** |
| 1605 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1606 | */ |
| 1607 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 1608 | |
| 1609 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1610 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1611 | */ |
| 1612 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 1613 | |
| 1614 | /** |
| 1615 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 1616 | */ |
| 1617 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 1618 | |
| 1619 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 1620 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1621 | * (e.g. PIN/Pattern/Password). |
| 1622 | */ |
| 1623 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 1624 | |
| 1625 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 1626 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 1627 | */ |
| 1628 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 1629 | |
| 1630 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1631 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1632 | */ |
| 1633 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1634 | |
| 1635 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1636 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1637 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1638 | * |
| 1639 | * <p>When multiple device administrators attempt to control device |
| 1640 | * encryption, the most secure, supported setting will always be |
| 1641 | * used. If any device administrator requests device encryption, |
| 1642 | * it will be enabled; Conversely, if a device administrator |
| 1643 | * attempts to disable device encryption while another |
| 1644 | * device administrator has enabled it, the call to disable will |
| 1645 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 1646 | * |
| 1647 | * <p>This policy controls encryption of the secure (application data) storage area. Data |
Andy Stadler | 50c294f | 2011-03-07 19:13:42 -0800 | [diff] [blame] | 1648 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 1649 | * or control the encryption of any other storage areas. |
| 1650 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 1651 | * {@code true}, then the directory returned by |
| 1652 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 1653 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1654 | * |
| 1655 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 1656 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 1657 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 1658 | * also require (and check for) a pattern, PIN, or password. |
| 1659 | * |
| 1660 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1661 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1662 | * @return the new request status (for all active admins) - will be one of |
| 1663 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 1664 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 1665 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1666 | */ |
| 1667 | public int setStorageEncryption(ComponentName admin, boolean encrypt) { |
| 1668 | if (mService != null) { |
| 1669 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1670 | return mService.setStorageEncryption(admin, encrypt, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1671 | } catch (RemoteException e) { |
| 1672 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1673 | } |
| 1674 | } |
| 1675 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1680 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1681 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1682 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 1683 | * this will return the requested encryption setting as an aggregate of all active |
| 1684 | * administrators. |
| 1685 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1686 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1687 | public boolean getStorageEncryption(ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1688 | if (mService != null) { |
| 1689 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1690 | return mService.getStorageEncryption(admin, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1691 | } catch (RemoteException e) { |
| 1692 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1693 | } |
| 1694 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1695 | return false; |
| 1696 | } |
| 1697 | |
| 1698 | /** |
| 1699 | * Called by an application that is administering the device to |
| 1700 | * determine the current encryption status of the device. |
| 1701 | * |
| 1702 | * Depending on the returned status code, the caller may proceed in different |
| 1703 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 1704 | * storage system does not support encryption. If the |
| 1705 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 1706 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
| 1707 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
| 1708 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 1709 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1710 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1711 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
| 1712 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, or{@link #ENCRYPTION_STATUS_ACTIVE}. |
| 1713 | */ |
| 1714 | public int getStorageEncryptionStatus() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1715 | return getStorageEncryptionStatus(UserHandle.myUserId()); |
| 1716 | } |
| 1717 | |
| 1718 | /** @hide per-user version */ |
| 1719 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1720 | if (mService != null) { |
| 1721 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1722 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1723 | } catch (RemoteException e) { |
| 1724 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1725 | } |
| 1726 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1727 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1731 | * Installs the given certificate as a user CA. |
| 1732 | * |
| 1733 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1734 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1735 | * |
| 1736 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1737 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1738 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1739 | public boolean installCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1740 | if (mService != null) { |
| 1741 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1742 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1743 | } catch (RemoteException e) { |
| 1744 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1745 | } |
| 1746 | } |
| 1747 | return false; |
| 1748 | } |
| 1749 | |
| 1750 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1751 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 1752 | * |
| 1753 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1754 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1755 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1756 | public void uninstallCaCert(ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1757 | if (mService != null) { |
| 1758 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1759 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1760 | mService.uninstallCaCert(admin, alias); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1761 | } catch (CertificateException e) { |
| 1762 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1763 | } catch (RemoteException e) { |
| 1764 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1770 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 1771 | * If a user has installed any certificates by other means than device policy these will be |
| 1772 | * included too. |
| 1773 | * |
| 1774 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1775 | */ |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1776 | public List<byte[]> getInstalledCaCerts() { |
| 1777 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 1778 | List<byte[]> certs = new ArrayList<byte[]>(); |
| 1779 | for (String alias : certStore.userAliases()) { |
| 1780 | try { |
| 1781 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 1782 | } catch (CertificateException ce) { |
| 1783 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 1784 | } |
| 1785 | } |
| 1786 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 1790 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 1791 | * means other than device policy will also be removed, except for system CA certificates. |
| 1792 | * |
| 1793 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1794 | */ |
| 1795 | public void uninstallAllUserCaCerts(ComponentName admin) { |
| 1796 | if (mService != null) { |
| 1797 | for (String alias : new TrustedCertificateStore().userAliases()) { |
| 1798 | try { |
| 1799 | mService.uninstallCaCert(admin, alias); |
| 1800 | } catch (RemoteException re) { |
| 1801 | Log.w(TAG, "Failed talking with device policy service", re); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | /** |
| 1808 | * Returns whether this certificate is installed as a trusted CA. |
| 1809 | * |
| 1810 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1811 | */ |
| 1812 | public boolean hasCaCertInstalled(byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1813 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1814 | return getCaCertAlias(certBuffer) != null; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 1815 | } catch (CertificateException ce) { |
| 1816 | Log.w(TAG, "Could not parse certificate", ce); |
| 1817 | } |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | /** |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 1822 | * Returns the alias of a given CA certificate in the certificate store, or null if it |
| 1823 | * doesn't exist. |
| 1824 | */ |
| 1825 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 1826 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 1827 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 1828 | new ByteArrayInputStream(certBuffer)); |
| 1829 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 1830 | } |
| 1831 | |
| 1832 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1833 | * Called by an application that is administering the device to disable all cameras |
| 1834 | * on the device. After setting this, no applications will be able to access any cameras |
| 1835 | * on the device. |
| 1836 | * |
| 1837 | * <p>The calling device admin must have requested |
| 1838 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 1839 | * this method; if it has not, a security exception will be thrown. |
| 1840 | * |
| 1841 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1842 | * @param disabled Whether or not the camera should be disabled. |
| 1843 | */ |
| 1844 | public void setCameraDisabled(ComponentName admin, boolean disabled) { |
| 1845 | if (mService != null) { |
| 1846 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1847 | mService.setCameraDisabled(admin, disabled, UserHandle.myUserId()); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1848 | } catch (RemoteException e) { |
| 1849 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | /** |
| 1855 | * Determine whether or not the device's cameras have been disabled either by the current |
| 1856 | * admin, if specified, or all admins. |
| 1857 | * @param admin The name of the admin component to check, or null to check if any admins |
| 1858 | * have disabled the camera |
| 1859 | */ |
| 1860 | public boolean getCameraDisabled(ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1861 | return getCameraDisabled(admin, UserHandle.myUserId()); |
| 1862 | } |
| 1863 | |
| 1864 | /** @hide per-user version */ |
| 1865 | public boolean getCameraDisabled(ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1866 | if (mService != null) { |
| 1867 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1868 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1869 | } catch (RemoteException e) { |
| 1870 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1871 | } |
| 1872 | } |
| 1873 | return false; |
| 1874 | } |
| 1875 | |
| 1876 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame^] | 1877 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 1878 | * screen capture also prevents the content from being shown on display devices that do not have |
| 1879 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 1880 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 1881 | * |
| 1882 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 1883 | * security exception will be thrown. |
| 1884 | * |
| 1885 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame^] | 1886 | * @param disabled Whether or not screen capture should be disabled. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 1887 | */ |
| 1888 | public void setScreenCaptureDisabled(ComponentName admin, boolean disabled) { |
| 1889 | if (mService != null) { |
| 1890 | try { |
| 1891 | mService.setScreenCaptureDisabled(admin, UserHandle.myUserId(), disabled); |
| 1892 | } catch (RemoteException e) { |
| 1893 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * Determine whether or not screen capture has been disabled by the current |
| 1900 | * admin, if specified, or all admins. |
| 1901 | * @param admin The name of the admin component to check, or null to check if any admins |
| 1902 | * have disabled screen capture. |
| 1903 | */ |
| 1904 | public boolean getScreenCaptureDisabled(ComponentName admin) { |
| 1905 | return getScreenCaptureDisabled(admin, UserHandle.myUserId()); |
| 1906 | } |
| 1907 | |
| 1908 | /** @hide per-user version */ |
| 1909 | public boolean getScreenCaptureDisabled(ComponentName admin, int userHandle) { |
| 1910 | if (mService != null) { |
| 1911 | try { |
| 1912 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 1913 | } catch (RemoteException e) { |
| 1914 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1915 | } |
| 1916 | } |
| 1917 | return false; |
| 1918 | } |
| 1919 | |
| 1920 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1921 | * Called by an application that is administering the device to disable keyguard customizations, |
| 1922 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 1923 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1924 | * |
| 1925 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1926 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1927 | * this method; if it has not, a security exception will be thrown. |
| 1928 | * |
| 1929 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1930 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 1931 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 1932 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
| 1933 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1934 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1935 | public void setKeyguardDisabledFeatures(ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1936 | if (mService != null) { |
| 1937 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1938 | mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId()); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1939 | } catch (RemoteException e) { |
| 1940 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1941 | } |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1946 | * Determine whether or not features have been disabled in keyguard either by the current |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1947 | * admin, if specified, or all admins. |
| 1948 | * @param admin The name of the admin component to check, or null to check if any admins |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1949 | * have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 1950 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 1951 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1952 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1953 | public int getKeyguardDisabledFeatures(ComponentName admin) { |
| 1954 | return getKeyguardDisabledFeatures(admin, UserHandle.myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | /** @hide per-user version */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1958 | public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1959 | if (mService != null) { |
| 1960 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1961 | return mService.getKeyguardDisabledFeatures(admin, userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1962 | } catch (RemoteException e) { |
| 1963 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1964 | } |
| 1965 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 1966 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1970 | * @hide |
| 1971 | */ |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 1972 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1973 | if (mService != null) { |
| 1974 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 1975 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1976 | } catch (RemoteException e) { |
| 1977 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1978 | } |
| 1979 | } |
| 1980 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1981 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1982 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 1983 | * @hide |
| 1984 | */ |
| 1985 | public void setActiveAdmin(ComponentName policyReceiver, boolean refreshing) { |
| 1986 | setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId()); |
| 1987 | } |
| 1988 | |
| 1989 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1990 | * Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1991 | * @hide |
| 1992 | */ |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1993 | public DeviceAdminInfo getAdminInfo(ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1994 | ActivityInfo ai; |
| 1995 | try { |
| 1996 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 1997 | PackageManager.GET_META_DATA); |
| 1998 | } catch (PackageManager.NameNotFoundException e) { |
| 1999 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2000 | return null; |
| 2001 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2002 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2003 | ResolveInfo ri = new ResolveInfo(); |
| 2004 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2005 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2006 | try { |
| 2007 | return new DeviceAdminInfo(mContext, ri); |
| 2008 | } catch (XmlPullParserException e) { |
| 2009 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2010 | return null; |
| 2011 | } catch (IOException e) { |
| 2012 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2013 | return null; |
| 2014 | } |
| 2015 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2016 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2017 | /** |
| 2018 | * @hide |
| 2019 | */ |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2020 | public void getRemoveWarning(ComponentName admin, RemoteCallback result) { |
| 2021 | if (mService != null) { |
| 2022 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2023 | mService.getRemoveWarning(admin, result, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2024 | } catch (RemoteException e) { |
| 2025 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2026 | } |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * @hide |
| 2032 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2033 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2034 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2035 | if (mService != null) { |
| 2036 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2037 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2038 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2039 | } catch (RemoteException e) { |
| 2040 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2041 | } |
| 2042 | } |
| 2043 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2044 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2045 | /** |
| 2046 | * @hide |
| 2047 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2048 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2049 | if (mService != null) { |
| 2050 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2051 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2052 | } catch (RemoteException e) { |
| 2053 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2054 | } |
| 2055 | } |
| 2056 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2057 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2058 | /** |
| 2059 | * @hide |
| 2060 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2061 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2062 | if (mService != null) { |
| 2063 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2064 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2065 | } catch (RemoteException e) { |
| 2066 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2067 | } |
| 2068 | } |
| 2069 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2070 | |
| 2071 | /** |
| 2072 | * @hide |
| 2073 | * Sets the given package as the device owner. The package must already be installed and there |
| 2074 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2075 | * method must be called before the device is provisioned. |
| 2076 | * @param packageName the package name of the application to be registered as the device owner. |
| 2077 | * @return whether the package was successfully registered as the device owner. |
| 2078 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2079 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2080 | * already been provisioned. |
| 2081 | */ |
| 2082 | public boolean setDeviceOwner(String packageName) throws IllegalArgumentException, |
| 2083 | IllegalStateException { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2084 | return setDeviceOwner(packageName, null); |
| 2085 | } |
| 2086 | |
| 2087 | /** |
| 2088 | * @hide |
| 2089 | * Sets the given package as the device owner. The package must already be installed and there |
| 2090 | * shouldn't be an existing device owner registered, for this call to succeed. Also, this |
| 2091 | * method must be called before the device is provisioned. |
| 2092 | * @param packageName the package name of the application to be registered as the device owner. |
| 2093 | * @param ownerName the human readable name of the institution that owns this device. |
| 2094 | * @return whether the package was successfully registered as the device owner. |
| 2095 | * @throws IllegalArgumentException if the package name is null or invalid |
| 2096 | * @throws IllegalStateException if a device owner is already registered or the device has |
| 2097 | * already been provisioned. |
| 2098 | */ |
| 2099 | public boolean setDeviceOwner(String packageName, String ownerName) |
| 2100 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2101 | if (mService != null) { |
| 2102 | try { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2103 | return mService.setDeviceOwner(packageName, ownerName); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2104 | } catch (RemoteException re) { |
| 2105 | Log.w(TAG, "Failed to set device owner"); |
| 2106 | } |
| 2107 | } |
| 2108 | return false; |
| 2109 | } |
| 2110 | |
| 2111 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2112 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 2113 | * A device owner app is a special device admin that cannot be deactivated by the user, once |
| 2114 | * activated as a device admin. It also cannot be uninstalled. To check if a particular |
| 2115 | * package is currently registered as the device owner app, pass in the package name from |
| 2116 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
| 2117 | * admin apps that want to check if they are also registered as the device owner app. The |
| 2118 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 2119 | * the setup process. |
| 2120 | * @param packageName the package name of the app, to compare with the registered device owner |
| 2121 | * app, if any. |
| 2122 | * @return whether or not the package is registered as the device owner app. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2123 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2124 | public boolean isDeviceOwnerApp(String packageName) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2125 | if (mService != null) { |
| 2126 | try { |
| 2127 | return mService.isDeviceOwner(packageName); |
| 2128 | } catch (RemoteException re) { |
| 2129 | Log.w(TAG, "Failed to check device owner"); |
| 2130 | } |
| 2131 | } |
| 2132 | return false; |
| 2133 | } |
| 2134 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2135 | /** |
| 2136 | * @hide |
| 2137 | * Redirect to isDeviceOwnerApp. |
| 2138 | */ |
| 2139 | public boolean isDeviceOwner(String packageName) { |
| 2140 | return isDeviceOwnerApp(packageName); |
| 2141 | } |
| 2142 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2143 | /** |
| 2144 | * Clears the current device owner. The caller must be the device owner. |
| 2145 | * |
| 2146 | * This function should be used cautiously as once it is called it cannot |
| 2147 | * be undone. The device owner can only be set as a part of device setup |
| 2148 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2149 | * |
| 2150 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2151 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2152 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2153 | if (mService != null) { |
| 2154 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2155 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2156 | } catch (RemoteException re) { |
| 2157 | Log.w(TAG, "Failed to clear device owner"); |
| 2158 | } |
| 2159 | } |
| 2160 | } |
| 2161 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2162 | /** @hide */ |
| 2163 | public String getDeviceOwner() { |
| 2164 | if (mService != null) { |
| 2165 | try { |
| 2166 | return mService.getDeviceOwner(); |
| 2167 | } catch (RemoteException re) { |
| 2168 | Log.w(TAG, "Failed to get device owner"); |
| 2169 | } |
| 2170 | } |
| 2171 | return null; |
| 2172 | } |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2173 | |
| 2174 | /** @hide */ |
| 2175 | public String getDeviceOwnerName() { |
| 2176 | if (mService != null) { |
| 2177 | try { |
| 2178 | return mService.getDeviceOwnerName(); |
| 2179 | } catch (RemoteException re) { |
| 2180 | Log.w(TAG, "Failed to get device owner"); |
| 2181 | } |
| 2182 | } |
| 2183 | return null; |
| 2184 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2185 | |
| 2186 | /** |
| 2187 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2188 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2189 | * Sets the given component as an active admin and registers the package as the profile |
| 2190 | * owner for this user. The package must already be installed and there shouldn't be |
| 2191 | * an existing profile owner registered for this user. Also, this method must be called |
| 2192 | * before the user setup has been completed. |
| 2193 | * <p> |
| 2194 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 2195 | * MANAGE_DEVICE_ADMINS permission. |
| 2196 | * @param admin The component to register as an active admin and profile owner. |
| 2197 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 2198 | * @return whether the admin was successfully registered as the profile owner. |
| 2199 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2200 | * the user has already been set up. |
| 2201 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 2202 | @SystemApi |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2203 | public boolean setActiveProfileOwner(ComponentName admin, String ownerName) |
| 2204 | throws IllegalArgumentException { |
| 2205 | if (mService != null) { |
| 2206 | try { |
| 2207 | final int myUserId = UserHandle.myUserId(); |
| 2208 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2209 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2210 | } catch (RemoteException re) { |
| 2211 | Log.w(TAG, "Failed to set profile owner " + re); |
| 2212 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2213 | } |
| 2214 | } |
| 2215 | return false; |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2220 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 2221 | * be from the same package as the active profile owner for this user, otherwise a |
| 2222 | * SecurityException will be thrown. |
| 2223 | * |
| 2224 | * @param admin The component to remove as the profile owner. |
| 2225 | * @return |
| 2226 | */ |
| 2227 | @SystemApi |
| 2228 | public void clearProfileOwner(ComponentName admin) { |
| 2229 | if (mService != null) { |
| 2230 | try { |
| 2231 | mService.clearProfileOwner(admin); |
| 2232 | } catch (RemoteException re) { |
| 2233 | Log.w(TAG, "Failed to clear profile owner " + admin + re); |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * @hide |
| 2240 | * Checks if the user was already setup. |
| 2241 | */ |
| 2242 | public boolean hasUserSetupCompleted() { |
| 2243 | if (mService != null) { |
| 2244 | try { |
| 2245 | return mService.hasUserSetupCompleted(); |
| 2246 | } catch (RemoteException re) { |
| 2247 | Log.w(TAG, "Failed to check if user setup has completed"); |
| 2248 | } |
| 2249 | } |
| 2250 | return true; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * @deprecated Use setProfileOwner(ComponentName ...) |
| 2255 | * @hide |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2256 | * Sets the given package as the profile owner of the given user profile. The package must |
| 2257 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 2258 | * user. Also, this method must be called before the user has been used for the first time. |
| 2259 | * @param packageName the package name of the application to be registered as profile owner. |
| 2260 | * @param ownerName the human readable name of the organisation associated with this DPM. |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 2261 | * @param userHandle the userId to set the profile owner for. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2262 | * @return whether the package was successfully registered as the profile owner. |
| 2263 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2264 | * the user has already been set up. |
| 2265 | */ |
Adam Connors | 661ec47 | 2014-02-11 13:59:46 +0000 | [diff] [blame] | 2266 | public boolean setProfileOwner(String packageName, String ownerName, int userHandle) |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2267 | throws IllegalArgumentException { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2268 | if (packageName == null) { |
| 2269 | throw new NullPointerException("packageName cannot be null"); |
| 2270 | } |
| 2271 | return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle); |
| 2272 | } |
| 2273 | |
| 2274 | /** |
| 2275 | * @hide |
| 2276 | * Sets the given component as the profile owner of the given user profile. The package must |
| 2277 | * already be installed and there shouldn't be an existing profile owner registered for this |
| 2278 | * user. Only the system can call this API if the user has already completed setup. |
| 2279 | * @param admin the component name to be registered as profile owner. |
| 2280 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 2281 | * @param userHandle the userId to set the profile owner for. |
| 2282 | * @return whether the component was successfully registered as the profile owner. |
| 2283 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or |
| 2284 | * the user has already been set up. |
| 2285 | */ |
| 2286 | public boolean setProfileOwner(ComponentName admin, String ownerName, int userHandle) |
| 2287 | throws IllegalArgumentException { |
| 2288 | if (admin == null) { |
| 2289 | throw new NullPointerException("admin cannot be null"); |
| 2290 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2291 | if (mService != null) { |
| 2292 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2293 | if (ownerName == null) { |
| 2294 | ownerName = ""; |
| 2295 | } |
| 2296 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2297 | } catch (RemoteException re) { |
| 2298 | Log.w(TAG, "Failed to set profile owner", re); |
| 2299 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2300 | } |
| 2301 | } |
| 2302 | return false; |
| 2303 | } |
| 2304 | |
| 2305 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2306 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 2307 | * be used. Only the profile owner can call this. |
| 2308 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2309 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2310 | * |
| 2311 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2312 | */ |
| 2313 | public void setProfileEnabled(ComponentName admin) { |
| 2314 | if (mService != null) { |
| 2315 | try { |
| 2316 | mService.setProfileEnabled(admin); |
| 2317 | } catch (RemoteException e) { |
| 2318 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | /** |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 2324 | * Sets the name of the Managed profile. In the device owner case it sets the name of the user |
| 2325 | * which it is called from. Only the profile owner or device owner can call this. If this is |
| 2326 | * never called by the profile or device owner, the name will be set to default values. |
| 2327 | * |
| 2328 | * @see #isProfileOwnerApp |
| 2329 | * @see #isDeviceOwnerApp |
| 2330 | * |
| 2331 | * @param profileName The name of the profile. |
| 2332 | */ |
| 2333 | public void setProfileName(ComponentName who, String profileName) { |
| 2334 | if (mService != null) { |
| 2335 | try { |
| 2336 | mService.setProfileName(who, profileName); |
| 2337 | } catch (RemoteException e) { |
| 2338 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2344 | * Used to determine if a particular package is registered as the Profile Owner for the |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2345 | * current user. A profile owner is a special device admin that has additional privileges |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2346 | * within the managed profile. |
| 2347 | * |
| 2348 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 2349 | * @return Whether or not the package is registered as the profile owner. |
| 2350 | */ |
| 2351 | public boolean isProfileOwnerApp(String packageName) { |
| 2352 | if (mService != null) { |
| 2353 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 2354 | ComponentName profileOwner = mService.getProfileOwner( |
| 2355 | Process.myUserHandle().getIdentifier()); |
| 2356 | return profileOwner != null |
| 2357 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2358 | } catch (RemoteException re) { |
| 2359 | Log.w(TAG, "Failed to check profile owner"); |
| 2360 | } |
| 2361 | } |
| 2362 | return false; |
| 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * @hide |
| 2367 | * @return the packageName of the owner of the given user profile or null if no profile |
| 2368 | * owner has been set for that user. |
| 2369 | * @throws IllegalArgumentException if the userId is invalid. |
| 2370 | */ |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2371 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2372 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 2373 | } |
| 2374 | |
| 2375 | /** |
| 2376 | * @see #getProfileOwner() |
| 2377 | * @hide |
| 2378 | */ |
| 2379 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2380 | if (mService != null) { |
| 2381 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2382 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2383 | } catch (RemoteException re) { |
| 2384 | Log.w(TAG, "Failed to get profile owner"); |
| 2385 | throw new IllegalArgumentException( |
| 2386 | "Requested profile owner for invalid userId", re); |
| 2387 | } |
| 2388 | } |
| 2389 | return null; |
| 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * @hide |
| 2394 | * @return the human readable name of the organisation associated with this DPM or null if |
| 2395 | * one is not set. |
| 2396 | * @throws IllegalArgumentException if the userId is invalid. |
| 2397 | */ |
| 2398 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 2399 | if (mService != null) { |
| 2400 | try { |
| 2401 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 2402 | } catch (RemoteException re) { |
| 2403 | Log.w(TAG, "Failed to get profile owner"); |
| 2404 | throw new IllegalArgumentException( |
| 2405 | "Requested profile owner for invalid userId", re); |
| 2406 | } |
| 2407 | } |
| 2408 | return null; |
| 2409 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2410 | |
| 2411 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 2412 | * @hide |
| 2413 | * @param user The user for whom to fetch the profile owner name, if any. |
| 2414 | * @return the human readable name of the organisation associated with this profile owner or |
| 2415 | * null if one is not set. |
| 2416 | * @throws IllegalArgumentException if the userId is invalid. |
| 2417 | */ |
| 2418 | @SystemApi |
| 2419 | public String getProfileOwnerNameAsUser(UserHandle user) throws IllegalArgumentException { |
| 2420 | if (mService != null) { |
| 2421 | try { |
| 2422 | return mService.getProfileOwnerName(user.getIdentifier()); |
| 2423 | } catch (RemoteException re) { |
| 2424 | Log.w(TAG, "Failed to get profile owner"); |
| 2425 | throw new IllegalArgumentException( |
| 2426 | "Requested profile owner for invalid userId", re); |
| 2427 | } |
| 2428 | } |
| 2429 | return null; |
| 2430 | } |
| 2431 | |
| 2432 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2433 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 2434 | * intents that match a certain intent filter. This activity will remain the default intent |
| 2435 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 2436 | * the intent preferences are reset. |
| 2437 | * |
| 2438 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 2439 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 2440 | * intent handler for the filter. |
| 2441 | * |
| 2442 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 2443 | * security exception will be thrown. |
| 2444 | * |
| 2445 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2446 | * @param filter The IntentFilter for which a default handler is added. |
| 2447 | * @param activity The Activity that is added as default intent handler. |
| 2448 | */ |
| 2449 | public void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, |
| 2450 | ComponentName activity) { |
| 2451 | if (mService != null) { |
| 2452 | try { |
| 2453 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 2454 | } catch (RemoteException e) { |
| 2455 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * Called by a profile owner or device owner to remove all persistent intent handler preferences |
Torne (Richard Coles) | 875e210 | 2014-02-24 14:11:56 +0000 | [diff] [blame] | 2462 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 2463 | * |
| 2464 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 2465 | * exception will be thrown. |
| 2466 | * |
| 2467 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2468 | * @param packageName The name of the package for which preferences are removed. |
| 2469 | */ |
| 2470 | public void clearPackagePersistentPreferredActivities(ComponentName admin, |
| 2471 | String packageName) { |
| 2472 | if (mService != null) { |
| 2473 | try { |
| 2474 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 2475 | } catch (RemoteException e) { |
| 2476 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2477 | } |
| 2478 | } |
| 2479 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2480 | |
| 2481 | /** |
| 2482 | * Called by a profile or device owner to set the application restrictions for a given target |
| 2483 | * application running in the managed profile. |
| 2484 | * |
| 2485 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be |
Amith Yamasani | c8c8425 | 2014-07-13 17:12:12 -0700 | [diff] [blame] | 2486 | * boolean, int, String, or String[]. The recommended format for keys |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2487 | * is "com.example.packagename/example-setting" to avoid naming conflicts with library |
| 2488 | * components such as {@link android.webkit.WebView}. |
| 2489 | * |
| 2490 | * <p>The application restrictions are only made visible to the target application and the |
| 2491 | * profile or device owner. |
| 2492 | * |
| 2493 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 2494 | * exception will be thrown. |
| 2495 | * |
| 2496 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2497 | * @param packageName The name of the package to update restricted settings for. |
| 2498 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 2499 | * set of active restrictions. |
| 2500 | */ |
| 2501 | public void setApplicationRestrictions(ComponentName admin, String packageName, |
| 2502 | Bundle settings) { |
| 2503 | if (mService != null) { |
| 2504 | try { |
| 2505 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 2506 | } catch (RemoteException e) { |
| 2507 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | /** |
Adrian Roos | 489d2df | 2014-07-29 21:01:39 +0200 | [diff] [blame] | 2513 | * Sets a list of features to enable for a TrustAgent component. This is meant to be |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2514 | * used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which will disable all |
| 2515 | * trust agents but those with features enabled by this function call. |
| 2516 | * |
| 2517 | * <p>The calling device admin must have requested |
| 2518 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
| 2519 | * this method; if it has not, a security exception will be thrown. |
| 2520 | * |
| 2521 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2522 | * @param agent Which component to enable features for. |
| 2523 | * @param features List of features to enable. Consult specific TrustAgent documentation for |
| 2524 | * the feature list. |
| 2525 | */ |
| 2526 | public void setTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent, |
| 2527 | List<String> features) { |
| 2528 | if (mService != null) { |
| 2529 | try { |
| 2530 | mService.setTrustAgentFeaturesEnabled(admin, agent, features, UserHandle.myUserId()); |
| 2531 | } catch (RemoteException e) { |
| 2532 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2533 | } |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | /** |
Adrian Roos | 489d2df | 2014-07-29 21:01:39 +0200 | [diff] [blame] | 2538 | * Gets list of enabled features for the given TrustAgent component. If admin is |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 2539 | * null, this will return the intersection of all features enabled for the given agent by all |
| 2540 | * admins. |
| 2541 | * |
| 2542 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2543 | * @param agent Which component to get enabled features for. |
| 2544 | * @return List of enabled features. |
| 2545 | */ |
| 2546 | public List<String> getTrustAgentFeaturesEnabled(ComponentName admin, ComponentName agent) { |
| 2547 | if (mService != null) { |
| 2548 | try { |
| 2549 | return mService.getTrustAgentFeaturesEnabled(admin, agent, UserHandle.myUserId()); |
| 2550 | } catch (RemoteException e) { |
| 2551 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2552 | } |
| 2553 | } |
| 2554 | return new ArrayList<String>(); // empty list |
| 2555 | } |
| 2556 | |
| 2557 | /** |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 2558 | * Called by a profile owner to set whether caller-Id information from the managed |
| 2559 | * profile will be shown for incoming calls. |
| 2560 | * |
| 2561 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 2562 | * security exception will be thrown. |
| 2563 | * |
| 2564 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2565 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 2566 | */ |
| 2567 | public void setCrossProfileCallerIdDisabled(ComponentName who, boolean disabled) { |
| 2568 | if (mService != null) { |
| 2569 | try { |
| 2570 | mService.setCrossProfileCallerIdDisabled(who, disabled); |
| 2571 | } catch (RemoteException e) { |
| 2572 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2573 | } |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | /** |
| 2578 | * Determine whether or not caller-Id information has been disabled. |
| 2579 | * |
| 2580 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 2581 | * security exception will be thrown. |
| 2582 | * |
| 2583 | * @param who Which {@link DeviceAdminReceiver} this request is associated with. |
| 2584 | */ |
| 2585 | public boolean getCrossProfileCallerIdDisabled(ComponentName who) { |
| 2586 | if (mService != null) { |
| 2587 | try { |
| 2588 | return mService.getCrossProfileCallerIdDisabled(who); |
| 2589 | } catch (RemoteException e) { |
| 2590 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2591 | } |
| 2592 | } |
| 2593 | return false; |
| 2594 | } |
| 2595 | |
| 2596 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 2597 | * Determine whether or not caller-Id information has been disabled. |
| 2598 | * |
| 2599 | * @param userHandle The user for whom to check the caller-id permission |
| 2600 | * @hide |
| 2601 | */ |
| 2602 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 2603 | if (mService != null) { |
| 2604 | try { |
| 2605 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 2606 | } catch (RemoteException e) { |
| 2607 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2608 | } |
| 2609 | } |
| 2610 | return false; |
| 2611 | } |
| 2612 | |
| 2613 | /** |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2614 | * Called by the profile owner so that some intents sent in the managed profile can also be |
| 2615 | * resolved in the parent, or vice versa. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2616 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2617 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 2618 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 2619 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 2620 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2621 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2622 | public void addCrossProfileIntentFilter(ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2623 | if (mService != null) { |
| 2624 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2625 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2626 | } catch (RemoteException e) { |
| 2627 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2628 | } |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | /** |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 2633 | * Called by a profile owner to remove the cross-profile intent filters that go from the |
| 2634 | * managed profile to the parent, or from the parent to the managed profile. |
| 2635 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2636 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2637 | */ |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2638 | public void clearCrossProfileIntentFilters(ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2639 | if (mService != null) { |
| 2640 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2641 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 2642 | } catch (RemoteException e) { |
| 2643 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2644 | } |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 2649 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 2650 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 2651 | * created. If you need to persist an identifier for this user, use |
| 2652 | * {@link UserManager#getSerialNumberForUser}. |
| 2653 | * |
| 2654 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2655 | * @param name the user's name |
| 2656 | * @see UserHandle |
| 2657 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 2658 | */ |
| 2659 | public UserHandle createUser(ComponentName admin, String name) { |
| 2660 | try { |
| 2661 | return mService.createUser(admin, name); |
| 2662 | } catch (RemoteException re) { |
| 2663 | Log.w(TAG, "Could not create a user", re); |
| 2664 | } |
| 2665 | return null; |
| 2666 | } |
| 2667 | |
| 2668 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 2669 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 2670 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 2671 | * created. If you need to persist an identifier for this user, use |
| 2672 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 2673 | * immediately. |
| 2674 | * |
| 2675 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 2676 | * as registered as an active admin on the new user. The profile owner package will be |
| 2677 | * installed on the new user if it already is installed on the device. |
| 2678 | * |
| 2679 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 2680 | * profileOwnerComponent when onEnable is called. |
| 2681 | * |
| 2682 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2683 | * @param name the user's name |
| 2684 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 2685 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 2686 | * the user. |
| 2687 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 2688 | * on the new user. |
| 2689 | * @see UserHandle |
| 2690 | * @return the UserHandle object for the created user, or null if the user could not be created. |
| 2691 | */ |
| 2692 | public UserHandle createAndInitializeUser(ComponentName admin, String name, String ownerName, |
| 2693 | ComponentName profileOwnerComponent, Bundle adminExtras) { |
| 2694 | try { |
| 2695 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 2696 | adminExtras); |
| 2697 | } catch (RemoteException re) { |
| 2698 | Log.w(TAG, "Could not create a user", re); |
| 2699 | } |
| 2700 | return null; |
| 2701 | } |
| 2702 | |
| 2703 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 2704 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 2705 | * not be removed. |
| 2706 | * |
| 2707 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2708 | * @param userHandle the user to remove. |
| 2709 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 2710 | */ |
| 2711 | public boolean removeUser(ComponentName admin, UserHandle userHandle) { |
| 2712 | try { |
| 2713 | return mService.removeUser(admin, userHandle); |
| 2714 | } catch (RemoteException re) { |
| 2715 | Log.w(TAG, "Could not remove user ", re); |
| 2716 | return false; |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 2721 | * Called by a device owner to switch the specified user to the foreground. |
| 2722 | * |
| 2723 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2724 | * @param userHandle the user to switch to; null will switch to primary. |
| 2725 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 2726 | * |
| 2727 | * @see Intent#ACTION_USER_FOREGROUND |
| 2728 | */ |
| 2729 | public boolean switchUser(ComponentName admin, UserHandle userHandle) { |
| 2730 | try { |
| 2731 | return mService.switchUser(admin, userHandle); |
| 2732 | } catch (RemoteException re) { |
| 2733 | Log.w(TAG, "Could not switch user ", re); |
| 2734 | return false; |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | /** |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 2739 | * Called by a profile or device owner to get the application restrictions for a given target |
| 2740 | * application running in the managed profile. |
| 2741 | * |
| 2742 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 2743 | * exception will be thrown. |
| 2744 | * |
| 2745 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2746 | * @param packageName The name of the package to fetch restricted settings of. |
| 2747 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 2748 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 2749 | * if no restrictions have been set. |
| 2750 | */ |
| 2751 | public Bundle getApplicationRestrictions(ComponentName admin, String packageName) { |
| 2752 | if (mService != null) { |
| 2753 | try { |
| 2754 | return mService.getApplicationRestrictions(admin, packageName); |
| 2755 | } catch (RemoteException e) { |
| 2756 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2757 | } |
| 2758 | } |
| 2759 | return null; |
| 2760 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 2761 | |
| 2762 | /** |
| 2763 | * Called by a profile or device owner to set a user restriction specified |
| 2764 | * by the key. |
| 2765 | * <p> |
| 2766 | * The calling device admin must be a profile or device owner; if it is not, |
| 2767 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 2768 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 2769 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2770 | * with. |
| 2771 | * @param key The key of the restriction. See the constants in |
| 2772 | * {@link android.os.UserManager} for the list of keys. |
| 2773 | */ |
| 2774 | public void addUserRestriction(ComponentName admin, String key) { |
| 2775 | if (mService != null) { |
| 2776 | try { |
| 2777 | mService.setUserRestriction(admin, key, true); |
| 2778 | } catch (RemoteException e) { |
| 2779 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2780 | } |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | /** |
| 2785 | * Called by a profile or device owner to clear a user restriction specified |
| 2786 | * by the key. |
| 2787 | * <p> |
| 2788 | * The calling device admin must be a profile or device owner; if it is not, |
| 2789 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 2790 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 2791 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 2792 | * with. |
| 2793 | * @param key The key of the restriction. See the constants in |
| 2794 | * {@link android.os.UserManager} for the list of keys. |
| 2795 | */ |
| 2796 | public void clearUserRestriction(ComponentName admin, String key) { |
| 2797 | if (mService != null) { |
| 2798 | try { |
| 2799 | mService.setUserRestriction(admin, key, false); |
| 2800 | } catch (RemoteException e) { |
| 2801 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2802 | } |
| 2803 | } |
| 2804 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 2805 | |
| 2806 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2807 | * Called by device or profile owner to hide or unhide packages. When a package is hidden it |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2808 | * is unavailable for use, but the data and actual package file remain. |
| 2809 | * |
| 2810 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2811 | * @param packageName The name of the package to hide or unhide. |
| 2812 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 2813 | * unhidden. |
| 2814 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2815 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2816 | public boolean setApplicationHidden(ComponentName admin, String packageName, |
| 2817 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2818 | if (mService != null) { |
| 2819 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2820 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2821 | } catch (RemoteException e) { |
| 2822 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2823 | } |
| 2824 | } |
| 2825 | return false; |
| 2826 | } |
| 2827 | |
| 2828 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2829 | * Called by profile or device owner to hide or unhide currently installed packages. This |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2830 | * should only be called by a profile or device owner running within a managed profile. |
| 2831 | * |
| 2832 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2833 | * @param intent An intent matching the app(s) to be updated. All apps that resolve for this |
| 2834 | * intent will be updated in the current profile. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2835 | * @param hidden {@code true} if the packages should be hidden, {@code false} if they should |
| 2836 | * be unhidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2837 | * @return int The number of activities that matched the intent and were updated. |
| 2838 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2839 | public int setApplicationsHidden(ComponentName admin, Intent intent, boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2840 | if (mService != null) { |
| 2841 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2842 | return mService.setApplicationsHidden(admin, intent, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2843 | } catch (RemoteException e) { |
| 2844 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2845 | } |
| 2846 | } |
| 2847 | return 0; |
| 2848 | } |
| 2849 | |
| 2850 | /** |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2851 | * Called by device or profile owner to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2852 | * |
| 2853 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2854 | * @param packageName The name of the package to retrieve the hidden status of. |
| 2855 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2856 | */ |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2857 | public boolean isApplicationHidden(ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2858 | if (mService != null) { |
| 2859 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2860 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 2861 | } catch (RemoteException e) { |
| 2862 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2863 | } |
| 2864 | } |
| 2865 | return false; |
| 2866 | } |
| 2867 | |
| 2868 | /** |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 2869 | * Called by profile or device owner to re-enable a system app that was disabled by default |
| 2870 | * when the managed profile was created. This can only be called from a profile or device |
| 2871 | * owner running within a managed profile. |
| 2872 | * |
| 2873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2874 | * @param packageName The package to be re-enabled in the current profile. |
| 2875 | */ |
| 2876 | public void enableSystemApp(ComponentName admin, String packageName) { |
| 2877 | if (mService != null) { |
| 2878 | try { |
| 2879 | mService.enableSystemApp(admin, packageName); |
| 2880 | } catch (RemoteException e) { |
| 2881 | Log.w(TAG, "Failed to install package: " + packageName); |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * Called by profile or device owner to re-enable system apps by intent that were disabled |
| 2888 | * by default when the managed profile was created. This can only be called from a profile |
| 2889 | * or device owner running within a managed profile. |
| 2890 | * |
| 2891 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2892 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
| 2893 | * intent will be re-enabled in the current profile. |
| 2894 | * @return int The number of activities that matched the intent and were installed. |
| 2895 | */ |
| 2896 | public int enableSystemApp(ComponentName admin, Intent intent) { |
| 2897 | if (mService != null) { |
| 2898 | try { |
| 2899 | return mService.enableSystemAppWithIntent(admin, intent); |
| 2900 | } catch (RemoteException e) { |
| 2901 | Log.w(TAG, "Failed to install packages matching filter: " + intent); |
| 2902 | } |
| 2903 | } |
| 2904 | return 0; |
| 2905 | } |
| 2906 | |
| 2907 | /** |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 2908 | * Called by a profile owner to disable account management for a specific type of account. |
| 2909 | * |
| 2910 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 2911 | * security exception will be thrown. |
| 2912 | * |
| 2913 | * <p>When account management is disabled for an account type, adding or removing an account |
| 2914 | * of that type will not be possible. |
| 2915 | * |
| 2916 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2917 | * @param accountType For which account management is disabled or enabled. |
| 2918 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 2919 | * enabled (false). |
| 2920 | */ |
| 2921 | public void setAccountManagementDisabled(ComponentName admin, String accountType, |
| 2922 | boolean disabled) { |
| 2923 | if (mService != null) { |
| 2924 | try { |
| 2925 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 2926 | } catch (RemoteException e) { |
| 2927 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2928 | } |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 2933 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 2934 | * |
| 2935 | * <p> Account management can be disabled/enabled by calling |
| 2936 | * {@link #setAccountManagementDisabled}. |
| 2937 | * |
| 2938 | * @return a list of account types for which account management has been disabled. |
| 2939 | * |
| 2940 | * @see #setAccountManagementDisabled |
| 2941 | */ |
| 2942 | public String[] getAccountTypesWithManagementDisabled() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 2943 | return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | /** |
| 2947 | * @see #getAccountTypesWithManagementDisabled() |
| 2948 | * @hide |
| 2949 | */ |
| 2950 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 2951 | if (mService != null) { |
| 2952 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 2953 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 2954 | } catch (RemoteException e) { |
| 2955 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | return null; |
| 2960 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2961 | |
| 2962 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 2963 | * Sets which packages may enter lock task mode. |
| 2964 | * |
| 2965 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 2966 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2967 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 2968 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 2969 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2970 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 2971 | * |
| 2972 | * @see Activity#startLockTask() |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2973 | * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String) |
| 2974 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2975 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2976 | public void setLockTaskPackages(ComponentName admin, String[] packages) |
| 2977 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2978 | if (mService != null) { |
| 2979 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2980 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2981 | } catch (RemoteException e) { |
| 2982 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2983 | } |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 2988 | * This function returns the list of packages allowed to start the lock task mode. |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2989 | * |
| 2990 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2991 | * @hide |
| 2992 | */ |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2993 | public String[] getLockTaskPackages(ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2994 | if (mService != null) { |
| 2995 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 2996 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 2997 | } catch (RemoteException e) { |
| 2998 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2999 | } |
| 3000 | } |
| 3001 | return null; |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * This function lets the caller know whether the given component is allowed to start the |
| 3006 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3007 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3008 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3009 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3010 | if (mService != null) { |
| 3011 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3012 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3013 | } catch (RemoteException e) { |
| 3014 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3015 | } |
| 3016 | } |
| 3017 | return false; |
| 3018 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3019 | |
| 3020 | /** |
| 3021 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 3022 | * of the setting is in the correct form for the setting type should be performed by the caller. |
| 3023 | * |
| 3024 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3025 | * @param setting The name of the setting to update. |
| 3026 | * @param value The value to update the setting to. |
| 3027 | */ |
| 3028 | public void setGlobalSetting(ComponentName admin, String setting, String value) { |
| 3029 | if (mService != null) { |
| 3030 | try { |
| 3031 | mService.setGlobalSetting(admin, setting, value); |
| 3032 | } catch (RemoteException e) { |
| 3033 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 3040 | * that the value of the setting is in the correct form for the setting type should be performed |
| 3041 | * by the caller. |
| 3042 | * |
| 3043 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3044 | * @param setting The name of the setting to update. |
| 3045 | * @param value The value to update the setting to. |
| 3046 | */ |
| 3047 | public void setSecureSetting(ComponentName admin, String setting, String value) { |
| 3048 | if (mService != null) { |
| 3049 | try { |
| 3050 | mService.setSecureSetting(admin, setting, value); |
| 3051 | } catch (RemoteException e) { |
| 3052 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3053 | } |
| 3054 | } |
| 3055 | } |
| 3056 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3057 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3058 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3059 | * making permission requests of a local or remote administrator of the user. |
| 3060 | * <p/> |
| 3061 | * Only a profile owner can designate the restrictions provider. |
| 3062 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3063 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 3064 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3065 | * it removes the restrictions provider previously assigned. |
| 3066 | */ |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3067 | public void setRestrictionsProvider(ComponentName admin, ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3068 | if (mService != null) { |
| 3069 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 3070 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 3071 | } catch (RemoteException re) { |
| 3072 | Log.w(TAG, "Failed to set permission provider on device policy service"); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 3076 | |
| 3077 | /** |
| 3078 | * Called by profile or device owners to set the master volume mute on or off. |
| 3079 | * |
| 3080 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3081 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 3082 | */ |
| 3083 | public void setMasterVolumeMuted(ComponentName admin, boolean on) { |
| 3084 | if (mService != null) { |
| 3085 | try { |
| 3086 | mService.setMasterVolumeMuted(admin, on); |
| 3087 | } catch (RemoteException re) { |
| 3088 | Log.w(TAG, "Failed to setMasterMute on device policy service"); |
| 3089 | } |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | /** |
| 3094 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 3095 | * |
| 3096 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3097 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 3098 | */ |
| 3099 | public boolean isMasterVolumeMuted(ComponentName admin) { |
| 3100 | if (mService != null) { |
| 3101 | try { |
| 3102 | return mService.isMasterVolumeMuted(admin); |
| 3103 | } catch (RemoteException re) { |
| 3104 | Log.w(TAG, "Failed to get isMasterMute on device policy service"); |
| 3105 | } |
| 3106 | } |
| 3107 | return false; |
| 3108 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 3109 | |
| 3110 | /** |
| 3111 | * Called by profile or device owners to change whether a user can uninstall |
| 3112 | * a package. |
| 3113 | * |
| 3114 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3115 | * @param packageName package to change. |
| 3116 | * @param blockUninstall true if the user shouldn't be able to uninstall the package. |
| 3117 | */ |
| 3118 | public void setBlockUninstall(ComponentName admin, String packageName, boolean blockUninstall) { |
| 3119 | if (mService != null) { |
| 3120 | try { |
| 3121 | mService.setBlockUninstall(admin, packageName, blockUninstall); |
| 3122 | } catch (RemoteException re) { |
| 3123 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3124 | } |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * Called by profile or device owners to check whether a user has been blocked from |
| 3130 | * uninstalling a package. |
| 3131 | * |
| 3132 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3133 | * @param packageName package to check. |
| 3134 | * @return true if the user shouldn't be able to uninstall the package. |
| 3135 | */ |
| 3136 | public boolean getBlockUninstall(ComponentName admin, String packageName) { |
| 3137 | if (mService != null) { |
| 3138 | try { |
| 3139 | return mService.getBlockUninstall(admin, packageName); |
| 3140 | } catch (RemoteException re) { |
| 3141 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 3142 | } |
| 3143 | } |
| 3144 | return false; |
| 3145 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 3146 | |
| 3147 | /** |
| 3148 | * Called by the profile owner to enable widget providers from a given package |
| 3149 | * to be available in the parent profile. As a result the user will be able to |
| 3150 | * add widgets from the white-listed package running under the profile to a widget |
| 3151 | * host which runs under the device owner, for example the home screen. Note that |
| 3152 | * a package may have zero or more provider components, where each component |
| 3153 | * provides a different widget type. |
| 3154 | * <p> |
| 3155 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3156 | * </p> |
| 3157 | * |
| 3158 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3159 | * @param packageName The package from which widget providers are white-listed. |
| 3160 | * @return Whether the package was added. |
| 3161 | * |
| 3162 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3163 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3164 | */ |
| 3165 | public boolean addCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3166 | if (mService != null) { |
| 3167 | try { |
| 3168 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 3169 | } catch (RemoteException re) { |
| 3170 | Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re); |
| 3171 | } |
| 3172 | } |
| 3173 | return false; |
| 3174 | } |
| 3175 | |
| 3176 | /** |
| 3177 | * Called by the profile owner to disable widget providers from a given package |
| 3178 | * to be available in the parent profile. For this method to take effect the |
| 3179 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 3180 | * android.content.ComponentName, String)}. |
| 3181 | * <p> |
| 3182 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
| 3183 | * </p> |
| 3184 | * |
| 3185 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3186 | * @param packageName The package from which widget providers are no longer |
| 3187 | * white-listed. |
| 3188 | * @return Whether the package was removed. |
| 3189 | * |
| 3190 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3191 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 3192 | */ |
| 3193 | public boolean removeCrossProfileWidgetProvider(ComponentName admin, String packageName) { |
| 3194 | if (mService != null) { |
| 3195 | try { |
| 3196 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 3197 | } catch (RemoteException re) { |
| 3198 | Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re); |
| 3199 | } |
| 3200 | } |
| 3201 | return false; |
| 3202 | } |
| 3203 | |
| 3204 | /** |
| 3205 | * Called by the profile owner to query providers from which packages are |
| 3206 | * available in the parent profile. |
| 3207 | * |
| 3208 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3209 | * @return The white-listed package list. |
| 3210 | * |
| 3211 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3212 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 3213 | */ |
| 3214 | public List<String> getCrossProfileWidgetProviders(ComponentName admin) { |
| 3215 | if (mService != null) { |
| 3216 | try { |
| 3217 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 3218 | if (providers != null) { |
| 3219 | return providers; |
| 3220 | } |
| 3221 | } catch (RemoteException re) { |
| 3222 | Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re); |
| 3223 | } |
| 3224 | } |
| 3225 | return Collections.emptyList(); |
| 3226 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 3227 | } |