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