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