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