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