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