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 | |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
Justin Morey | b5deda7 | 2014-07-24 10:53:40 -0500 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 24 | import android.app.Activity; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 25 | import android.content.ComponentName; |
| 26 | import android.content.Context; |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 27 | import android.content.Intent; |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 28 | import android.content.IntentFilter; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 29 | import android.content.pm.ActivityInfo; |
| 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.ResolveInfo; |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 33 | import android.net.ProxyInfo; |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 34 | import android.os.Bundle; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 35 | import android.os.Handler; |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 36 | import android.os.PersistableBundle; |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 37 | import android.os.Process; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 38 | import android.os.RemoteCallback; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.os.RemoteException; |
| 40 | import android.os.ServiceManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 42 | import android.os.UserManager; |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 43 | import android.provider.Settings; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 44 | import android.security.Credentials; |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 45 | import android.service.restrictions.RestrictionsReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | import android.util.Log; |
| 47 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 48 | import com.android.org.conscrypt.TrustedCertificateStore; |
| 49 | |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 50 | import org.xmlpull.v1.XmlPullParserException; |
| 51 | |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 52 | import java.io.ByteArrayInputStream; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 53 | import java.io.IOException; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 54 | import java.net.InetSocketAddress; |
| 55 | import java.net.Proxy; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 56 | import java.security.KeyFactory; |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 57 | import java.security.PrivateKey; |
| 58 | import java.security.cert.Certificate; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 59 | import java.security.cert.CertificateException; |
| 60 | import java.security.cert.CertificateFactory; |
| 61 | import java.security.cert.X509Certificate; |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 62 | import java.security.spec.PKCS8EncodedKeySpec; |
| 63 | import java.security.spec.InvalidKeySpecException; |
| 64 | import java.security.NoSuchAlgorithmException; |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 66 | import java.util.Collections; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 67 | import java.util.List; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 70 | * Public interface for managing policies enforced on a device. Most clients of this class must be |
| 71 | * registered with the system as a |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 72 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally, |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 73 | * a device administrator may be registered as either a profile or device owner. A given method is |
| 74 | * accessible to all device administrators unless the documentation for that method specifies that |
| 75 | * it is restricted to either device or profile owners. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 76 | * |
| 77 | * <div class="special reference"> |
| 78 | * <h3>Developer Guides</h3> |
Alexandra Gherghina | 541afcd | 2014-11-07 11:18:12 +0000 | [diff] [blame] | 79 | * <p>For more information about managing policies for device administration, read the |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 80 | * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 81 | * developer guide. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 82 | * </div> |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | */ |
| 84 | public class DevicePolicyManager { |
| 85 | private static String TAG = "DevicePolicyManager"; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 86 | |
| 87 | private final Context mContext; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 88 | private final IDevicePolicyManager mService; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 89 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 90 | private DevicePolicyManager(Context context, Handler handler) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 91 | mContext = context; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 92 | mService = IDevicePolicyManager.Stub.asInterface( |
| 93 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 94 | } |
| 95 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 96 | /** @hide */ |
| 97 | public static DevicePolicyManager create(Context context, Handler handler) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 98 | DevicePolicyManager me = new DevicePolicyManager(context, handler); |
| 99 | return me.mService != null ? me : null; |
| 100 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 101 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 102 | /** |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 103 | * Activity action: Starts the provisioning flow which sets up a managed profile. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 104 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 105 | * <p>A managed profile allows data separation for example for the usage of a |
| 106 | * device as a personal and corporate device. The user which provisioning is started from and |
| 107 | * the managed profile share a launcher. |
| 108 | * |
Andrew Solovay | 27f5337 | 2015-03-02 16:37:59 -0800 | [diff] [blame] | 109 | * <p>This intent will typically be sent by a mobile device management application (MDM). |
| 110 | * Provisioning adds a managed profile and sets the MDM as the profile owner who has full |
| 111 | * control over the profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 112 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 113 | * In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the |
| 114 | * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. |
| 115 | * As of {@link android.os.Build.VERSION_CODES#MNC}, it should contain the extra |
| 116 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only |
| 117 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 118 | * |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 119 | * <p> When managed provisioning has completed, broadcasts are sent to the application specified |
| 120 | * in the provisioning intent. The |
| 121 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the |
| 122 | * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in |
| 123 | * the primary profile. |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 124 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 125 | * <p> If provisioning fails, the managedProfile is removed so the device returns to its |
| 126 | * previous state. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 127 | */ |
| 128 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 129 | public static final String ACTION_PROVISION_MANAGED_PROFILE |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 130 | = "android.app.action.PROVISION_MANAGED_PROFILE"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 131 | |
| 132 | /** |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 133 | * Activity action: Starts the provisioning flow which sets up a managed device. |
| 134 | * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}. |
| 135 | * |
| 136 | * <p> During device owner provisioning a device admin app is set as the owner of the device. |
| 137 | * A device owner has full control over the device. The device owner can not be modified by the |
| 138 | * user. |
| 139 | * |
| 140 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 141 | * employee or client. |
| 142 | * |
| 143 | * <p> An intent with this action can be sent only on an unprovisioned device. |
| 144 | * It is possible to check if the device is provisioned or not by looking at |
| 145 | * {@link android.provider.Settings.Global#DEVICE_PROVISIONED} |
| 146 | * |
| 147 | * The intent contains the following extras: |
| 148 | * <ul> |
| 149 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> |
| 150 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 151 | * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li> |
| 152 | * </ul> |
| 153 | * |
| 154 | * <p> When device owner provisioning has completed, an intent of the type |
| 155 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the |
| 156 | * device owner. |
| 157 | * |
| 158 | * <p> If provisioning fails, the device is factory reset. |
| 159 | * |
| 160 | */ |
| 161 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 162 | public static final String ACTION_PROVISION_MANAGED_DEVICE |
| 163 | = "android.app.action.PROVISION_MANAGED_DEVICE"; |
| 164 | |
| 165 | /** |
Brian Carlstrom | f1fe51b | 2014-09-03 08:55:05 -0700 | [diff] [blame] | 166 | * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that allows |
| 167 | * a mobile device management application that starts managed profile provisioning to pass data |
| 168 | * to itself on the managed profile when provisioning completes. The mobile device management |
| 169 | * application sends this extra in an intent with the action |
| 170 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} and receives it in |
| 171 | * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action |
| 172 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed |
| 173 | * during the managed profile provisioning. |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 174 | */ |
| 175 | public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 176 | "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; |
Sander Alewijnse | 90f14bf | 2014-08-20 16:22:44 +0100 | [diff] [blame] | 177 | |
| 178 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 179 | * A String extra holding the package name of the mobile device management application that |
| 180 | * will be set as the profile owner or device owner. |
| 181 | * |
| 182 | * <p>If an application starts provisioning directly via an intent with action |
| 183 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the |
| 184 | * application that started provisioning. The package will be set as profile owner in that case. |
| 185 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 186 | * <p>This package is set as device owner when device owner provisioning is started by an NFC |
| 187 | * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 188 | * |
| 189 | * <p> When this extra is set, the application must have exactly one device admin receiver. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 190 | * This receiver will be set as the profile or device owner and active admin. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 191 | |
| 192 | * @see DeviceAdminReceiver |
| 193 | * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still |
| 194 | * supported. |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 195 | */ |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 196 | @Deprecated |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 197 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME |
Esteban Talavera | ef9c523 | 2014-09-08 13:51:18 +0100 | [diff] [blame] | 198 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME"; |
Jessica Hummel | f72078b | 2014-03-06 16:13:12 +0000 | [diff] [blame] | 199 | |
| 200 | /** |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 201 | * A ComponentName extra indicating the device admin receiver of the mobile device management |
| 202 | * application that will be set as the profile owner or device owner and active admin. |
| 203 | * |
| 204 | * <p>If an application starts provisioning directly via an intent with action |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 205 | * {@link #ACTION_PROVISION_MANAGED_PROFILE} or |
| 206 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this |
| 207 | * component has to match the package name of the application that started provisioning. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 208 | * |
| 209 | * <p>This component is set as device owner and active admin when device owner provisioning is |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 210 | * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC |
| 211 | * message containing an NFC record with MIME type |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 212 | * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. For the NFC record, the component name should be |
| 213 | * flattened to a string, via {@link ComponentName#flattenToShortString()}. |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 214 | * |
| 215 | * @see DeviceAdminReceiver |
| 216 | */ |
| 217 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME |
| 218 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; |
| 219 | |
| 220 | /** |
Alexandra Gherghina | aaf2f3e | 2014-11-13 12:46:15 +0000 | [diff] [blame] | 221 | * An {@link android.accounts.Account} extra holding the account to migrate during managed |
| 222 | * profile provisioning. If the account supplied is present in the primary user, it will be |
| 223 | * copied, along with its credentials to the managed profile and removed from the primary user. |
| 224 | * |
| 225 | * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
| 226 | */ |
| 227 | |
| 228 | public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE |
| 229 | = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; |
| 230 | |
| 231 | /** |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 232 | * A String extra that, holds the email address of the account which a managed profile is |
| 233 | * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and |
| 234 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 235 | * |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 236 | * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
| 237 | * |
Jessica Hummel | e3da790 | 2014-08-20 15:20:11 +0100 | [diff] [blame] | 238 | * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning |
| 239 | * contains this extra, it is forwarded in the |
| 240 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile |
| 241 | * device management application that was set as the profile owner during provisioning. |
| 242 | * 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] | 243 | */ |
Sander Alewijnse | 2b338a2 | 2014-09-12 12:28:40 +0100 | [diff] [blame] | 244 | public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS |
| 245 | = "android.app.extra.PROVISIONING_EMAIL_ADDRESS"; |
Nicolas Prevot | 07ac20b | 2014-05-27 15:37:45 +0100 | [diff] [blame] | 246 | |
| 247 | /** |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 248 | * A Boolean extra that can be used by the mobile device management application to skip the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 249 | * disabling of system apps during provisioning when set to {@code true}. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 250 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 251 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action |
| 252 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 253 | */ |
Sander Alewijnse | 5a14425 | 2014-11-18 13:25:04 +0000 | [diff] [blame] | 254 | public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = |
| 255 | "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED"; |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 256 | |
| 257 | /** |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 258 | * A String extra holding the time zone {@link android.app.AlarmManager} that the device |
| 259 | * will be set to. |
| 260 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 261 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 262 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 263 | */ |
| 264 | public static final String EXTRA_PROVISIONING_TIME_ZONE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 265 | = "android.app.extra.PROVISIONING_TIME_ZONE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 266 | |
| 267 | /** |
Esteban Talavera | d469a0b | 2014-08-20 13:54:25 +0100 | [diff] [blame] | 268 | * A Long extra holding the wall clock time (in milliseconds) to be set on the device's |
| 269 | * {@link android.app.AlarmManager}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 270 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 271 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 272 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 273 | */ |
| 274 | public static final String EXTRA_PROVISIONING_LOCAL_TIME |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 275 | = "android.app.extra.PROVISIONING_LOCAL_TIME"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * A String extra holding the {@link java.util.Locale} that the device will be set to. |
| 279 | * Format: xx_yy, where xx is the language code, and yy the country code. |
| 280 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 281 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 282 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 283 | */ |
| 284 | public static final String EXTRA_PROVISIONING_LOCALE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 285 | = "android.app.extra.PROVISIONING_LOCALE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * A String extra holding the ssid of the wifi network that should be used during nfc device |
| 289 | * owner provisioning for downloading the mobile device management application. |
| 290 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 291 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 292 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 293 | */ |
| 294 | public static final String EXTRA_PROVISIONING_WIFI_SSID |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 295 | = "android.app.extra.PROVISIONING_WIFI_SSID"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID} |
| 299 | * is hidden or not. |
| 300 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 301 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 302 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 303 | */ |
| 304 | public static final String EXTRA_PROVISIONING_WIFI_HIDDEN |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 305 | = "android.app.extra.PROVISIONING_WIFI_HIDDEN"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * A String extra indicating the security type of the wifi network in |
| 309 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 310 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 311 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 312 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 313 | */ |
| 314 | public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 315 | = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * A String extra holding the password of the wifi network in |
| 319 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 320 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 321 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 322 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 323 | */ |
| 324 | public static final String EXTRA_PROVISIONING_WIFI_PASSWORD |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 325 | = "android.app.extra.PROVISIONING_WIFI_PASSWORD"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 326 | |
| 327 | /** |
| 328 | * A String extra holding the proxy host for the wifi network in |
| 329 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 330 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 331 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 332 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 333 | */ |
| 334 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 335 | = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * An int extra holding the proxy port for the wifi network in |
| 339 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 340 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 341 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 342 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 343 | */ |
| 344 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 345 | = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * A String extra holding the proxy bypass for the wifi network in |
| 349 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 350 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 351 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 352 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 353 | */ |
| 354 | public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 355 | = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * A String extra holding the proxy auto-config (PAC) URL for the wifi network in |
| 359 | * {@link #EXTRA_PROVISIONING_WIFI_SSID}. |
| 360 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 361 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 362 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 363 | */ |
| 364 | public static final String EXTRA_PROVISIONING_WIFI_PAC_URL |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 365 | = "android.app.extra.PROVISIONING_WIFI_PAC_URL"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 366 | |
| 367 | /** |
| 368 | * A String extra holding a url that specifies the download location of the device admin |
| 369 | * package. When not provided it is assumed that the device admin package is already installed. |
| 370 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 371 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 372 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 373 | */ |
| 374 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 375 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 376 | |
| 377 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 378 | * An int extra holding a minimum required version code for the device admin package. If the |
| 379 | * device admin is already installed on the device, it will only be re-downloaded from |
| 380 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the |
| 381 | * installed package is less than this version code. |
| 382 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 383 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 384 | * provisioning via an NFC bump. |
| 385 | */ |
| 386 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE |
| 387 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; |
| 388 | |
| 389 | /** |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 390 | * A String extra holding a http cookie header which should be used in the http request to the |
| 391 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 392 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 393 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 394 | * provisioning via an NFC bump. |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 395 | */ |
| 396 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 397 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 398 | |
| 399 | /** |
Rubin Xu | e30ab11 | 2015-03-24 11:22:28 +0000 | [diff] [blame] | 400 | * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 401 | * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 402 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 403 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 404 | * present. The provided checksum should match the checksum of the file at the download |
| 405 | * location. If the checksum doesn't match an error will be shown to the user and the user will |
| 406 | * be asked to factory reset the device. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 407 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 408 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 409 | * provisioning via an NFC bump. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 410 | */ |
| 411 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM |
Esteban Talavera | 37f0184 | 2014-09-05 10:50:57 +0100 | [diff] [blame] | 412 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 413 | |
| 414 | /** |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 415 | * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any signature of the |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 416 | * android package archive at the download location specified in {@link |
| 417 | * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}. |
| 418 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 419 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 420 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 421 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 422 | * |
| 423 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 424 | * present. The provided checksum should match the checksum of any signature of the file at |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 425 | * the download location. If the checksum does not match an error will be shown to the user and |
| 426 | * the user will be asked to factory reset the device. |
| 427 | * |
| 428 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner |
| 429 | * provisioning via an NFC bump. |
| 430 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 431 | public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM |
| 432 | = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 433 | |
| 434 | /** |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 435 | * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile |
| 436 | * has completed successfully. |
| 437 | * |
| 438 | * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning |
Nicolas Prevot | ebe2d99 | 2015-05-12 18:14:53 -0700 | [diff] [blame] | 439 | * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}. |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 440 | * |
Ying Wang | 7f38aab | 2015-02-20 11:50:09 -0800 | [diff] [blame] | 441 | * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which |
Alexandra Gherghina | db4bc57 | 2015-01-08 12:17:40 +0000 | [diff] [blame] | 442 | * corresponds to the account requested to be migrated at provisioning time, if any. |
| 443 | */ |
| 444 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 445 | public static final String ACTION_MANAGED_PROFILE_PROVISIONED |
| 446 | = "android.app.action.MANAGED_PROFILE_PROVISIONED"; |
| 447 | |
| 448 | /** |
Julia Reynolds | 2f46d94 | 2015-05-05 11:44:20 -0400 | [diff] [blame] | 449 | * A boolean extra indicating whether device encryption can be skipped as part of Device Owner |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 450 | * provisioning. |
| 451 | * |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 452 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} or an intent with action |
| 453 | * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning. |
Julia Reynolds | a9ec70b | 2015-02-02 09:54:26 -0500 | [diff] [blame] | 454 | */ |
| 455 | public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION = |
| 456 | "android.app.extra.PROVISIONING_SKIP_ENCRYPTION"; |
| 457 | |
| 458 | /** |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 459 | * On devices managed by a device owner app, a {@link ComponentName} extra indicating the |
| 460 | * component of the application that is temporarily granted device owner privileges during |
| 461 | * device initialization and profile owner privileges during secondary user initialization. |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 462 | * |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 463 | * <p> |
Rubin Xu | 6a38e43 | 2015-03-26 14:47:45 +0000 | [diff] [blame] | 464 | * It can also be used in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts |
Rubin Xu | 44ef750b | 2015-03-23 16:51:33 +0000 | [diff] [blame] | 465 | * device owner provisioning via an NFC bump. For the NFC record, it should be flattened to a |
| 466 | * string first. |
| 467 | * |
| 468 | * @see ComponentName#flattenToShortString() |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 469 | */ |
| 470 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME |
| 471 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME"; |
| 472 | |
| 473 | /** |
| 474 | * A String extra holding an http url that specifies the download location of the device |
| 475 | * initializer package. When not provided it is assumed that the device initializer package is |
| 476 | * already installed. |
| 477 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 478 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 479 | * provisioning via an NFC bump. |
| 480 | */ |
| 481 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION |
| 482 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION"; |
| 483 | |
| 484 | /** |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 485 | * An int extra holding a minimum required version code for the device initializer package. |
| 486 | * If the initializer is already installed on the device, it will only be re-downloaded from |
| 487 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION} if the version of |
| 488 | * the installed package is less than this version code. |
| 489 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 490 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
Julia Reynolds | c173174 | 2015-03-19 14:56:28 -0400 | [diff] [blame] | 491 | * provisioning via an NFC bump. |
| 492 | */ |
| 493 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE |
| 494 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE"; |
| 495 | |
| 496 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 497 | * A String extra holding a http cookie header which should be used in the http request to the |
| 498 | * url specified in {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. |
| 499 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 500 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 501 | * provisioning via an NFC bump. |
| 502 | */ |
| 503 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER |
| 504 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER"; |
| 505 | |
| 506 | /** |
Rubin Xu | e30ab11 | 2015-03-24 11:22:28 +0000 | [diff] [blame] | 507 | * A String extra holding the URL-safe base64 encoded SHA-1 checksum of the file at download |
| 508 | * location specified in |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 509 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. |
| 510 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 511 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM} |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 512 | * should be present. The provided checksum should match the checksum of the file at the |
| 513 | * download location. If the checksum doesn't match an error will be shown to the user and the |
| 514 | * user will be asked to factory reset the device. |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 515 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 516 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 517 | * provisioning via an NFC bump. |
| 518 | */ |
| 519 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM |
| 520 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM"; |
| 521 | |
| 522 | /** |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 523 | * A String extra holding the URL-safe base64 encoded SHA-1 checksum of any signature of the |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 524 | * android package archive at the download location specified in {@link |
| 525 | * #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}. |
| 526 | * |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 527 | * <p>The signatures of an android package archive can be obtained using |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 528 | * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag |
| 529 | * {@link android.content.pm.PackageManager#GET_SIGNATURES}. |
| 530 | * |
| 531 | * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM} |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 532 | * should be present. The provided checksum should match the checksum of any signature of the |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 533 | * file at the download location. If the checksum doesn't match an error will be shown to the |
| 534 | * user and the user will be asked to factory reset the device. |
| 535 | * |
| 536 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
| 537 | * provisioning via an NFC bump. |
| 538 | */ |
Rubin Xu | 5c82d2c | 2015-06-02 09:29:46 +0100 | [diff] [blame^] | 539 | public static final String EXTRA_PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM |
| 540 | = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_SIGNATURE_CHECKSUM"; |
Sander Alewijnse | e4f878cb | 2015-04-14 10:49:17 +0100 | [diff] [blame] | 541 | |
| 542 | /** |
Craig Lafayette | 8e27c4d | 2015-03-19 08:36:38 -0400 | [diff] [blame] | 543 | * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that |
| 544 | * holds data needed by the system to wipe factory reset protection. The data needed to wipe |
| 545 | * the device depend on the installed factory reset protection implementation. For example, |
| 546 | * if an account is needed to unlock a device, this extra may contain data used to |
| 547 | * authenticate that account. |
| 548 | * |
| 549 | * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner |
| 550 | * provisioning via an NFC bump. |
| 551 | */ |
| 552 | public static final String EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS |
| 553 | = "android.app.extra.PROVISIONING_RESET_PROTECTION_PARAMETERS"; |
| 554 | |
Craig Lafayette | 97e473e | 2015-03-19 10:19:38 -0400 | [diff] [blame] | 555 | /** |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 556 | * This MIME type is used for starting the Device Owner provisioning that does not require |
| 557 | * provisioning features introduced in Android API level |
| 558 | * {@link android.os.Build.VERSION_CODES#MNC} or later levels. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 559 | * |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 560 | * <p>For more information about the provisioning process see |
| 561 | * {@link #MIME_TYPE_PROVISIONING_NFC_V2}. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 562 | * |
Sander Alewijnse | 8c41156 | 2014-11-12 18:03:11 +0000 | [diff] [blame] | 563 | * <p>The NFC record must contain a serialized {@link java.util.Properties} object which |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 564 | * contains the following properties: |
| 565 | * <ul> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 566 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li> |
| 567 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
Sander Alewijnse | 681bce9 | 2014-07-24 16:46:26 +0100 | [diff] [blame] | 568 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 569 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 570 | * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li> |
| 571 | * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li> |
| 572 | * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li> |
| 573 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li> |
| 574 | * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li> |
| 575 | * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li> |
| 576 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li> |
| 577 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li> |
| 578 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li> |
| 579 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 580 | * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li></ul> |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 581 | * |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 582 | * <p> |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 583 | * As of {@link android.os.Build.VERSION_CODES#MNC}, the properties should contain |
| 584 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of |
| 585 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only |
| 586 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported). |
| 587 | * |
| 588 | * @see #MIME_TYPE_PROVISIONING_NFC_V2 |
| 589 | * |
| 590 | */ |
| 591 | public static final String MIME_TYPE_PROVISIONING_NFC |
| 592 | = "application/com.android.managedprovisioning"; |
| 593 | |
| 594 | |
| 595 | /** |
| 596 | * This MIME type is used for starting the Device Owner provisioning that requires |
| 597 | * new provisioning features introduced in API version |
| 598 | * {@link android.os.Build.VERSION_CODES#MNC} in addition to those supported in earlier |
| 599 | * versions. |
| 600 | * |
| 601 | * <p>During device owner provisioning a device admin app is set as the owner of the device. |
| 602 | * A device owner has full control over the device. The device owner can not be modified by the |
Nicolas Prevot | 64bf7b2 | 2015-04-29 14:43:49 +0100 | [diff] [blame] | 603 | * user. |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 604 | * |
| 605 | * <p> A typical use case would be a device that is owned by a company, but used by either an |
| 606 | * employee or client. |
| 607 | * |
| 608 | * <p> The NFC message should be sent to an unprovisioned device. |
| 609 | * |
| 610 | * <p>The NFC record must contain a serialized {@link java.util.Properties} object which |
| 611 | * contains the following properties in addition to properties listed at |
| 612 | * {@link #MIME_TYPE_PROVISIONING_NFC}: |
| 613 | * <ul> |
| 614 | * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li> |
| 615 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}, optional</li> |
| 616 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, optional</li> |
| 617 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li> |
| 618 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}, optional</li> |
| 619 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, optional</li> |
| 620 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. |
| 621 | * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property |
| 622 | * should be converted to a String via |
| 623 | * {@link android.content.ComponentName#flattenToString()}</li> |
Craig Lafayette | 240e648 | 2015-06-02 11:12:43 -0400 | [diff] [blame] | 624 | * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul> |
Nicolas Prevot | 1844025 | 2015-03-09 14:07:17 +0000 | [diff] [blame] | 625 | * |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 626 | * <p> When device owner provisioning has completed, an intent of the type |
| 627 | * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the |
| 628 | * device owner. |
| 629 | * |
| 630 | * <p> |
| 631 | * If provisioning fails, the device is factory reset. |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 632 | */ |
Andrei Kapishnikov | 35e71f5 | 2015-03-16 17:24:04 -0400 | [diff] [blame] | 633 | public static final String MIME_TYPE_PROVISIONING_NFC_V2 |
| 634 | = "application/com.android.managedprovisioning.v2"; |
Sander Alewijnse | 1cc4ecc | 2014-06-23 19:56:52 +0100 | [diff] [blame] | 635 | |
| 636 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 637 | * Activity action: ask the user to add a new device administrator to the system. |
| 638 | * The desired policy is the ComponentName of the policy in the |
| 639 | * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to |
| 640 | * bring the user through adding the device administrator to the system (or |
| 641 | * allowing them to reject it). |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 642 | * |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 643 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 644 | * field to provide the user with additional explanation (in addition |
| 645 | * to your component's description) about what is being added. |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 646 | * |
| 647 | * <p>If your administrator is already active, this will ordinarily return immediately (without |
| 648 | * user intervention). However, if your administrator has been updated and is requesting |
| 649 | * additional uses-policy flags, the user will be presented with the new list. New policies |
| 650 | * 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] | 651 | */ |
| 652 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 653 | public static final String ACTION_ADD_DEVICE_ADMIN |
| 654 | = "android.app.action.ADD_DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 655 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 656 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 657 | * @hide |
| 658 | * Activity action: ask the user to add a new device administrator as the profile owner |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 659 | * for this user. Only system apps can launch this intent. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 660 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 661 | * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN} |
| 662 | * extra field. This will invoke a UI to bring the user through adding the profile owner admin |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 663 | * to remotely control restrictions on the user. |
| 664 | * |
| 665 | * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the |
| 666 | * result of whether or not the user approved the action. If approved, the result will |
| 667 | * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well |
| 668 | * as a profile owner. |
| 669 | * |
| 670 | * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION} |
| 671 | * field to provide the user with additional explanation (in addition |
| 672 | * to your component's description) about what is being added. |
| 673 | * |
Amith Yamasani | 814e987 | 2015-03-23 14:04:53 -0700 | [diff] [blame] | 674 | * <p>If there is already a profile owner active or the caller is not a system app, the |
| 675 | * operation will return a failure result. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 676 | */ |
| 677 | @SystemApi |
| 678 | public static final String ACTION_SET_PROFILE_OWNER |
| 679 | = "android.app.action.SET_PROFILE_OWNER"; |
| 680 | |
| 681 | /** |
| 682 | * @hide |
| 683 | * Name of the profile owner admin that controls the user. |
| 684 | */ |
| 685 | @SystemApi |
| 686 | public static final String EXTRA_PROFILE_OWNER_NAME |
| 687 | = "android.app.extra.PROFILE_OWNER_NAME"; |
| 688 | |
| 689 | /** |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 690 | * Activity action: send when any policy admin changes a policy. |
| 691 | * 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] | 692 | * |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 693 | * @hide |
| 694 | */ |
| 695 | public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED |
| 696 | = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED"; |
| 697 | |
| 698 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 699 | * The ComponentName of the administrator component. |
| 700 | * |
| 701 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 702 | */ |
| 703 | public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 704 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 705 | /** |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 706 | * An optional CharSequence providing additional explanation for why the |
| 707 | * admin is being added. |
| 708 | * |
| 709 | * @see #ACTION_ADD_DEVICE_ADMIN |
| 710 | */ |
| 711 | public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 712 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 713 | /** |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 714 | * Activity action: have the user enter a new password. This activity should |
| 715 | * be launched after using {@link #setPasswordQuality(ComponentName, int)}, |
| 716 | * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user |
| 717 | * enter a new password that meets the current requirements. You can use |
| 718 | * {@link #isActivePasswordSufficient()} to determine whether you need to |
| 719 | * have the user select a new password in order to meet the current |
| 720 | * constraints. Upon being resumed from this activity, you can check the new |
| 721 | * password characteristics to see if they are sufficient. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 722 | */ |
| 723 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 724 | public static final String ACTION_SET_NEW_PASSWORD |
| 725 | = "android.app.action.SET_NEW_PASSWORD"; |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 726 | |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 727 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 728 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 729 | * the parent profile to access intents sent from the managed profile. |
| 730 | * That is, when an app in the managed profile calls |
| 731 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 732 | * matching activity in the parent profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 733 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 734 | public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001; |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 735 | |
| 736 | /** |
Nicolas Prevot | 2c1c5dd | 2015-01-12 12:32:56 +0000 | [diff] [blame] | 737 | * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in |
| 738 | * the managed profile to access intents sent from the parent profile. |
| 739 | * That is, when an app in the parent profile calls |
| 740 | * {@link Activity#startActivity(Intent)}, the intent can be resolved by a |
| 741 | * matching activity in the managed profile. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 742 | */ |
Nicolas Prevot | 86a9673 | 2014-09-08 12:13:05 +0100 | [diff] [blame] | 743 | public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 744 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 745 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 746 | * Broadcast action: notify that a new local system update policy has been set by the device |
| 747 | * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 748 | */ |
| 749 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 750 | public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED |
| 751 | = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED"; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 752 | |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 753 | /** |
| 754 | * Permission policy to prompt user for new permission requests for runtime permissions. |
| 755 | * Already granted or denied permissions are not affected by this. |
| 756 | */ |
| 757 | public static final int PERMISSION_POLICY_PROMPT = 0; |
| 758 | |
| 759 | /** |
| 760 | * Permission policy to always grant new permission requests for runtime permissions. |
| 761 | * Already granted or denied permissions are not affected by this. |
| 762 | */ |
| 763 | public static final int PERMISSION_POLICY_AUTO_GRANT = 1; |
| 764 | |
| 765 | /** |
| 766 | * Permission policy to always deny new permission requests for runtime permissions. |
| 767 | * Already granted or denied permissions are not affected by this. |
| 768 | */ |
| 769 | public static final int PERMISSION_POLICY_AUTO_DENY = 2; |
| 770 | |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 771 | /** |
| 772 | * Runtime permission state: The user can manage the permission |
| 773 | * through the UI. |
| 774 | */ |
| 775 | public static final int PERMISSION_GRANT_STATE_DEFAULT = 0; |
| 776 | |
| 777 | /** |
| 778 | * Runtime permission state: The permission is granted to the app |
| 779 | * and the user cannot manage the permission through the UI. |
| 780 | */ |
| 781 | public static final int PERMISSION_GRANT_STATE_GRANTED = 1; |
| 782 | |
| 783 | /** |
| 784 | * Runtime permission state: The permission is denied to the app |
| 785 | * and the user cannot manage the permission through the UI. |
| 786 | */ |
| 787 | public static final int PERMISSION_GRANT_STATE_DENIED = 2; |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 788 | |
| 789 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 790 | * Return true if the given administrator component is currently |
| 791 | * active (enabled) in the system. |
| 792 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 793 | public boolean isAdminActive(@NonNull ComponentName admin) { |
| 794 | return isAdminActiveAsUser(admin, UserHandle.myUserId()); |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /** |
| 798 | * @see #isAdminActive(ComponentName) |
| 799 | * @hide |
| 800 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 801 | public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 802 | if (mService != null) { |
| 803 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 804 | return mService.isAdminActive(admin, userId); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 805 | } catch (RemoteException e) { |
| 806 | Log.w(TAG, "Failed talking with device policy service", e); |
| 807 | } |
| 808 | } |
| 809 | return false; |
| 810 | } |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 811 | /** |
| 812 | * Return true if the given administrator component is currently being removed |
| 813 | * for the user. |
| 814 | * @hide |
| 815 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 816 | public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) { |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 817 | if (mService != null) { |
| 818 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 819 | return mService.isRemovingAdmin(admin, userId); |
Fyodor Kupolov | 96fb932 | 2014-12-01 15:08:09 -0800 | [diff] [blame] | 820 | } catch (RemoteException e) { |
| 821 | Log.w(TAG, "Failed talking with device policy service", e); |
| 822 | } |
| 823 | } |
| 824 | return false; |
| 825 | } |
| 826 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 827 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 828 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 829 | * Return a list of all currently active device administrators' component |
| 830 | * names. If there are no administrators {@code null} may be |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 831 | * returned. |
| 832 | */ |
| 833 | public List<ComponentName> getActiveAdmins() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 834 | return getActiveAdminsAsUser(UserHandle.myUserId()); |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * @see #getActiveAdmins() |
| 839 | * @hide |
| 840 | */ |
| 841 | public List<ComponentName> getActiveAdminsAsUser(int userId) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 842 | if (mService != null) { |
| 843 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 844 | return mService.getActiveAdmins(userId); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 845 | } catch (RemoteException e) { |
| 846 | Log.w(TAG, "Failed talking with device policy service", e); |
| 847 | } |
| 848 | } |
| 849 | return null; |
| 850 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 851 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 852 | /** |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 853 | * Used by package administration code to determine if a package can be stopped |
| 854 | * or uninstalled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 855 | * @hide |
| 856 | */ |
| 857 | public boolean packageHasActiveAdmins(String packageName) { |
| 858 | if (mService != null) { |
| 859 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 860 | return mService.packageHasActiveAdmins(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 861 | } catch (RemoteException e) { |
| 862 | Log.w(TAG, "Failed talking with device policy service", e); |
| 863 | } |
| 864 | } |
| 865 | return false; |
| 866 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 867 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 868 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 869 | * Remove a current administration component. This can only be called |
| 870 | * by the application that owns the administration component; if you |
| 871 | * try to remove someone else's component, a security exception will be |
| 872 | * thrown. |
| 873 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 874 | public void removeActiveAdmin(@NonNull ComponentName admin) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 875 | if (mService != null) { |
| 876 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 877 | mService.removeActiveAdmin(admin, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 878 | } catch (RemoteException e) { |
| 879 | Log.w(TAG, "Failed talking with device policy service", e); |
| 880 | } |
| 881 | } |
| 882 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 883 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 884 | /** |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 885 | * Returns true if an administrator has been granted a particular device policy. This can |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 886 | * be used to check whether the administrator was activated under an earlier set of policies, |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 887 | * but requires additional policies after an upgrade. |
| 888 | * |
| 889 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be |
| 890 | * an active administrator, or an exception will be thrown. |
| 891 | * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}. |
| 892 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 893 | public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) { |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 894 | if (mService != null) { |
| 895 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 896 | return mService.hasGrantedPolicy(admin, usesPolicy, UserHandle.myUserId()); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 897 | } catch (RemoteException e) { |
| 898 | Log.w(TAG, "Failed talking with device policy service", e); |
| 899 | } |
| 900 | } |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 905 | * Constant for {@link #setPasswordQuality}: the policy has no requirements |
| 906 | * for the password. Note that quality constants are ordered so that higher |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 907 | * values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 908 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 909 | public static final int PASSWORD_QUALITY_UNSPECIFIED = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 910 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 911 | /** |
Jim Miller | 3e5d3fd | 2011-09-02 17:30:35 -0700 | [diff] [blame] | 912 | * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric |
| 913 | * recognition technology. This implies technologies that can recognize the identity of |
| 914 | * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000). |
| 915 | * Note that quality constants are ordered so that higher values are more restrictive. |
| 916 | */ |
| 917 | public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000; |
| 918 | |
| 919 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 920 | * Constant for {@link #setPasswordQuality}: the policy requires some kind |
| 921 | * 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] | 922 | * are ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 923 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 924 | public static final int PASSWORD_QUALITY_SOMETHING = 0x10000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 925 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 926 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 927 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
| 928 | * password containing at least numeric characters. Note that quality |
| 929 | * constants are ordered so that higher values are more restrictive. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 930 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 931 | public static final int PASSWORD_QUALITY_NUMERIC = 0x20000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 932 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 933 | /** |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 934 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 935 | * password containing at least numeric characters with no repeating (4444) |
| 936 | * or ordered (1234, 4321, 2468) sequences. Note that quality |
| 937 | * constants are ordered so that higher values are more restrictive. |
| 938 | */ |
| 939 | public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000; |
| 940 | |
| 941 | /** |
| 942 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 943 | * password containing at least alphabetic (or other symbol) characters. |
| 944 | * Note that quality constants are ordered so that higher values are more |
| 945 | * restrictive. |
| 946 | */ |
| 947 | public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 948 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 949 | /** |
| 950 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 951 | * password containing at least <em>both></em> numeric <em>and</em> |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 952 | * alphabetic (or other symbol) characters. Note that quality constants are |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 953 | * ordered so that higher values are more restrictive. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 954 | */ |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 955 | public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 956 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 957 | /** |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 958 | * Constant for {@link #setPasswordQuality}: the user must have entered a |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 959 | * password containing at least a letter, a numerical digit and a special |
| 960 | * symbol, by default. With this password quality, passwords can be |
| 961 | * restricted to contain various sets of characters, like at least an |
| 962 | * uppercase letter, etc. These are specified using various methods, |
| 963 | * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note |
| 964 | * that quality constants are ordered so that higher values are more |
| 965 | * restrictive. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 966 | */ |
| 967 | public static final int PASSWORD_QUALITY_COMPLEX = 0x60000; |
| 968 | |
| 969 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 970 | * Called by an application that is administering the device to set the |
| 971 | * password restrictions it is imposing. After setting this, the user |
| 972 | * will not be able to enter a new password that is not at least as |
| 973 | * restrictive as what has been set. Note that the current password |
| 974 | * will remain until the user has set a new one, so the change does not |
| 975 | * take place immediately. To prompt the user for a new password, use |
| 976 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 977 | * |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 978 | * <p>Quality constants are ordered so that higher values are more restrictive; |
| 979 | * thus the highest requested quality constant (between the policy set here, |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 980 | * the user's preference, and any other considerations) is the one that |
| 981 | * is in effect. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 982 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 983 | * <p>The calling device admin must have requested |
| 984 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 985 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 986 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 987 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 988 | * @param quality The new desired quality. One of |
| 989 | * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING}, |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 990 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 991 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 992 | * or {@link #PASSWORD_QUALITY_COMPLEX}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 993 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 994 | public void setPasswordQuality(@NonNull ComponentName admin, int quality) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 995 | if (mService != null) { |
| 996 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 997 | mService.setPasswordQuality(admin, quality); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 998 | } catch (RemoteException e) { |
| 999 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1003 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1004 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1005 | * Retrieve the current minimum password quality for all admins of this user |
| 1006 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1007 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1008 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1009 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1010 | public int getPasswordQuality(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1011 | return getPasswordQuality(admin, UserHandle.myUserId()); |
| 1012 | } |
| 1013 | |
| 1014 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1015 | public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1016 | if (mService != null) { |
| 1017 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1018 | return mService.getPasswordQuality(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1019 | } catch (RemoteException e) { |
| 1020 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1021 | } |
| 1022 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1023 | return PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1024 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1025 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1026 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1027 | * Called by an application that is administering the device to set the |
| 1028 | * minimum allowed password length. After setting this, the user |
| 1029 | * will not be able to enter a new password that is not at least as |
| 1030 | * restrictive as what has been set. Note that the current password |
| 1031 | * will remain until the user has set a new one, so the change does not |
| 1032 | * take place immediately. To prompt the user for a new password, use |
| 1033 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1034 | * constraint is only imposed if the administrator has also requested either |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1035 | * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, |
| 1036 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}, |
| 1037 | * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1038 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1039 | * <p>The calling device admin must have requested |
| 1040 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1041 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1042 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1043 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1044 | * @param length The new desired minimum password length. A value of 0 |
| 1045 | * means there is no restriction. |
| 1046 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1047 | public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1048 | if (mService != null) { |
| 1049 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1050 | mService.setPasswordMinimumLength(admin, length); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1051 | } catch (RemoteException e) { |
| 1052 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1056 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1057 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1058 | * Retrieve the current minimum password length for all admins of this |
| 1059 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1060 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1061 | * all admins. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1062 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1063 | public int getPasswordMinimumLength(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1064 | return getPasswordMinimumLength(admin, UserHandle.myUserId()); |
| 1065 | } |
| 1066 | |
| 1067 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1068 | public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1069 | if (mService != null) { |
| 1070 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1071 | return mService.getPasswordMinimumLength(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1072 | } catch (RemoteException e) { |
| 1073 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1074 | } |
| 1075 | } |
| 1076 | return 0; |
| 1077 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1078 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1079 | /** |
| 1080 | * Called by an application that is administering the device to set the |
| 1081 | * minimum number of upper case letters required in the password. After |
| 1082 | * setting this, the user will not be able to enter a new password that is |
| 1083 | * not at least as restrictive as what has been set. Note that the current |
| 1084 | * password will remain until the user has set a new one, so the change does |
| 1085 | * not take place immediately. To prompt the user for a new password, use |
| 1086 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1087 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1088 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1089 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1090 | * <p> |
| 1091 | * The calling device admin must have requested |
| 1092 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1093 | * this method; if it has not, a security exception will be thrown. |
| 1094 | * |
| 1095 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1096 | * with. |
| 1097 | * @param length The new desired minimum number of upper case letters |
| 1098 | * required in the password. A value of 0 means there is no |
| 1099 | * restriction. |
| 1100 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1101 | public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1102 | if (mService != null) { |
| 1103 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1104 | mService.setPasswordMinimumUpperCase(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1105 | } catch (RemoteException e) { |
| 1106 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Retrieve the current number of upper case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1113 | * password for all admins of this user and its profiles or a particular one. |
| 1114 | * This is the same value as set by |
| 1115 | * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1116 | * and only applies when the password quality is |
| 1117 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1118 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1119 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1120 | * aggregate all admins. |
| 1121 | * @return The minimum number of upper case letters required in the |
| 1122 | * password. |
| 1123 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1124 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1125 | return getPasswordMinimumUpperCase(admin, UserHandle.myUserId()); |
| 1126 | } |
| 1127 | |
| 1128 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1129 | public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1130 | if (mService != null) { |
| 1131 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1132 | return mService.getPasswordMinimumUpperCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1133 | } catch (RemoteException e) { |
| 1134 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1135 | } |
| 1136 | } |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * Called by an application that is administering the device to set the |
| 1142 | * minimum number of lower case letters required in the password. After |
| 1143 | * setting this, the user will not be able to enter a new password that is |
| 1144 | * not at least as restrictive as what has been set. Note that the current |
| 1145 | * password will remain until the user has set a new one, so the change does |
| 1146 | * not take place immediately. To prompt the user for a new password, use |
| 1147 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1148 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1149 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1150 | * default value is 0. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1151 | * <p> |
| 1152 | * The calling device admin must have requested |
| 1153 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1154 | * this method; if it has not, a security exception will be thrown. |
| 1155 | * |
| 1156 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1157 | * with. |
| 1158 | * @param length The new desired minimum number of lower case letters |
| 1159 | * required in the password. A value of 0 means there is no |
| 1160 | * restriction. |
| 1161 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1162 | public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1163 | if (mService != null) { |
| 1164 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1165 | mService.setPasswordMinimumLowerCase(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1166 | } catch (RemoteException e) { |
| 1167 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * Retrieve the current number of lower case letters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1174 | * password for all admins of this user and its profiles or a particular one. |
| 1175 | * This is the same value as set by |
| 1176 | * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1177 | * and only applies when the password quality is |
| 1178 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1179 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1180 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1181 | * aggregate all admins. |
| 1182 | * @return The minimum number of lower case letters required in the |
| 1183 | * password. |
| 1184 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1185 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1186 | return getPasswordMinimumLowerCase(admin, UserHandle.myUserId()); |
| 1187 | } |
| 1188 | |
| 1189 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1190 | public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1191 | if (mService != null) { |
| 1192 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1193 | return mService.getPasswordMinimumLowerCase(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1194 | } catch (RemoteException e) { |
| 1195 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1196 | } |
| 1197 | } |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * Called by an application that is administering the device to set the |
| 1203 | * minimum number of letters required in the password. After setting this, |
| 1204 | * the user will not be able to enter a new password that is not at least as |
| 1205 | * restrictive as what has been set. Note that the current password will |
| 1206 | * remain until the user has set a new one, so the change does not take |
| 1207 | * place immediately. To prompt the user for a new password, use |
| 1208 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1209 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1210 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1211 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1212 | * <p> |
| 1213 | * The calling device admin must have requested |
| 1214 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1215 | * this method; if it has not, a security exception will be thrown. |
| 1216 | * |
| 1217 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1218 | * with. |
| 1219 | * @param length The new desired minimum number of letters required in the |
| 1220 | * password. A value of 0 means there is no restriction. |
| 1221 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1222 | public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1223 | if (mService != null) { |
| 1224 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1225 | mService.setPasswordMinimumLetters(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1226 | } catch (RemoteException e) { |
| 1227 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Retrieve the current number of letters required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1234 | * admins or a particular one. This is the same value as |
| 1235 | * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)} |
| 1236 | * and only applies when the password quality is |
| 1237 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1238 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1239 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1240 | * aggregate all admins. |
| 1241 | * @return The minimum number of letters required in the password. |
| 1242 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1243 | public int getPasswordMinimumLetters(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1244 | return getPasswordMinimumLetters(admin, UserHandle.myUserId()); |
| 1245 | } |
| 1246 | |
| 1247 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1248 | public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1249 | if (mService != null) { |
| 1250 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1251 | return mService.getPasswordMinimumLetters(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1252 | } catch (RemoteException e) { |
| 1253 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1254 | } |
| 1255 | } |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * Called by an application that is administering the device to set the |
| 1261 | * minimum number of numerical digits required in the password. After |
| 1262 | * setting this, the user will not be able to enter a new password that is |
| 1263 | * not at least as restrictive as what has been set. Note that the current |
| 1264 | * password will remain until the user has set a new one, so the change does |
| 1265 | * not take place immediately. To prompt the user for a new password, use |
| 1266 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1267 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1268 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1269 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1270 | * <p> |
| 1271 | * The calling device admin must have requested |
| 1272 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1273 | * this method; if it has not, a security exception will be thrown. |
| 1274 | * |
| 1275 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1276 | * with. |
| 1277 | * @param length The new desired minimum number of numerical digits required |
| 1278 | * in the password. A value of 0 means there is no restriction. |
| 1279 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1280 | public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1281 | if (mService != null) { |
| 1282 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1283 | mService.setPasswordMinimumNumeric(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1284 | } catch (RemoteException e) { |
| 1285 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * Retrieve the current number of numerical digits required in the password |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1292 | * for all admins of this user and its profiles or a particular one. |
| 1293 | * This is the same value as set by |
| 1294 | * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1295 | * and only applies when the password quality is |
| 1296 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1297 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1298 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1299 | * aggregate all admins. |
| 1300 | * @return The minimum number of numerical digits required in the password. |
| 1301 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1302 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1303 | return getPasswordMinimumNumeric(admin, UserHandle.myUserId()); |
| 1304 | } |
| 1305 | |
| 1306 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1307 | public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1308 | if (mService != null) { |
| 1309 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1310 | return mService.getPasswordMinimumNumeric(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1311 | } catch (RemoteException e) { |
| 1312 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1313 | } |
| 1314 | } |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * Called by an application that is administering the device to set the |
| 1320 | * minimum number of symbols required in the password. After setting this, |
| 1321 | * the user will not be able to enter a new password that is not at least as |
| 1322 | * restrictive as what has been set. Note that the current password will |
| 1323 | * remain until the user has set a new one, so the change does not take |
| 1324 | * place immediately. To prompt the user for a new password, use |
| 1325 | * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This |
| 1326 | * constraint is only imposed if the administrator has also requested |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1327 | * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The |
| 1328 | * default value is 1. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1329 | * <p> |
| 1330 | * The calling device admin must have requested |
| 1331 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1332 | * this method; if it has not, a security exception will be thrown. |
| 1333 | * |
| 1334 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1335 | * with. |
| 1336 | * @param length The new desired minimum number of symbols required in the |
| 1337 | * password. A value of 0 means there is no restriction. |
| 1338 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1339 | public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1340 | if (mService != null) { |
| 1341 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1342 | mService.setPasswordMinimumSymbols(admin, length); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1343 | } catch (RemoteException e) { |
| 1344 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /** |
| 1350 | * Retrieve the current number of symbols required in the password for all |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1351 | * admins or a particular one. This is the same value as |
| 1352 | * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)} |
| 1353 | * and only applies when the password quality is |
| 1354 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1355 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1356 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1357 | * aggregate all admins. |
| 1358 | * @return The minimum number of symbols required in the password. |
| 1359 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1360 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1361 | return getPasswordMinimumSymbols(admin, UserHandle.myUserId()); |
| 1362 | } |
| 1363 | |
| 1364 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1365 | public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1366 | if (mService != null) { |
| 1367 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1368 | return mService.getPasswordMinimumSymbols(admin, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1369 | } catch (RemoteException e) { |
| 1370 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1371 | } |
| 1372 | } |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1376 | /** |
| 1377 | * Called by an application that is administering the device to set the |
| 1378 | * minimum number of non-letter characters (numerical digits or symbols) |
| 1379 | * required in the password. After setting this, the user will not be able |
| 1380 | * to enter a new password that is not at least as restrictive as what has |
| 1381 | * been set. Note that the current password will remain until the user has |
| 1382 | * set a new one, so the change does not take place immediately. To prompt |
| 1383 | * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after |
| 1384 | * setting this value. This constraint is only imposed if the administrator |
| 1385 | * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with |
| 1386 | * {@link #setPasswordQuality}. The default value is 0. |
| 1387 | * <p> |
| 1388 | * The calling device admin must have requested |
| 1389 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1390 | * this method; if it has not, a security exception will be thrown. |
| 1391 | * |
| 1392 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1393 | * with. |
| 1394 | * @param length The new desired minimum number of letters required in the |
| 1395 | * password. A value of 0 means there is no restriction. |
| 1396 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1397 | public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1398 | if (mService != null) { |
| 1399 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1400 | mService.setPasswordMinimumNonLetter(admin, length); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1401 | } catch (RemoteException e) { |
| 1402 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1403 | } |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * Retrieve the current number of non-letter characters required in the |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1409 | * password for all admins of this user and its profiles or a particular one. |
| 1410 | * This is the same value as set by |
| 1411 | * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)} |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1412 | * and only applies when the password quality is |
| 1413 | * {@link #PASSWORD_QUALITY_COMPLEX}. |
| 1414 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1415 | * @param admin The name of the admin component to check, or {@code null} to |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1416 | * aggregate all admins. |
| 1417 | * @return The minimum number of letters required in the password. |
| 1418 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1419 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1420 | return getPasswordMinimumNonLetter(admin, UserHandle.myUserId()); |
| 1421 | } |
| 1422 | |
| 1423 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1424 | public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1425 | if (mService != null) { |
| 1426 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1427 | return mService.getPasswordMinimumNonLetter(admin, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1428 | } catch (RemoteException e) { |
| 1429 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1430 | } |
| 1431 | } |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1435 | /** |
| 1436 | * Called by an application that is administering the device to set the length |
| 1437 | * of the password history. After setting this, the user will not be able to |
| 1438 | * enter a new password that is the same as any password in the history. Note |
| 1439 | * that the current password will remain until the user has set a new one, so |
| 1440 | * the change does not take place immediately. To prompt the user for a new |
| 1441 | * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value. |
| 1442 | * This constraint is only imposed if the administrator has also requested |
Jim Miller | 85516d0 | 2014-01-31 17:08:37 -0800 | [diff] [blame] | 1443 | * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} |
| 1444 | * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC} |
| 1445 | * with {@link #setPasswordQuality}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1446 | * |
| 1447 | * <p> |
| 1448 | * The calling device admin must have requested |
| 1449 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this |
| 1450 | * method; if it has not, a security exception will be thrown. |
| 1451 | * |
| 1452 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1453 | * with. |
| 1454 | * @param length The new desired length of password history. A value of 0 |
| 1455 | * means there is no restriction. |
| 1456 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1457 | public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1458 | if (mService != null) { |
| 1459 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1460 | mService.setPasswordHistoryLength(admin, length); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1461 | } catch (RemoteException e) { |
| 1462 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | /** |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1468 | * Called by a device admin to set the password expiration timeout. Calling this method |
| 1469 | * will restart the countdown for password expiration for the given admin, as will changing |
| 1470 | * the device password (for all admins). |
| 1471 | * |
| 1472 | * <p>The provided timeout is the time delta in ms and will be added to the current time. |
| 1473 | * For example, to have the password expire 5 days from now, timeout would be |
| 1474 | * 5 * 86400 * 1000 = 432000000 ms for timeout. |
| 1475 | * |
| 1476 | * <p>To disable password expiration, a value of 0 may be used for timeout. |
| 1477 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1478 | * <p>The calling device admin must have requested |
| 1479 | * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this |
| 1480 | * method; if it has not, a security exception will be thrown. |
| 1481 | * |
Jessica Hummel | 9da6039 | 2014-05-21 12:32:57 +0100 | [diff] [blame] | 1482 | * <p> Note that setting the password will automatically reset the expiration time for all |
| 1483 | * active admins. Active admins do not need to explicitly call this method in that case. |
| 1484 | * |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1485 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 1486 | * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 |
| 1487 | * means there is no restriction (unlimited). |
| 1488 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1489 | public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1490 | if (mService != null) { |
| 1491 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1492 | mService.setPasswordExpirationTimeout(admin, timeout); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1493 | } catch (RemoteException e) { |
| 1494 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | /** |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 1500 | * Get the password expiration timeout for the given admin. The expiration timeout is the |
| 1501 | * recurring expiration timeout provided in the call to |
| 1502 | * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1503 | * aggregate of all policy administrators if {@code admin} is null. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1504 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1505 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1506 | * @return The timeout for the given admin or the minimum of all timeouts |
| 1507 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1508 | public long getPasswordExpirationTimeout(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1509 | if (mService != null) { |
| 1510 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1511 | return mService.getPasswordExpirationTimeout(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1512 | } catch (RemoteException e) { |
| 1513 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1514 | } |
| 1515 | } |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * 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] | 1521 | * all admins of this user and its profiles if admin is null. If the password is |
| 1522 | * expired, this will return the time since the password expired as a negative number. |
| 1523 | * If admin is null, then a composite of all expiration timeouts is returned |
| 1524 | * - which will be the minimum of all timeouts. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1525 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1526 | * @param admin The name of the admin component to check, or {@code null} to aggregate all admins. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1527 | * @return The password expiration time, in ms. |
| 1528 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1529 | public long getPasswordExpiration(@Nullable ComponentName admin) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1530 | if (mService != null) { |
| 1531 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1532 | return mService.getPasswordExpiration(admin, UserHandle.myUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1533 | } catch (RemoteException e) { |
| 1534 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1535 | } |
| 1536 | } |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1541 | * Retrieve the current password history length for all admins of this |
| 1542 | * user and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1543 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1544 | * all admins. |
| 1545 | * @return The length of the password history |
| 1546 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1547 | public int getPasswordHistoryLength(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1548 | return getPasswordHistoryLength(admin, UserHandle.myUserId()); |
| 1549 | } |
| 1550 | |
| 1551 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1552 | public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1553 | if (mService != null) { |
| 1554 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1555 | return mService.getPasswordHistoryLength(admin, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1556 | } catch (RemoteException e) { |
| 1557 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1558 | } |
| 1559 | } |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1563 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1564 | * Return the maximum password length that the device supports for a |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1565 | * particular password quality. |
Dianne Hackborn | 364f6e3 | 2010-01-29 17:38:20 -0800 | [diff] [blame] | 1566 | * @param quality The quality being interrogated. |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1567 | * @return Returns the maximum length that the user can enter. |
| 1568 | */ |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1569 | public int getPasswordMaximumLength(int quality) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1570 | // Kind-of arbitrary. |
| 1571 | return 16; |
| 1572 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1573 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1574 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1575 | * Determine whether the current password the user has set is sufficient |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1576 | * to meet the policy requirements (quality, minimum length) that have been |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1577 | * requested by the admins of this user and its profiles. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1578 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1579 | * <p>The calling device admin must have requested |
| 1580 | * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call |
| 1581 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1582 | * |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1583 | * @return Returns true if the password meets the current requirements, else false. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1584 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1585 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1586 | if (mService != null) { |
| 1587 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1588 | return mService.isActivePasswordSufficient(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1589 | } catch (RemoteException e) { |
| 1590 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1591 | } |
| 1592 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1593 | return false; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1594 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1595 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1596 | /** |
| 1597 | * Retrieve the number of times the user has failed at entering a |
| 1598 | * password since that last successful password entry. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1599 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1600 | * <p>The calling device admin must have requested |
| 1601 | * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call |
| 1602 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1603 | */ |
| 1604 | public int getCurrentFailedPasswordAttempts() { |
| 1605 | if (mService != null) { |
| 1606 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1607 | return mService.getCurrentFailedPasswordAttempts(UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1608 | } catch (RemoteException e) { |
| 1609 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1610 | } |
| 1611 | } |
| 1612 | return -1; |
| 1613 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1614 | |
| 1615 | /** |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1616 | * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set. |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1617 | * |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1618 | * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set. |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1619 | * @hide |
| 1620 | */ |
| 1621 | public boolean getDoNotAskCredentialsOnBoot() { |
| 1622 | if (mService != null) { |
| 1623 | try { |
| 1624 | return mService.getDoNotAskCredentialsOnBoot(); |
| 1625 | } catch (RemoteException e) { |
| 1626 | Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e); |
| 1627 | } |
| 1628 | } |
| 1629 | return false; |
| 1630 | } |
| 1631 | |
| 1632 | /** |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1633 | * Setting this to a value greater than zero enables a built-in policy |
| 1634 | * that will perform a device wipe after too many incorrect |
| 1635 | * device-unlock passwords have been entered. This built-in policy combines |
| 1636 | * watching for failed passwords and wiping the device, and requires |
| 1637 | * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1638 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1639 | * |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1640 | * <p>To implement any other policy (e.g. wiping data for a particular |
| 1641 | * application only, erasing or revoking credentials, or reporting the |
| 1642 | * failure to a server), you should implement |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1643 | * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} |
Andrew Stadler | 88209d1 | 2010-02-08 22:59:36 -0800 | [diff] [blame] | 1644 | * instead. Do not use this API, because if the maximum count is reached, |
| 1645 | * 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] | 1646 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1647 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1648 | * @param num The number of failed password attempts at which point the |
| 1649 | * device will wipe its data. |
| 1650 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1651 | public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1652 | if (mService != null) { |
| 1653 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1654 | mService.setMaximumFailedPasswordsForWipe(admin, num); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1655 | } catch (RemoteException e) { |
| 1656 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1657 | } |
| 1658 | } |
| 1659 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1660 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1661 | /** |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1662 | * Retrieve the current maximum number of login attempts that are allowed |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1663 | * 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] | 1664 | * or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1665 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1666 | * all admins. |
| 1667 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1668 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1669 | return getMaximumFailedPasswordsForWipe(admin, UserHandle.myUserId()); |
| 1670 | } |
| 1671 | |
| 1672 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1673 | public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1674 | if (mService != null) { |
| 1675 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1676 | return mService.getMaximumFailedPasswordsForWipe(admin, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1677 | } catch (RemoteException e) { |
| 1678 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1679 | } |
| 1680 | } |
| 1681 | return 0; |
| 1682 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1683 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1684 | /** |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 1685 | * Returns the profile with the smallest maximum failed passwords for wipe, |
| 1686 | * for the given user. So for primary user, it might return the primary or |
| 1687 | * a managed profile. For a secondary user, it would be the same as the |
| 1688 | * user passed in. |
| 1689 | * @hide Used only by Keyguard |
| 1690 | */ |
| 1691 | public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) { |
| 1692 | if (mService != null) { |
| 1693 | try { |
| 1694 | return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle); |
| 1695 | } catch (RemoteException e) { |
| 1696 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1697 | } |
| 1698 | } |
| 1699 | return UserHandle.USER_NULL; |
| 1700 | } |
| 1701 | |
| 1702 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1703 | * Flag for {@link #resetPassword}: don't allow other admins to change |
| 1704 | * the password again until the user has entered it. |
| 1705 | */ |
| 1706 | public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1707 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1708 | /** |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1709 | * Flag for {@link #resetPassword}: don't ask for user credentials on device boot. |
| 1710 | * If the flag is set, the device can be booted without asking for user password. |
| 1711 | * The absence of this flag does not change the current boot requirements. This flag |
| 1712 | * can be set by the device owner only. If the app is not the device owner, the flag |
| 1713 | * is ignored. Once the flag is set, it cannot be reverted back without resetting the |
| 1714 | * device to factory defaults. |
| 1715 | */ |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1716 | public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002; |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1717 | |
| 1718 | /** |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1719 | * Force a new device unlock password (the password needed to access the |
| 1720 | * entire device, not for individual accounts) on the user. This takes |
| 1721 | * effect immediately. |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1722 | * The given password must be sufficient for the |
| 1723 | * current password quality and length constraints as returned by |
| 1724 | * {@link #getPasswordQuality(ComponentName)} and |
| 1725 | * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet |
| 1726 | * these constraints, then it will be rejected and false returned. Note |
| 1727 | * that the password may be a stronger quality (containing alphanumeric |
| 1728 | * characters when the requested quality is only numeric), in which case |
| 1729 | * the currently active quality will be increased to match. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1730 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1731 | * <p>Calling with a null or empty password will clear any existing PIN, |
| 1732 | * pattern or password if the current password constraints allow it. |
| 1733 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1734 | * <p>The calling device admin must have requested |
| 1735 | * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call |
| 1736 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1737 | * |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 1738 | * <p>Calling this from a managed profile will throw a security exception. |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1739 | * |
Adrian Roos | f8f56bc | 2014-11-20 23:55:34 +0100 | [diff] [blame] | 1740 | * @param password The new password for the user. Null or empty clears the password. |
Andrei Kapishnikov | 4eb6a36 | 2015-04-02 15:21:20 -0400 | [diff] [blame] | 1741 | * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and |
Craig Lafayette | 4e401fa | 2015-05-07 10:24:02 -0400 | [diff] [blame] | 1742 | * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}. |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1743 | * @return Returns true if the password was applied, or false if it is |
| 1744 | * not acceptable for the current constraints. |
| 1745 | */ |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1746 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1747 | if (mService != null) { |
| 1748 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1749 | return mService.resetPassword(password, flags); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1750 | } catch (RemoteException e) { |
| 1751 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1752 | } |
| 1753 | } |
| 1754 | return false; |
| 1755 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1756 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1757 | /** |
| 1758 | * Called by an application that is administering the device to set the |
| 1759 | * maximum time for user activity until the device will lock. This limits |
| 1760 | * the length that the user can set. It takes effect immediately. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1761 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1762 | * <p>The calling device admin must have requested |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1763 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1764 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1765 | * |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1766 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1767 | * @param timeMs The new desired maximum time to lock in milliseconds. |
| 1768 | * A value of 0 means there is no restriction. |
| 1769 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1770 | public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1771 | if (mService != null) { |
| 1772 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1773 | mService.setMaximumTimeToLock(admin, timeMs); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1774 | } catch (RemoteException e) { |
| 1775 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1776 | } |
| 1777 | } |
| 1778 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1779 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1780 | /** |
Jessica Hummel | 91da58d | 2014-04-10 17:39:43 +0100 | [diff] [blame] | 1781 | * Retrieve the current maximum time to unlock for all admins of this user |
| 1782 | * and its profiles or a particular one. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1783 | * @param admin The name of the admin component to check, or {@code null} to aggregate |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1784 | * all admins. |
Jim Miller | d4efaac | 2014-08-14 18:02:45 -0700 | [diff] [blame] | 1785 | * @return time in milliseconds for the given admin or the minimum value (strictest) of |
Jim Miller | 76b9b8b | 2014-08-22 17:04:57 -0700 | [diff] [blame] | 1786 | * all admins if admin is null. Returns 0 if there are no restrictions. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1787 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1788 | public long getMaximumTimeToLock(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1789 | return getMaximumTimeToLock(admin, UserHandle.myUserId()); |
| 1790 | } |
| 1791 | |
| 1792 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1793 | public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1794 | if (mService != null) { |
| 1795 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1796 | return mService.getMaximumTimeToLock(admin, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1797 | } catch (RemoteException e) { |
| 1798 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1799 | } |
| 1800 | } |
| 1801 | return 0; |
| 1802 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1803 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1804 | /** |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1805 | * Make the device lock immediately, as if the lock screen timeout has |
| 1806 | * expired at the point of this call. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1807 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1808 | * <p>The calling device admin must have requested |
| 1809 | * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call |
| 1810 | * this method; if it has not, a security exception will be thrown. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1811 | */ |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1812 | public void lockNow() { |
| 1813 | if (mService != null) { |
| 1814 | try { |
| 1815 | mService.lockNow(); |
| 1816 | } catch (RemoteException e) { |
| 1817 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1818 | } |
| 1819 | } |
| 1820 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1821 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1822 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1823 | * Flag for {@link #wipeData(int)}: also erase the device's external |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1824 | * storage (such as SD cards). |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1825 | */ |
| 1826 | public static final int WIPE_EXTERNAL_STORAGE = 0x0001; |
| 1827 | |
| 1828 | /** |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1829 | * Flag for {@link #wipeData(int)}: also erase the factory reset protection |
| 1830 | * data. |
| 1831 | * |
Paul Crowley | 2934b26 | 2014-12-02 11:21:13 +0000 | [diff] [blame] | 1832 | * <p>This flag may only be set by device owner admins; if it is set by |
| 1833 | * other admins a {@link SecurityException} will be thrown. |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1834 | */ |
| 1835 | public static final int WIPE_RESET_PROTECTION_DATA = 0x0002; |
| 1836 | |
| 1837 | /** |
Robin Lee | 85bd63f | 2015-02-10 11:51:00 +0000 | [diff] [blame] | 1838 | * Ask the user data be wiped. Wiping the primary user will cause the |
| 1839 | * device to reboot, erasing all user data while next booting up. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1840 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1841 | * <p>The calling device admin must have requested |
| 1842 | * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call |
| 1843 | * this method; if it has not, a security exception will be thrown. |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1844 | * |
Paul Crowley | a7e87ac | 2014-11-18 13:50:19 +0000 | [diff] [blame] | 1845 | * @param flags Bit mask of additional options: currently supported flags |
| 1846 | * are {@link #WIPE_EXTERNAL_STORAGE} and |
| 1847 | * {@link #WIPE_RESET_PROTECTION_DATA}. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1848 | */ |
| 1849 | public void wipeData(int flags) { |
| 1850 | if (mService != null) { |
| 1851 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1852 | mService.wipeData(flags, UserHandle.myUserId()); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1853 | } catch (RemoteException e) { |
| 1854 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1855 | } |
| 1856 | } |
| 1857 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1858 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1859 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1860 | * Called by an application that is administering the device to set the |
| 1861 | * global proxy and exclusion list. |
| 1862 | * <p> |
| 1863 | * The calling device admin must have requested |
| 1864 | * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call |
| 1865 | * this method; if it has not, a security exception will be thrown. |
| 1866 | * Only the first device admin can set the proxy. If a second admin attempts |
| 1867 | * to set the proxy, the {@link ComponentName} of the admin originally setting the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1868 | * proxy will be returned. If successful in setting the proxy, {@code null} will |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1869 | * be returned. |
| 1870 | * The method can be called repeatedly by the device admin alrady setting the |
| 1871 | * proxy to update the proxy and exclusion list. |
| 1872 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1873 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1874 | * @param proxySpec the global proxy desired. Must be an HTTP Proxy. |
| 1875 | * Pass Proxy.NO_PROXY to reset the proxy. |
| 1876 | * @param exclusionList a list of domains to be excluded from the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1877 | * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName} |
| 1878 | * of the device admin that sets the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1879 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1880 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1881 | public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1882 | List<String> exclusionList ) { |
| 1883 | if (proxySpec == null) { |
| 1884 | throw new NullPointerException(); |
| 1885 | } |
| 1886 | if (mService != null) { |
| 1887 | try { |
| 1888 | String hostSpec; |
| 1889 | String exclSpec; |
| 1890 | if (proxySpec.equals(Proxy.NO_PROXY)) { |
| 1891 | hostSpec = null; |
| 1892 | exclSpec = null; |
| 1893 | } else { |
| 1894 | if (!proxySpec.type().equals(Proxy.Type.HTTP)) { |
| 1895 | throw new IllegalArgumentException(); |
| 1896 | } |
| 1897 | InetSocketAddress sa = (InetSocketAddress)proxySpec.address(); |
| 1898 | String hostName = sa.getHostName(); |
| 1899 | int port = sa.getPort(); |
| 1900 | StringBuilder hostBuilder = new StringBuilder(); |
| 1901 | hostSpec = hostBuilder.append(hostName) |
| 1902 | .append(":").append(Integer.toString(port)).toString(); |
| 1903 | if (exclusionList == null) { |
| 1904 | exclSpec = ""; |
| 1905 | } else { |
| 1906 | StringBuilder listBuilder = new StringBuilder(); |
| 1907 | boolean firstDomain = true; |
| 1908 | for (String exclDomain : exclusionList) { |
| 1909 | if (!firstDomain) { |
| 1910 | listBuilder = listBuilder.append(","); |
| 1911 | } else { |
| 1912 | firstDomain = false; |
| 1913 | } |
| 1914 | listBuilder = listBuilder.append(exclDomain.trim()); |
| 1915 | } |
| 1916 | exclSpec = listBuilder.toString(); |
| 1917 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 1918 | if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec) |
| 1919 | != android.net.Proxy.PROXY_VALID) |
| 1920 | throw new IllegalArgumentException(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1921 | } |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 1922 | return mService.setGlobalProxy(admin, hostSpec, exclSpec); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1923 | } catch (RemoteException e) { |
| 1924 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1925 | } |
| 1926 | } |
| 1927 | return null; |
| 1928 | } |
| 1929 | |
| 1930 | /** |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 1931 | * Set a network-independent global HTTP proxy. This is not normally what you want |
| 1932 | * for typical HTTP proxies - they are generally network dependent. However if you're |
| 1933 | * doing something unusual like general internal filtering this may be useful. On |
| 1934 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1935 | * |
| 1936 | * <p>This method requires the caller to be the device owner. |
| 1937 | * |
| 1938 | * <p>This proxy is only a recommendation and it is possible that some apps will ignore it. |
| 1939 | * @see ProxyInfo |
| 1940 | * |
| 1941 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 1942 | * with. |
| 1943 | * @param proxyInfo The a {@link ProxyInfo} object defining the new global |
| 1944 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1945 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1946 | public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo |
| 1947 | proxyInfo) { |
Jason Monk | 03bc991 | 2014-05-13 09:44:57 -0400 | [diff] [blame] | 1948 | if (mService != null) { |
| 1949 | try { |
| 1950 | mService.setRecommendedGlobalProxy(admin, proxyInfo); |
| 1951 | } catch (RemoteException e) { |
| 1952 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | /** |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1958 | * Returns the component name setting the global proxy. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 1959 | * @return ComponentName object of the device admin that set the global proxy, or {@code null} |
| 1960 | * if no admin has set the proxy. |
Andy Stadler | d267272 | 2011-02-16 10:53:33 -0800 | [diff] [blame] | 1961 | * @hide |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1962 | */ |
| 1963 | public ComponentName getGlobalProxyAdmin() { |
| 1964 | if (mService != null) { |
| 1965 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1966 | return mService.getGlobalProxyAdmin(UserHandle.myUserId()); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1967 | } catch (RemoteException e) { |
| 1968 | Log.w(TAG, "Failed talking with device policy service", e); |
| 1969 | } |
| 1970 | } |
| 1971 | return null; |
| 1972 | } |
| 1973 | |
| 1974 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1975 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1976 | * indicating that encryption is not supported. |
| 1977 | */ |
| 1978 | public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; |
| 1979 | |
| 1980 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1981 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1982 | * indicating that encryption is supported, but is not currently active. |
| 1983 | */ |
| 1984 | public static final int ENCRYPTION_STATUS_INACTIVE = 1; |
| 1985 | |
| 1986 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 1987 | * Result code for {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1988 | * indicating that encryption is not currently active, but is currently |
| 1989 | * being activated. This is only reported by devices that support |
| 1990 | * encryption of data and only when the storage is currently |
| 1991 | * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data |
| 1992 | * to become encrypted will never return this value. |
| 1993 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1994 | public static final int ENCRYPTION_STATUS_ACTIVATING = 2; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1995 | |
| 1996 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 1997 | * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}: |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 1998 | * indicating that encryption is active. |
| 1999 | */ |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2000 | public static final int ENCRYPTION_STATUS_ACTIVE = 3; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2001 | |
| 2002 | /** |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2003 | * Result code for {@link #getStorageEncryptionStatus}: |
| 2004 | * indicating that encryption is active, but an encryption key has not |
| 2005 | * been set by the user. |
| 2006 | */ |
| 2007 | public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4; |
| 2008 | |
| 2009 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2010 | * Activity action: begin the process of encrypting data on the device. This activity should |
| 2011 | * be launched after using {@link #setStorageEncryption} to request encryption be activated. |
| 2012 | * After resuming from this activity, use {@link #getStorageEncryption} |
| 2013 | * to check encryption status. However, on some devices this activity may never return, as |
| 2014 | * it may trigger a reboot and in some cases a complete data wipe of the device. |
| 2015 | */ |
| 2016 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 2017 | public static final String ACTION_START_ENCRYPTION |
| 2018 | = "android.app.action.START_ENCRYPTION"; |
| 2019 | |
| 2020 | /** |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2021 | * Widgets are enabled in keyguard |
| 2022 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2023 | public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2024 | |
| 2025 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2026 | * Disable all keyguard widgets. Has no effect. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2027 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2028 | public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0; |
| 2029 | |
| 2030 | /** |
| 2031 | * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2032 | */ |
| 2033 | public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1; |
| 2034 | |
| 2035 | /** |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2036 | * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2037 | */ |
| 2038 | public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2; |
| 2039 | |
| 2040 | /** |
| 2041 | * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password) |
| 2042 | */ |
| 2043 | public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3; |
| 2044 | |
| 2045 | /** |
Adrian Roos | a06d5ca | 2014-07-28 15:14:21 +0200 | [diff] [blame] | 2046 | * Ignore trust agent state on secure keyguard screens |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2047 | * (e.g. PIN/Pattern/Password). |
| 2048 | */ |
| 2049 | public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4; |
| 2050 | |
| 2051 | /** |
Jim Miller | 06e3450 | 2014-07-17 14:46:05 -0700 | [diff] [blame] | 2052 | * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password). |
| 2053 | */ |
| 2054 | public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5; |
| 2055 | |
| 2056 | /** |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2057 | * Disable all current and future keyguard customizations. |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2058 | */ |
| 2059 | public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2060 | |
| 2061 | /** |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2062 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2063 | * request that the storage system be encrypted. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2064 | * |
| 2065 | * <p>When multiple device administrators attempt to control device |
| 2066 | * encryption, the most secure, supported setting will always be |
| 2067 | * used. If any device administrator requests device encryption, |
| 2068 | * it will be enabled; Conversely, if a device administrator |
| 2069 | * attempts to disable device encryption while another |
| 2070 | * device administrator has enabled it, the call to disable will |
| 2071 | * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}). |
| 2072 | * |
| 2073 | * <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] | 2074 | * written to other storage areas may or may not be encrypted, and this policy does not require |
| 2075 | * or control the encryption of any other storage areas. |
| 2076 | * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is |
| 2077 | * {@code true}, then the directory returned by |
| 2078 | * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk |
| 2079 | * within the encrypted storage area. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2080 | * |
| 2081 | * <p>Important Note: On some devices, it is possible to encrypt storage without requiring |
| 2082 | * the user to create a device PIN or Password. In this case, the storage is encrypted, but |
| 2083 | * the encryption key may not be fully secured. For maximum security, the administrator should |
| 2084 | * also require (and check for) a pattern, PIN, or password. |
| 2085 | * |
| 2086 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2087 | * @param encrypt true to request encryption, false to release any previous request |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2088 | * @return the new request status (for all active admins) - will be one of |
| 2089 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or |
| 2090 | * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use |
| 2091 | * {@link #getStorageEncryptionStatus()} to query the actual device state. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2092 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2093 | public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2094 | if (mService != null) { |
| 2095 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2096 | return mService.setStorageEncryption(admin, encrypt); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2097 | } catch (RemoteException e) { |
| 2098 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2099 | } |
| 2100 | } |
| 2101 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2102 | } |
| 2103 | |
| 2104 | /** |
| 2105 | * Called by an application that is administering the device to |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2106 | * determine the requested setting for secure storage. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2107 | * |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2108 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 2109 | * this will return the requested encryption setting as an aggregate of all active |
| 2110 | * administrators. |
| 2111 | * @return true if the admin(s) are requesting encryption, false if not. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2112 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2113 | public boolean getStorageEncryption(@Nullable ComponentName admin) { |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2114 | if (mService != null) { |
| 2115 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2116 | return mService.getStorageEncryption(admin, UserHandle.myUserId()); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2117 | } catch (RemoteException e) { |
| 2118 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2119 | } |
| 2120 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2121 | return false; |
| 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * Called by an application that is administering the device to |
| 2126 | * determine the current encryption status of the device. |
| 2127 | * |
| 2128 | * Depending on the returned status code, the caller may proceed in different |
| 2129 | * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the |
| 2130 | * storage system does not support encryption. If the |
| 2131 | * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link |
| 2132 | * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2133 | * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the |
| 2134 | * storage system has enabled encryption but no password is set so further action |
| 2135 | * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2136 | * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required. |
| 2137 | * |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2138 | * @return current status of encryption. The value will be one of |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2139 | * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, |
Robin Lee | 3795fb0 | 2015-02-16 14:17:23 +0000 | [diff] [blame] | 2140 | * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, |
| 2141 | * or {@link #ENCRYPTION_STATUS_ACTIVE}. |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2142 | */ |
| 2143 | public int getStorageEncryptionStatus() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2144 | return getStorageEncryptionStatus(UserHandle.myUserId()); |
| 2145 | } |
| 2146 | |
| 2147 | /** @hide per-user version */ |
| 2148 | public int getStorageEncryptionStatus(int userHandle) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2149 | if (mService != null) { |
| 2150 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2151 | return mService.getStorageEncryptionStatus(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2152 | } catch (RemoteException e) { |
| 2153 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2154 | } |
| 2155 | } |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2156 | return ENCRYPTION_STATUS_UNSUPPORTED; |
| 2157 | } |
| 2158 | |
| 2159 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2160 | * Installs the given certificate as a user CA. |
| 2161 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2162 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2163 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2164 | * @param certBuffer encoded form of the certificate to install. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2165 | * |
| 2166 | * @return false if the certBuffer cannot be parsed or installation is |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2167 | * interrupted, true otherwise. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2168 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2169 | public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2170 | if (mService != null) { |
| 2171 | try { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2172 | return mService.installCaCert(admin, certBuffer); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2173 | } catch (RemoteException e) { |
| 2174 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2175 | } |
| 2176 | } |
| 2177 | return false; |
| 2178 | } |
| 2179 | |
| 2180 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2181 | * Uninstalls the given certificate from trusted user CAs, if present. |
| 2182 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2183 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2184 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2185 | * @param certBuffer encoded form of the certificate to remove. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2186 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2187 | public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) { |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2188 | if (mService != null) { |
| 2189 | try { |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2190 | final String alias = getCaCertAlias(certBuffer); |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2191 | mService.uninstallCaCerts(admin, new String[] {alias}); |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2192 | } catch (CertificateException e) { |
| 2193 | Log.w(TAG, "Unable to parse certificate", e); |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2194 | } catch (RemoteException e) { |
| 2195 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2201 | * Returns all CA certificates that are currently trusted, excluding system CA certificates. |
| 2202 | * If a user has installed any certificates by other means than device policy these will be |
| 2203 | * included too. |
| 2204 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2205 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2206 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2207 | * @return a List of byte[] arrays, each encoding one user CA certificate. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2208 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2209 | public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2210 | List<byte[]> certs = new ArrayList<byte[]>(); |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2211 | if (mService != null) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2212 | try { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2213 | mService.enforceCanManageCaCerts(admin); |
| 2214 | final TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2215 | for (String alias : certStore.userAliases()) { |
| 2216 | try { |
| 2217 | certs.add(certStore.getCertificate(alias).getEncoded()); |
| 2218 | } catch (CertificateException ce) { |
| 2219 | Log.w(TAG, "Could not encode certificate: " + alias, ce); |
| 2220 | } |
| 2221 | } |
| 2222 | } catch (RemoteException re) { |
| 2223 | Log.w(TAG, "Failed talking with device policy service", re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | return certs; |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /** |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2230 | * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by |
| 2231 | * means other than device policy will also be removed, except for system CA certificates. |
| 2232 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2233 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2234 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2235 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2236 | public void uninstallAllUserCaCerts(@Nullable ComponentName admin) { |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2237 | if (mService != null) { |
Robin Lee | 83881bd | 2015-06-09 16:04:38 -0700 | [diff] [blame] | 2238 | try { |
| 2239 | mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases() |
| 2240 | .toArray(new String[0])); |
| 2241 | } catch (RemoteException re) { |
| 2242 | Log.w(TAG, "Failed talking with device policy service", re); |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | /** |
| 2248 | * Returns whether this certificate is installed as a trusted CA. |
| 2249 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2250 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2251 | * {@code null} if calling from a delegated certificate installer. |
Robin Lee | 7e67871 | 2014-07-24 16:41:31 +0100 | [diff] [blame] | 2252 | * @param certBuffer encoded form of the certificate to look up. |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2253 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2254 | public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) { |
Esteban Talavera | 808f6ef | 2014-08-28 17:15:54 +0100 | [diff] [blame] | 2255 | if (mService != null) { |
| 2256 | try { |
| 2257 | mService.enforceCanManageCaCerts(admin); |
| 2258 | return getCaCertAlias(certBuffer) != null; |
| 2259 | } catch (RemoteException re) { |
| 2260 | Log.w(TAG, "Failed talking with device policy service", re); |
| 2261 | } catch (CertificateException ce) { |
| 2262 | Log.w(TAG, "Could not parse certificate", ce); |
| 2263 | } |
Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2264 | } |
| 2265 | return false; |
| 2266 | } |
| 2267 | |
| 2268 | /** |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2269 | * Called by a device or profile owner to install a certificate and private key pair. The |
| 2270 | * keypair will be visible to all apps within the profile. |
| 2271 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2272 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2273 | * {@code null} if calling from a delegated certificate installer. |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2274 | * @param privKey The private key to install. |
| 2275 | * @param cert The certificate to install. |
| 2276 | * @param alias The private key alias under which to install the certificate. If a certificate |
| 2277 | * with that alias already exists, it will be overwritten. |
| 2278 | * @return {@code true} if the keys were installed, {@code false} otherwise. |
| 2279 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2280 | public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert, |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2281 | String alias) { |
| 2282 | try { |
| 2283 | final byte[] pemCert = Credentials.convertToPem(cert); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2284 | final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm()) |
| 2285 | .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded(); |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2286 | return mService.installKeyPair(admin, pkcs8Key, pemCert, alias); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2287 | } catch (RemoteException e) { |
| 2288 | Log.w(TAG, "Failed talking with device policy service", e); |
Robin Lee | 0d5ccb7 | 2014-09-12 17:41:44 +0100 | [diff] [blame] | 2289 | } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { |
| 2290 | Log.w(TAG, "Failed to obtain private key material", e); |
| 2291 | } catch (CertificateException | IOException e) { |
| 2292 | Log.w(TAG, "Could not pem-encode certificate", e); |
Bernhard Bauer | 26408cc | 2014-09-08 14:07:31 +0100 | [diff] [blame] | 2293 | } |
| 2294 | return false; |
| 2295 | } |
| 2296 | |
| 2297 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2298 | * @return the alias of a given CA certificate in the certificate store, or {@code null} if it |
Robin Lee | 306fe08 | 2014-06-19 14:04:24 +0000 | [diff] [blame] | 2299 | * doesn't exist. |
| 2300 | */ |
| 2301 | private static String getCaCertAlias(byte[] certBuffer) throws CertificateException { |
| 2302 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2303 | final X509Certificate cert = (X509Certificate) certFactory.generateCertificate( |
| 2304 | new ByteArrayInputStream(certBuffer)); |
| 2305 | return new TrustedCertificateStore().getCertificateAlias(cert); |
| 2306 | } |
| 2307 | |
| 2308 | /** |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2309 | * Called by a profile owner or device owner to grant access to privileged certificate |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2310 | * manipulation APIs to a third-party certificate installer app. Granted APIs include |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2311 | * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert}, |
Rubin Xu | acdc183 | 2015-04-02 12:40:20 +0100 | [diff] [blame] | 2312 | * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2313 | * <p> |
| 2314 | * Delegated certificate installer is a per-user state. The delegated access is persistent until |
| 2315 | * it is later cleared by calling this method with a null value or uninstallling the certificate |
| 2316 | * installer. |
| 2317 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2318 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2319 | * @param installerPackage The package name of the certificate installer which will be given |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2320 | * access. If {@code null} is given the current package will be cleared. |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2321 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2322 | public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String |
| 2323 | installerPackage) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2324 | if (mService != null) { |
| 2325 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2326 | mService.setCertInstallerPackage(admin, installerPackage); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2327 | } catch (RemoteException e) { |
| 2328 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Called by a profile owner or device owner to retrieve the certificate installer for the |
| 2335 | * current user. null if none is set. |
| 2336 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2337 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2338 | * @return The package name of the current delegated certificate installer, or {@code null} |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2339 | * if none is set. |
| 2340 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2341 | public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException { |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2342 | if (mService != null) { |
| 2343 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2344 | return mService.getCertInstallerPackage(admin); |
Rubin Xu | ec32b56 | 2015-03-03 17:34:05 +0000 | [diff] [blame] | 2345 | } catch (RemoteException e) { |
| 2346 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2347 | } |
| 2348 | } |
| 2349 | return null; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2353 | * Called by an application that is administering the device to disable all cameras |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2354 | * on the device, for this user. After setting this, no applications running as this user |
| 2355 | * will be able to access any cameras on the device. |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2356 | * |
| 2357 | * <p>The calling device admin must have requested |
| 2358 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call |
| 2359 | * this method; if it has not, a security exception will be thrown. |
| 2360 | * |
| 2361 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2362 | * @param disabled Whether or not the camera should be disabled. |
| 2363 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2364 | public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2365 | if (mService != null) { |
| 2366 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2367 | mService.setCameraDisabled(admin, disabled); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2368 | } catch (RemoteException e) { |
| 2369 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2370 | } |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | /** |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2375 | * Determine whether or not the device's cameras have been disabled for this user, |
| 2376 | * either by the current admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2377 | * @param admin The name of the admin component to check, or {@code null} to check whether any admins |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2378 | * have disabled the camera |
| 2379 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2380 | public boolean getCameraDisabled(@Nullable ComponentName admin) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2381 | return getCameraDisabled(admin, UserHandle.myUserId()); |
| 2382 | } |
| 2383 | |
| 2384 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2385 | public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2386 | if (mService != null) { |
| 2387 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2388 | return mService.getCameraDisabled(admin, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2389 | } catch (RemoteException e) { |
| 2390 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2391 | } |
| 2392 | } |
| 2393 | return false; |
| 2394 | } |
| 2395 | |
| 2396 | /** |
Esteban Talavera | 1aee98f | 2014-08-21 14:03:55 +0100 | [diff] [blame] | 2397 | * Called by a device/profile owner to set whether the screen capture is disabled. Disabling |
| 2398 | * screen capture also prevents the content from being shown on display devices that do not have |
| 2399 | * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about |
| 2400 | * secure surfaces and secure displays. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2401 | * |
| 2402 | * <p>The calling device admin must be a device or profile owner. If it is not, a |
| 2403 | * security exception will be thrown. |
| 2404 | * |
| 2405 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2406 | * @param disabled Whether screen capture is disabled or not. |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2407 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2408 | public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2409 | if (mService != null) { |
| 2410 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2411 | mService.setScreenCaptureDisabled(admin, disabled); |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2412 | } catch (RemoteException e) { |
| 2413 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2414 | } |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * Determine whether or not screen capture has been disabled by the current |
| 2420 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2421 | * @param admin The name of the admin component to check, or {@code null} to check whether any admins |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2422 | * have disabled screen capture. |
| 2423 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2424 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2425 | return getScreenCaptureDisabled(admin, UserHandle.myUserId()); |
| 2426 | } |
| 2427 | |
| 2428 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2429 | public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) { |
Sander Alewijnse | d2a1eec | 2014-07-09 12:57:05 +0100 | [diff] [blame] | 2430 | if (mService != null) { |
| 2431 | try { |
| 2432 | return mService.getScreenCaptureDisabled(admin, userHandle); |
| 2433 | } catch (RemoteException e) { |
| 2434 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2435 | } |
| 2436 | } |
| 2437 | return false; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2441 | * Called by a device owner to set whether auto time is required. If auto time is |
| 2442 | * required the user cannot set the date and time, but has to use network date and time. |
| 2443 | * |
| 2444 | * <p>Note: if auto time is required the user can still manually set the time zone. |
| 2445 | * |
| 2446 | * <p>The calling device admin must be a device owner. If it is not, a security exception will |
| 2447 | * be thrown. |
| 2448 | * |
| 2449 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2450 | * @param required Whether auto time is set required or not. |
| 2451 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2452 | public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) { |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2453 | if (mService != null) { |
| 2454 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2455 | mService.setAutoTimeRequired(admin, required); |
Sander Alewijnse | 0ced627 | 2014-08-26 11:18:26 +0100 | [diff] [blame] | 2456 | } catch (RemoteException e) { |
| 2457 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | /** |
| 2463 | * @return true if auto time is required. |
| 2464 | */ |
| 2465 | public boolean getAutoTimeRequired() { |
| 2466 | if (mService != null) { |
| 2467 | try { |
| 2468 | return mService.getAutoTimeRequired(); |
| 2469 | } catch (RemoteException e) { |
| 2470 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2471 | } |
| 2472 | } |
| 2473 | return false; |
| 2474 | } |
| 2475 | |
| 2476 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2477 | * Called by an application that is administering the device to disable keyguard customizations, |
| 2478 | * such as widgets. After setting this, keyguard features will be disabled according to the |
| 2479 | * provided feature list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2480 | * |
| 2481 | * <p>The calling device admin must have requested |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2482 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2483 | * this method; if it has not, a security exception will be thrown. |
| 2484 | * |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2485 | * <p>Calling this from a managed profile before version |
| 2486 | * {@link android.os.Build.VERSION_CODES#MNC} will throw a security exception. |
| 2487 | * |
| 2488 | * <p>From version {@link android.os.Build.VERSION_CODES#MNC} a profile owner can set: |
| 2489 | * <ul> |
| 2490 | * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT} |
| 2491 | * these will affect the profile's parent user. |
| 2492 | * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications |
| 2493 | * generated by applications in the managed profile. |
| 2494 | * </ul> |
| 2495 | * <p>Requests to disable other features on a managed profile will be ignored. The admin |
| 2496 | * can check which features have been disabled by calling |
| 2497 | * {@link #getKeyguardDisabledFeatures(ComponentName)} |
Amith Yamasani | 242f4b1 | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 2498 | * |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2499 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2500 | * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default), |
| 2501 | * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA}, |
Jim Miller | 50e6218 | 2014-04-23 17:25:00 -0700 | [diff] [blame] | 2502 | * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 2503 | * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}, |
| 2504 | * {@link #KEYGUARD_DISABLE_FEATURES_ALL} |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2505 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2506 | public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2507 | if (mService != null) { |
| 2508 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 2509 | mService.setKeyguardDisabledFeatures(admin, which); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2510 | } catch (RemoteException e) { |
| 2511 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2517 | * 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] | 2518 | * admin, if specified, or all admins. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2519 | * @param admin The name of the admin component to check, or {@code null} to check whether any admins |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2520 | * have disabled features in keyguard. |
Jim Miller | 3520774 | 2012-11-02 15:33:20 -0700 | [diff] [blame] | 2521 | * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)} |
| 2522 | * for a list. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2523 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2524 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2525 | return getKeyguardDisabledFeatures(admin, UserHandle.myUserId()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2529 | public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) { |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2530 | if (mService != null) { |
| 2531 | try { |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2532 | return mService.getKeyguardDisabledFeatures(admin, userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2533 | } catch (RemoteException e) { |
| 2534 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2535 | } |
| 2536 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2537 | return KEYGUARD_DISABLE_FEATURES_NONE; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2541 | * @hide |
| 2542 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2543 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing, |
| 2544 | int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2545 | if (mService != null) { |
| 2546 | try { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2547 | mService.setActiveAdmin(policyReceiver, refreshing, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2548 | } catch (RemoteException e) { |
| 2549 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2550 | } |
| 2551 | } |
| 2552 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2553 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2554 | /** |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2555 | * @hide |
| 2556 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2557 | public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) { |
Jessica Hummel | 6d36b60 | 2014-04-04 12:42:17 +0100 | [diff] [blame] | 2558 | setActiveAdmin(policyReceiver, refreshing, UserHandle.myUserId()); |
| 2559 | } |
| 2560 | |
| 2561 | /** |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2562 | * 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] | 2563 | * @hide |
| 2564 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2565 | public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2566 | ActivityInfo ai; |
| 2567 | try { |
| 2568 | ai = mContext.getPackageManager().getReceiverInfo(cn, |
| 2569 | PackageManager.GET_META_DATA); |
| 2570 | } catch (PackageManager.NameNotFoundException e) { |
| 2571 | Log.w(TAG, "Unable to retrieve device policy " + cn, e); |
| 2572 | return null; |
| 2573 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2574 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2575 | ResolveInfo ri = new ResolveInfo(); |
| 2576 | ri.activityInfo = ai; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2577 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2578 | try { |
| 2579 | return new DeviceAdminInfo(mContext, ri); |
| 2580 | } catch (XmlPullParserException e) { |
| 2581 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2582 | return null; |
| 2583 | } catch (IOException e) { |
| 2584 | Log.w(TAG, "Unable to parse device policy " + cn, e); |
| 2585 | return null; |
| 2586 | } |
| 2587 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2588 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2589 | /** |
| 2590 | * @hide |
| 2591 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2592 | public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2593 | if (mService != null) { |
| 2594 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2595 | mService.getRemoveWarning(admin, result, UserHandle.myUserId()); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2596 | } catch (RemoteException e) { |
| 2597 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2598 | } |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | /** |
| 2603 | * @hide |
| 2604 | */ |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2605 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2606 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2607 | if (mService != null) { |
| 2608 | try { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2609 | mService.setActivePasswordState(quality, length, letters, uppercase, lowercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2610 | numbers, symbols, nonletter, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2611 | } catch (RemoteException e) { |
| 2612 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2613 | } |
| 2614 | } |
| 2615 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2616 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2617 | /** |
| 2618 | * @hide |
| 2619 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2620 | public void reportFailedPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2621 | if (mService != null) { |
| 2622 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2623 | mService.reportFailedPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2624 | } catch (RemoteException e) { |
| 2625 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2626 | } |
| 2627 | } |
| 2628 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2629 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2630 | /** |
| 2631 | * @hide |
| 2632 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2633 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2634 | if (mService != null) { |
| 2635 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2636 | mService.reportSuccessfulPasswordAttempt(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2637 | } catch (RemoteException e) { |
| 2638 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2639 | } |
| 2640 | } |
| 2641 | } |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2642 | |
| 2643 | /** |
| 2644 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2645 | * Sets the given package as the device owner. |
| 2646 | * Same as {@link #setDeviceOwner(String, String)} but without setting a device owner name. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2647 | * @param packageName the package name of the application to be registered as the device owner. |
| 2648 | * @return whether the package was successfully registered as the device owner. |
| 2649 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2650 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2651 | */ |
| 2652 | public boolean setDeviceOwner(String packageName) throws IllegalArgumentException, |
| 2653 | IllegalStateException { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2654 | return setDeviceOwner(packageName, null); |
| 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * @hide |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2659 | * Sets the given package as the device owner. The package must already be installed. There |
| 2660 | * must not already be a device owner. |
| 2661 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 2662 | * this method. |
| 2663 | * Calling this after the setup phase of the primary user has completed is allowed only if |
| 2664 | * the caller is the shell uid, and there are no additional users and no accounts. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2665 | * @param packageName the package name of the application to be registered as the device owner. |
| 2666 | * @param ownerName the human readable name of the institution that owns this device. |
| 2667 | * @return whether the package was successfully registered as the device owner. |
| 2668 | * @throws IllegalArgumentException if the package name is null or invalid |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2669 | * @throws IllegalStateException If the preconditions mentioned are not met. |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2670 | */ |
| 2671 | public boolean setDeviceOwner(String packageName, String ownerName) |
| 2672 | throws IllegalArgumentException, IllegalStateException { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2673 | if (mService != null) { |
| 2674 | try { |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2675 | return mService.setDeviceOwner(packageName, ownerName); |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2676 | } catch (RemoteException re) { |
| 2677 | Log.w(TAG, "Failed to set device owner"); |
| 2678 | } |
| 2679 | } |
| 2680 | return false; |
| 2681 | } |
| 2682 | |
| 2683 | /** |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2684 | * Used to determine if a particular package has been registered as a Device Owner app. |
| 2685 | * A device owner app is a special device admin that cannot be deactivated by the user, once |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2686 | * activated as a device admin. It also cannot be uninstalled. To check whether a particular |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2687 | * package is currently registered as the device owner app, pass in the package name from |
| 2688 | * {@link Context#getPackageName()} to this method.<p/>This is useful for device |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2689 | * admin apps that want to check whether they are also registered as the device owner app. The |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2690 | * exact mechanism by which a device admin app is registered as a device owner app is defined by |
| 2691 | * the setup process. |
| 2692 | * @param packageName the package name of the app, to compare with the registered device owner |
| 2693 | * app, if any. |
| 2694 | * @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] | 2695 | */ |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2696 | public boolean isDeviceOwnerApp(String packageName) { |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2697 | if (mService != null) { |
| 2698 | try { |
| 2699 | return mService.isDeviceOwner(packageName); |
| 2700 | } catch (RemoteException re) { |
| 2701 | Log.w(TAG, "Failed to check device owner"); |
| 2702 | } |
| 2703 | } |
| 2704 | return false; |
| 2705 | } |
| 2706 | |
Amith Yamasani | 3b458ad | 2013-04-18 18:40:07 -0700 | [diff] [blame] | 2707 | /** |
| 2708 | * @hide |
| 2709 | * Redirect to isDeviceOwnerApp. |
| 2710 | */ |
| 2711 | public boolean isDeviceOwner(String packageName) { |
| 2712 | return isDeviceOwnerApp(packageName); |
| 2713 | } |
| 2714 | |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2715 | /** |
| 2716 | * Clears the current device owner. The caller must be the device owner. |
| 2717 | * |
| 2718 | * This function should be used cautiously as once it is called it cannot |
| 2719 | * be undone. The device owner can only be set as a part of device setup |
| 2720 | * before setup completes. |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2721 | * |
| 2722 | * @param packageName The package name of the device owner. |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2723 | */ |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2724 | public void clearDeviceOwnerApp(String packageName) { |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2725 | if (mService != null) { |
| 2726 | try { |
Jason Monk | 94d2cf9 | 2014-06-18 09:53:34 -0400 | [diff] [blame] | 2727 | mService.clearDeviceOwner(packageName); |
Jason Monk | b0dced8 | 2014-06-06 14:36:20 -0400 | [diff] [blame] | 2728 | } catch (RemoteException re) { |
| 2729 | Log.w(TAG, "Failed to clear device owner"); |
| 2730 | } |
| 2731 | } |
| 2732 | } |
| 2733 | |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2734 | /** @hide */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 2735 | @SystemApi |
Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2736 | public String getDeviceOwner() { |
| 2737 | if (mService != null) { |
| 2738 | try { |
| 2739 | return mService.getDeviceOwner(); |
| 2740 | } catch (RemoteException re) { |
| 2741 | Log.w(TAG, "Failed to get device owner"); |
| 2742 | } |
| 2743 | } |
| 2744 | return null; |
| 2745 | } |
Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2746 | |
| 2747 | /** @hide */ |
| 2748 | public String getDeviceOwnerName() { |
| 2749 | if (mService != null) { |
| 2750 | try { |
| 2751 | return mService.getDeviceOwnerName(); |
| 2752 | } catch (RemoteException re) { |
| 2753 | Log.w(TAG, "Failed to get device owner"); |
| 2754 | } |
| 2755 | } |
| 2756 | return null; |
| 2757 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2758 | |
| 2759 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2760 | * Sets the given component as the device initializer. The package must already be installed and |
| 2761 | * set as an active device administrator, and there must not be an existing device initializer, |
| 2762 | * for this call to succeed. This method can only be called by an app holding the |
| 2763 | * MANAGE_DEVICE_ADMINS permission before the device is provisioned or by a device owner app. A |
| 2764 | * device initializer app is granted device owner privileges during device initialization and |
| 2765 | * profile owner privileges during secondary user initialization. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2766 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or |
| 2767 | * {@code null} if not called by the device owner. |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2768 | * @param initializer Which {@link DeviceAdminReceiver} to make device initializer. |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 2769 | * @return whether the component was successfully registered as the device initializer. |
| 2770 | * @throws IllegalArgumentException if the componentname is null or invalid |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2771 | * @throws IllegalStateException if the caller is not device owner or the device has |
| 2772 | * already been provisioned or a device initializer already exists. |
| 2773 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2774 | public boolean setDeviceInitializer(@Nullable ComponentName admin, |
| 2775 | @NonNull ComponentName initializer) |
Julia Reynolds | 731051e | 2015-05-11 15:52:08 -0400 | [diff] [blame] | 2776 | throws IllegalArgumentException, IllegalStateException { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2777 | if (mService != null) { |
| 2778 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2779 | return mService.setDeviceInitializer(admin, initializer); |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2780 | } catch (RemoteException re) { |
| 2781 | Log.w(TAG, "Failed to set device initializer"); |
| 2782 | } |
| 2783 | } |
| 2784 | return false; |
| 2785 | } |
| 2786 | |
| 2787 | /** |
| 2788 | * Used to determine if a particular package has been registered as the device initializer. |
| 2789 | * |
| 2790 | * @param packageName the package name of the app, to compare with the registered device |
| 2791 | * initializer app, if any. |
| 2792 | * @return whether or not the caller is registered as the device initializer app. |
| 2793 | */ |
| 2794 | public boolean isDeviceInitializerApp(String packageName) { |
| 2795 | if (mService != null) { |
| 2796 | try { |
| 2797 | return mService.isDeviceInitializer(packageName); |
| 2798 | } catch (RemoteException re) { |
| 2799 | Log.w(TAG, "Failed to check device initializer"); |
| 2800 | } |
| 2801 | } |
| 2802 | return false; |
| 2803 | } |
| 2804 | |
| 2805 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2806 | * Removes the device initializer, so that it will not be invoked on user initialization for any |
| 2807 | * subsequently created users. This method can be called by either the device owner or device |
Julia Reynolds | 1c3754a | 2015-03-05 10:06:41 -0500 | [diff] [blame] | 2808 | * initializer itself. The caller must be an active administrator. |
| 2809 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2810 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2811 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2812 | public void clearDeviceInitializerApp(@NonNull ComponentName admin) { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2813 | if (mService != null) { |
| 2814 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2815 | mService.clearDeviceInitializer(admin); |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2816 | } catch (RemoteException re) { |
| 2817 | Log.w(TAG, "Failed to clear device initializer"); |
| 2818 | } |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | /** |
| 2823 | * @hide |
| 2824 | * Gets the device initializer of the system. |
| 2825 | * |
| 2826 | * @return the package name of the device initializer. |
| 2827 | */ |
| 2828 | @SystemApi |
| 2829 | public String getDeviceInitializerApp() { |
| 2830 | if (mService != null) { |
| 2831 | try { |
| 2832 | return mService.getDeviceInitializer(); |
| 2833 | } catch (RemoteException re) { |
| 2834 | Log.w(TAG, "Failed to get device initializer"); |
| 2835 | } |
| 2836 | } |
| 2837 | return null; |
| 2838 | } |
| 2839 | |
| 2840 | /** |
Julia Reynolds | eaafdf72 | 2015-04-02 08:49:47 -0400 | [diff] [blame] | 2841 | * @hide |
| 2842 | * Gets the device initializer component of the system. |
| 2843 | * |
| 2844 | * @return the component name of the device initializer. |
| 2845 | */ |
| 2846 | @SystemApi |
| 2847 | public ComponentName getDeviceInitializerComponent() { |
| 2848 | if (mService != null) { |
| 2849 | try { |
| 2850 | return mService.getDeviceInitializerComponent(); |
| 2851 | } catch (RemoteException re) { |
| 2852 | Log.w(TAG, "Failed to get device initializer"); |
| 2853 | } |
| 2854 | } |
| 2855 | return null; |
| 2856 | } |
| 2857 | |
| 2858 | |
| 2859 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2860 | * Sets the enabled state of the user. A user should be enabled only once it is ready to |
| 2861 | * be used. |
| 2862 | * |
| 2863 | * <p>Device initializer must call this method to mark the user as functional. |
| 2864 | * Only the device initializer agent can call this. |
| 2865 | * |
| 2866 | * <p>When the user is enabled, if the device initializer is not also the device owner, the |
| 2867 | * device initializer will no longer have elevated permissions to call methods in this class. |
| 2868 | * Additionally, it will be removed as an active administrator and its |
| 2869 | * {@link DeviceAdminReceiver} will be disabled. |
| 2870 | * |
| 2871 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2872 | * @return whether the user is now enabled. |
| 2873 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2874 | public boolean setUserEnabled(@NonNull ComponentName admin) { |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2875 | if (mService != null) { |
| 2876 | try { |
| 2877 | return mService.setUserEnabled(admin); |
| 2878 | } catch (RemoteException e) { |
| 2879 | Log.w(TAG, "Failed talking with device policy service", e); |
| 2880 | } |
| 2881 | } |
| 2882 | return false; |
| 2883 | } |
| 2884 | |
| 2885 | /** |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2886 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2887 | * @deprecated Use #ACTION_SET_PROFILE_OWNER |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2888 | * Sets the given component as an active admin and registers the package as the profile |
| 2889 | * owner for this user. The package must already be installed and there shouldn't be |
| 2890 | * an existing profile owner registered for this user. Also, this method must be called |
| 2891 | * before the user setup has been completed. |
| 2892 | * <p> |
| 2893 | * This method can only be called by system apps that hold MANAGE_USERS permission and |
| 2894 | * MANAGE_DEVICE_ADMINS permission. |
| 2895 | * @param admin The component to register as an active admin and profile owner. |
| 2896 | * @param ownerName The user-visible name of the entity that is managing this user. |
| 2897 | * @return whether the admin was successfully registered as the profile owner. |
| 2898 | * @throws IllegalArgumentException if packageName is null, the package isn't installed, or |
| 2899 | * the user has already been set up. |
| 2900 | */ |
Justin Morey | 80440cc | 2014-07-24 09:16:35 -0500 | [diff] [blame] | 2901 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2902 | public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName) |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2903 | throws IllegalArgumentException { |
| 2904 | if (mService != null) { |
| 2905 | try { |
| 2906 | final int myUserId = UserHandle.myUserId(); |
| 2907 | mService.setActiveAdmin(admin, false, myUserId); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2908 | return mService.setProfileOwner(admin, ownerName, myUserId); |
Amith Yamasani | aba4f1b | 2014-07-01 15:36:12 +0530 | [diff] [blame] | 2909 | } catch (RemoteException re) { |
| 2910 | Log.w(TAG, "Failed to set profile owner " + re); |
| 2911 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2912 | } |
| 2913 | } |
| 2914 | return false; |
| 2915 | } |
| 2916 | |
| 2917 | /** |
| 2918 | * @hide |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2919 | * Clears the active profile owner and removes all user restrictions. The caller must |
| 2920 | * be from the same package as the active profile owner for this user, otherwise a |
| 2921 | * SecurityException will be thrown. |
| 2922 | * |
| 2923 | * @param admin The component to remove as the profile owner. |
| 2924 | * @return |
| 2925 | */ |
| 2926 | @SystemApi |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2927 | public void clearProfileOwner(@NonNull ComponentName admin) { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2928 | if (mService != null) { |
| 2929 | try { |
| 2930 | mService.clearProfileOwner(admin); |
| 2931 | } catch (RemoteException re) { |
| 2932 | Log.w(TAG, "Failed to clear profile owner " + admin + re); |
| 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | /** |
Julia Reynolds | e925440 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 2938 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2939 | * Checks whether the user was already setup. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2940 | */ |
| 2941 | public boolean hasUserSetupCompleted() { |
| 2942 | if (mService != null) { |
| 2943 | try { |
| 2944 | return mService.hasUserSetupCompleted(); |
| 2945 | } catch (RemoteException re) { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2946 | Log.w(TAG, "Failed to check whether user setup has completed"); |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | return true; |
| 2950 | } |
| 2951 | |
| 2952 | /** |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2953 | * @hide |
| 2954 | * Sets the given component as the profile owner of the given user profile. The package must |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2955 | * already be installed. There must not already be a profile owner for this user. |
| 2956 | * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call |
| 2957 | * this method. |
| 2958 | * Calling this after the setup phase of the specified user has completed is allowed only if: |
| 2959 | * - the caller is SYSTEM_UID. |
| 2960 | * - or the caller is the shell uid, and there are no accounts on the specified user. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2961 | * @param admin the component name to be registered as profile owner. |
| 2962 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 2963 | * @param userHandle the userId to set the profile owner for. |
| 2964 | * @return whether the component was successfully registered as the profile owner. |
Nicolas Prevot | 2806374 | 2015-01-08 15:37:12 +0000 | [diff] [blame] | 2965 | * @throws IllegalArgumentException if admin is null, the package isn't installed, or the |
| 2966 | * preconditions mentioned are not met. |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2967 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2968 | public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName, |
Robin Lee | ddd553f | 2015-04-30 14:18:22 +0100 | [diff] [blame] | 2969 | int userHandle) throws IllegalArgumentException { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2970 | if (admin == null) { |
| 2971 | throw new NullPointerException("admin cannot be null"); |
| 2972 | } |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2973 | if (mService != null) { |
| 2974 | try { |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 2975 | if (ownerName == null) { |
| 2976 | ownerName = ""; |
| 2977 | } |
| 2978 | return mService.setProfileOwner(admin, ownerName, userHandle); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 2979 | } catch (RemoteException re) { |
| 2980 | Log.w(TAG, "Failed to set profile owner", re); |
| 2981 | throw new IllegalArgumentException("Couldn't set profile owner.", re); |
| 2982 | } |
| 2983 | } |
| 2984 | return false; |
| 2985 | } |
| 2986 | |
| 2987 | /** |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2988 | * Sets the enabled state of the profile. A profile should be enabled only once it is ready to |
| 2989 | * be used. Only the profile owner can call this. |
| 2990 | * |
Alexandra Gherghina | df35d57 | 2014-04-09 13:54:39 +0100 | [diff] [blame] | 2991 | * @see #isProfileOwnerApp |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2992 | * |
| 2993 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 2994 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 2995 | public void setProfileEnabled(@NonNull ComponentName admin) { |
Alexandra Gherghina | 512675b | 2014-04-02 11:23:54 +0100 | [diff] [blame] | 2996 | if (mService != null) { |
| 2997 | try { |
| 2998 | mService.setProfileEnabled(admin); |
| 2999 | } catch (RemoteException e) { |
| 3000 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3001 | } |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3006 | * Sets the name of the profile. In the device owner case it sets the name of the user |
| 3007 | * which it is called from. Only a profile owner or device owner can call this. If this is |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3008 | * never called by the profile or device owner, the name will be set to default values. |
| 3009 | * |
| 3010 | * @see #isProfileOwnerApp |
| 3011 | * @see #isDeviceOwnerApp |
| 3012 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3013 | * @param admin Which {@link DeviceAdminReceiver} this request is associate with. |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3014 | * @param profileName The name of the profile. |
| 3015 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3016 | public void setProfileName(@NonNull ComponentName admin, String profileName) { |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3017 | if (mService != null) { |
| 3018 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3019 | mService.setProfileName(admin, profileName); |
Fyodor Kupolov | 78f1314 | 2015-05-27 16:52:45 -0700 | [diff] [blame] | 3020 | } catch (RemoteException e) { |
| 3021 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3022 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3023 | } |
| 3024 | } |
Jessica Hummel | 1333ea1 | 2014-06-23 11:20:10 +0100 | [diff] [blame] | 3025 | |
| 3026 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3027 | * 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] | 3028 | * current user. A profile owner is a special device admin that has additional privileges |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3029 | * within the profile. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3030 | * |
| 3031 | * @param packageName The package name of the app to compare with the registered profile owner. |
| 3032 | * @return Whether or not the package is registered as the profile owner. |
| 3033 | */ |
| 3034 | public boolean isProfileOwnerApp(String packageName) { |
| 3035 | if (mService != null) { |
| 3036 | try { |
Nicolas Prevot | 90af6d7 | 2014-07-30 14:19:12 +0100 | [diff] [blame] | 3037 | ComponentName profileOwner = mService.getProfileOwner( |
| 3038 | Process.myUserHandle().getIdentifier()); |
| 3039 | return profileOwner != null |
| 3040 | && profileOwner.getPackageName().equals(packageName); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3041 | } catch (RemoteException re) { |
| 3042 | Log.w(TAG, "Failed to check profile owner"); |
| 3043 | } |
| 3044 | } |
| 3045 | return false; |
| 3046 | } |
| 3047 | |
| 3048 | /** |
| 3049 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3050 | * @return the packageName of the owner of the given user profile or {@code null} if no profile |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3051 | * owner has been set for that user. |
| 3052 | * @throws IllegalArgumentException if the userId is invalid. |
| 3053 | */ |
Nicolas Prevot | 465acf3 | 2014-08-06 17:03:25 +0100 | [diff] [blame] | 3054 | @SystemApi |
Amith Yamasani | bf3a946 | 2014-07-28 14:26:42 -0700 | [diff] [blame] | 3055 | public ComponentName getProfileOwner() throws IllegalArgumentException { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3056 | return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier()); |
| 3057 | } |
| 3058 | |
| 3059 | /** |
| 3060 | * @see #getProfileOwner() |
| 3061 | * @hide |
| 3062 | */ |
| 3063 | public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException { |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3064 | if (mService != null) { |
| 3065 | try { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3066 | return mService.getProfileOwner(userId); |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3067 | } catch (RemoteException re) { |
| 3068 | Log.w(TAG, "Failed to get profile owner"); |
| 3069 | throw new IllegalArgumentException( |
| 3070 | "Requested profile owner for invalid userId", re); |
| 3071 | } |
| 3072 | } |
| 3073 | return null; |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * @hide |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3078 | * @return the human readable name of the organisation associated with this DPM or {@code null} |
| 3079 | * if one is not set. |
Adam Connors | 776c555 | 2014-01-09 10:42:56 +0000 | [diff] [blame] | 3080 | * @throws IllegalArgumentException if the userId is invalid. |
| 3081 | */ |
| 3082 | public String getProfileOwnerName() throws IllegalArgumentException { |
| 3083 | if (mService != null) { |
| 3084 | try { |
| 3085 | return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier()); |
| 3086 | } catch (RemoteException re) { |
| 3087 | Log.w(TAG, "Failed to get profile owner"); |
| 3088 | throw new IllegalArgumentException( |
| 3089 | "Requested profile owner for invalid userId", re); |
| 3090 | } |
| 3091 | } |
| 3092 | return null; |
| 3093 | } |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3094 | |
| 3095 | /** |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3096 | * @hide |
| 3097 | * @param user The user for whom to fetch the profile owner name, if any. |
| 3098 | * @return the human readable name of the organisation associated with this profile owner or |
| 3099 | * null if one is not set. |
| 3100 | * @throws IllegalArgumentException if the userId is invalid. |
| 3101 | */ |
| 3102 | @SystemApi |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3103 | public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException { |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3104 | if (mService != null) { |
| 3105 | try { |
Selim Cinek | 24ac55e | 2014-08-27 12:51:45 +0200 | [diff] [blame] | 3106 | return mService.getProfileOwnerName(userId); |
Amith Yamasani | 38f836b | 2014-08-20 14:51:15 -0700 | [diff] [blame] | 3107 | } catch (RemoteException re) { |
| 3108 | Log.w(TAG, "Failed to get profile owner"); |
| 3109 | throw new IllegalArgumentException( |
| 3110 | "Requested profile owner for invalid userId", re); |
| 3111 | } |
| 3112 | } |
| 3113 | return null; |
| 3114 | } |
| 3115 | |
| 3116 | /** |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3117 | * Called by a profile owner or device owner to add a default intent handler activity for |
| 3118 | * intents that match a certain intent filter. This activity will remain the default intent |
| 3119 | * handler even if the set of potential event handlers for the intent filter changes and if |
| 3120 | * the intent preferences are reset. |
| 3121 | * |
| 3122 | * <p>The default disambiguation mechanism takes over if the activity is not installed |
| 3123 | * (anymore). When the activity is (re)installed, it is automatically reset as default |
| 3124 | * intent handler for the filter. |
| 3125 | * |
| 3126 | * <p>The calling device admin must be a profile owner or device owner. If it is not, a |
| 3127 | * security exception will be thrown. |
| 3128 | * |
| 3129 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3130 | * @param filter The IntentFilter for which a default handler is added. |
| 3131 | * @param activity The Activity that is added as default intent handler. |
| 3132 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3133 | public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter, |
| 3134 | @NonNull ComponentName activity) { |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3135 | if (mService != null) { |
| 3136 | try { |
| 3137 | mService.addPersistentPreferredActivity(admin, filter, activity); |
| 3138 | } catch (RemoteException e) { |
| 3139 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3140 | } |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * 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] | 3146 | * associated with the given package that were set by {@link #addPersistentPreferredActivity}. |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3147 | * |
| 3148 | * <p>The calling device admin must be a profile owner. If it is not, a security |
| 3149 | * exception will be thrown. |
| 3150 | * |
| 3151 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3152 | * @param packageName The name of the package for which preferences are removed. |
| 3153 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3154 | public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin, |
Sander Alewijnse | f475ca3 | 2014-02-17 15:13:58 +0000 | [diff] [blame] | 3155 | String packageName) { |
| 3156 | if (mService != null) { |
| 3157 | try { |
| 3158 | mService.clearPackagePersistentPreferredActivities(admin, packageName); |
| 3159 | } catch (RemoteException e) { |
| 3160 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3161 | } |
| 3162 | } |
| 3163 | } |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3164 | |
| 3165 | /** |
| 3166 | * Called by a profile or device owner to set the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3167 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3168 | * |
| 3169 | * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be |
Kenny Guy | d00cfc5 | 2014-09-18 16:24:31 +0100 | [diff] [blame] | 3170 | * boolean, int, String, or String[]. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3171 | * |
| 3172 | * <p>The application restrictions are only made visible to the target application and the |
| 3173 | * profile or device owner. |
| 3174 | * |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3175 | * <p>If the restrictions are not available yet, but may be applied in the near future, |
| 3176 | * the admin can notify the target application of that by adding |
| 3177 | * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter. |
| 3178 | * |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3179 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 3180 | * exception will be thrown. |
| 3181 | * |
| 3182 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3183 | * @param packageName The name of the package to update restricted settings for. |
| 3184 | * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new |
| 3185 | * set of active restrictions. |
Sander Alewijnse | 53d63dc | 2014-11-07 21:43:00 +0000 | [diff] [blame] | 3186 | * |
| 3187 | * @see UserManager#KEY_RESTRICTIONS_PENDING |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3188 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3189 | public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName, |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3190 | Bundle settings) { |
| 3191 | if (mService != null) { |
| 3192 | try { |
| 3193 | mService.setApplicationRestrictions(admin, packageName, settings); |
| 3194 | } catch (RemoteException e) { |
| 3195 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3196 | } |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3201 | * Sets a list of configuration features to enable for a TrustAgent component. This is meant |
| 3202 | * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all |
| 3203 | * trust agents but those enabled by this function call. If flag |
| 3204 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3205 | * |
| 3206 | * <p>The calling device admin must have requested |
| 3207 | * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3208 | * this method; if not, a security exception will be thrown. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3209 | * |
| 3210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3211 | * @param target Component name of the agent to be enabled. |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3212 | * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3213 | * will be strictly disabled according to the state of the |
| 3214 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag. |
| 3215 | * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins, |
| 3216 | * then it's up to the TrustAgent itself to aggregate the values from all device admins. |
| 3217 | * <p>Consult documentation for the specific TrustAgent to determine legal options parameters. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3218 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3219 | public void setTrustAgentConfiguration(@NonNull ComponentName admin, |
| 3220 | @NonNull ComponentName target, PersistableBundle configuration) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3221 | if (mService != null) { |
| 3222 | try { |
Fyodor Kupolov | bdc58c6 | 2015-01-29 13:24:03 -0800 | [diff] [blame] | 3223 | mService.setTrustAgentConfiguration(admin, target, configuration); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3224 | } catch (RemoteException e) { |
| 3225 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3226 | } |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | /** |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3231 | * Gets configuration for the given trust agent based on aggregating all calls to |
| 3232 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for |
| 3233 | * all device admins. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3234 | * |
Jim Miller | b5db57a | 2015-01-14 18:17:19 -0800 | [diff] [blame] | 3235 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null, |
| 3236 | * this function returns a list of configurations for all admins that declare |
| 3237 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares |
| 3238 | * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call |
| 3239 | * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} |
| 3240 | * for this {@param agent} or calls it with a null configuration, null is returned. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3241 | * @param agent Which component to get enabled features for. |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3242 | * @return configuration for the given trust agent. |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3243 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3244 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3245 | @NonNull ComponentName agent) { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3246 | return getTrustAgentConfiguration(admin, agent, UserHandle.myUserId()); |
| 3247 | } |
| 3248 | |
| 3249 | /** @hide per-user version */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3250 | public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin, |
| 3251 | @NonNull ComponentName agent, int userHandle) { |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3252 | if (mService != null) { |
| 3253 | try { |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3254 | return mService.getTrustAgentConfiguration(admin, agent, userHandle); |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3255 | } catch (RemoteException e) { |
| 3256 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3257 | } |
| 3258 | } |
Jim Miller | e303bf4 | 2014-08-26 17:12:29 -0700 | [diff] [blame] | 3259 | return new ArrayList<PersistableBundle>(); // empty list |
Jim Miller | 604e755 | 2014-07-18 19:00:02 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3263 | * Called by a profile owner of a managed profile to set whether caller-Id information from |
| 3264 | * the managed profile will be shown in the parent profile, for incoming calls. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3265 | * |
| 3266 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3267 | * security exception will be thrown. |
| 3268 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3269 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3270 | * @param disabled If true caller-Id information in the managed profile is not displayed. |
| 3271 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3272 | public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3273 | if (mService != null) { |
| 3274 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3275 | mService.setCrossProfileCallerIdDisabled(admin, disabled); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3276 | } catch (RemoteException e) { |
| 3277 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3278 | } |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3283 | * Called by a profile owner of a managed profile to determine whether or not caller-Id |
| 3284 | * information has been disabled. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3285 | * |
| 3286 | * <p>The calling device admin must be a profile owner. If it is not, a |
| 3287 | * security exception will be thrown. |
| 3288 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3289 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3290 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3291 | public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) { |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3292 | if (mService != null) { |
| 3293 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3294 | return mService.getCrossProfileCallerIdDisabled(admin); |
Adam Connors | 210fe21 | 2014-07-17 15:41:43 +0100 | [diff] [blame] | 3295 | } catch (RemoteException e) { |
| 3296 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3297 | } |
| 3298 | } |
| 3299 | return false; |
| 3300 | } |
| 3301 | |
| 3302 | /** |
Amith Yamasani | 570002f | 2014-07-18 15:48:54 -0700 | [diff] [blame] | 3303 | * Determine whether or not caller-Id information has been disabled. |
| 3304 | * |
| 3305 | * @param userHandle The user for whom to check the caller-id permission |
| 3306 | * @hide |
| 3307 | */ |
| 3308 | public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) { |
| 3309 | if (mService != null) { |
| 3310 | try { |
| 3311 | return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier()); |
| 3312 | } catch (RemoteException e) { |
| 3313 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3314 | } |
| 3315 | } |
| 3316 | return false; |
| 3317 | } |
| 3318 | |
| 3319 | /** |
Makoto Onuki | 1040da1 | 2015-03-19 11:24:00 -0700 | [diff] [blame] | 3320 | * Start Quick Contact on the managed profile for the current user, if the policy allows. |
| 3321 | * @hide |
| 3322 | */ |
| 3323 | public void startManagedQuickContact(String actualLookupKey, long actualContactId, |
| 3324 | Intent originalIntent) { |
| 3325 | if (mService != null) { |
| 3326 | try { |
| 3327 | mService.startManagedQuickContact( |
| 3328 | actualLookupKey, actualContactId, originalIntent); |
| 3329 | } catch (RemoteException e) { |
| 3330 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3331 | } |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | /** |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3336 | * Called by a profile owner of a managed profile to set whether bluetooth |
| 3337 | * devices can access enterprise contacts. |
| 3338 | * <p> |
| 3339 | * The calling device admin must be a profile owner. If it is not, a |
| 3340 | * security exception will be thrown. |
| 3341 | * <p> |
| 3342 | * This API works on managed profile only. |
| 3343 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3344 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3345 | * with. |
| 3346 | * @param disabled If true, bluetooth devices cannot access enterprise |
| 3347 | * contacts. |
| 3348 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3349 | public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3350 | if (mService != null) { |
| 3351 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3352 | mService.setBluetoothContactSharingDisabled(admin, disabled); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3353 | } catch (RemoteException e) { |
| 3354 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3355 | } |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | /** |
| 3360 | * Called by a profile owner of a managed profile to determine whether or |
| 3361 | * not Bluetooth devices cannot access enterprise contacts. |
| 3362 | * <p> |
| 3363 | * The calling device admin must be a profile owner. If it is not, a |
| 3364 | * security exception will be thrown. |
| 3365 | * <p> |
| 3366 | * This API works on managed profile only. |
| 3367 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3368 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3369 | * with. |
| 3370 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3371 | public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) { |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3372 | if (mService != null) { |
| 3373 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3374 | return mService.getBluetoothContactSharingDisabled(admin); |
Ricky Wai | 778ba13 | 2015-03-31 14:21:22 +0100 | [diff] [blame] | 3375 | } catch (RemoteException e) { |
| 3376 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3377 | } |
| 3378 | } |
| 3379 | return true; |
| 3380 | } |
| 3381 | |
| 3382 | /** |
| 3383 | * Determine whether or not Bluetooth devices cannot access contacts. |
| 3384 | * <p> |
| 3385 | * This API works on managed profile UserHandle only. |
| 3386 | * |
| 3387 | * @param userHandle The user for whom to check the caller-id permission |
| 3388 | * @hide |
| 3389 | */ |
| 3390 | public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) { |
| 3391 | if (mService != null) { |
| 3392 | try { |
| 3393 | return mService.getBluetoothContactSharingDisabledForUser(userHandle |
| 3394 | .getIdentifier()); |
| 3395 | } catch (RemoteException e) { |
| 3396 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3397 | } |
| 3398 | } |
| 3399 | return true; |
| 3400 | } |
| 3401 | |
| 3402 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3403 | * Called by the profile owner of a managed profile so that some intents sent in the managed |
| 3404 | * profile can also be resolved in the parent, or vice versa. |
Nicolas Prevot | fc7b444 | 2014-12-17 15:28:29 +0000 | [diff] [blame] | 3405 | * Only activity intents are supported. |
| 3406 | * |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3407 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3408 | * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the |
| 3409 | * other profile |
Nicolas Prevot | 41d926e | 2014-06-09 11:48:56 +0100 | [diff] [blame] | 3410 | * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and |
| 3411 | * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3412 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3413 | public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3414 | if (mService != null) { |
| 3415 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3416 | mService.addCrossProfileIntentFilter(admin, filter, flags); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3417 | } catch (RemoteException e) { |
| 3418 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3424 | * Called by a profile owner of a managed profile to remove the cross-profile intent filters |
| 3425 | * that go from the managed profile to the parent, or from the parent to the managed profile. |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 3426 | * Only removes those that have been set by the profile owner. |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3427 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3428 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3429 | public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) { |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3430 | if (mService != null) { |
| 3431 | try { |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 3432 | mService.clearCrossProfileIntentFilters(admin); |
Nicolas Prevot | 10fa67c | 2014-03-24 13:44:38 +0000 | [diff] [blame] | 3433 | } catch (RemoteException e) { |
| 3434 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | |
| 3439 | /** |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3440 | * Called by a profile or device owner to set the permitted accessibility services. When |
| 3441 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 3442 | * user the device owner or profile owner is an admin for. |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 3443 | * |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3444 | * By default the user can use any accessiblity service. When zero or more packages have |
| 3445 | * been added, accessiblity services that are not in the list and not part of the system |
Jim Miller | b1474f4 | 2014-08-26 18:42:58 -0700 | [diff] [blame] | 3446 | * can not be enabled by the user. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3447 | * |
| 3448 | * <p> Calling with a null value for the list disables the restriction so that all services |
| 3449 | * can be used, calling with an empty list only allows the builtin system's services. |
| 3450 | * |
| 3451 | * <p> System accesibility services are always available to the user the list can't modify |
| 3452 | * this. |
| 3453 | * |
| 3454 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3455 | * @param packageNames List of accessibility service package names. |
| 3456 | * |
| 3457 | * @return true if setting the restriction succeeded. It fail if there is |
| 3458 | * one or more non-system accessibility services enabled, that are not in the list. |
| 3459 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3460 | public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin, |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3461 | List<String> packageNames) { |
| 3462 | if (mService != null) { |
| 3463 | try { |
| 3464 | return mService.setPermittedAccessibilityServices(admin, packageNames); |
| 3465 | } catch (RemoteException e) { |
| 3466 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3467 | } |
| 3468 | } |
| 3469 | return false; |
| 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * Returns the list of permitted accessibility services set by this device or profile owner. |
| 3474 | * |
| 3475 | * <p>An empty list means no accessibility services except system services are allowed. |
| 3476 | * Null means all accessibility services are allowed. |
| 3477 | * |
| 3478 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3479 | * @return List of accessiblity service package names. |
| 3480 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3481 | public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3482 | if (mService != null) { |
| 3483 | try { |
| 3484 | return mService.getPermittedAccessibilityServices(admin); |
| 3485 | } catch (RemoteException e) { |
| 3486 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3487 | } |
| 3488 | } |
| 3489 | return null; |
| 3490 | } |
| 3491 | |
| 3492 | /** |
| 3493 | * Returns the list of accessibility services permitted by the device or profiles |
| 3494 | * owners of this user. |
| 3495 | * |
| 3496 | * <p>Null means all accessibility services are allowed, if a non-null list is returned |
| 3497 | * it will contain the intersection of the permitted lists for any device or profile |
| 3498 | * owners that apply to this user. It will also include any system accessibility services. |
| 3499 | * |
| 3500 | * @param userId which user to check for. |
| 3501 | * @return List of accessiblity service package names. |
| 3502 | * @hide |
| 3503 | */ |
| 3504 | @SystemApi |
| 3505 | public List<String> getPermittedAccessibilityServices(int userId) { |
| 3506 | if (mService != null) { |
| 3507 | try { |
| 3508 | return mService.getPermittedAccessibilityServicesForUser(userId); |
| 3509 | } catch (RemoteException e) { |
| 3510 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3511 | } |
| 3512 | } |
| 3513 | return null; |
| 3514 | } |
| 3515 | |
| 3516 | /** |
| 3517 | * Called by a profile or device owner to set the permitted input methods services. When |
| 3518 | * set by a device owner or profile owner the restriction applies to all profiles of the |
| 3519 | * user the device owner or profile owner is an admin for. |
| 3520 | * |
| 3521 | * By default the user can use any input method. When zero or more packages have |
| 3522 | * been added, input method that are not in the list and not part of the system |
| 3523 | * can not be enabled by the user. |
| 3524 | * |
| 3525 | * This method will fail if it is called for a admin that is not for the foreground user |
| 3526 | * or a profile of the foreground user. |
| 3527 | * |
| 3528 | * <p> Calling with a null value for the list disables the restriction so that all input methods |
| 3529 | * can be used, calling with an empty list disables all but the system's own input methods. |
| 3530 | * |
| 3531 | * <p> System input methods are always available to the user this method can't modify this. |
| 3532 | * |
| 3533 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3534 | * @param packageNames List of input method package names. |
Kenny Guy | 74a7024 | 2015-02-05 19:48:38 +0000 | [diff] [blame] | 3535 | * @return true if setting the restriction succeeded. It will fail if there are |
| 3536 | * one or more non-system input methods currently enabled that are not in |
| 3537 | * the packageNames list. |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3538 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3539 | public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3540 | if (mService != null) { |
| 3541 | try { |
| 3542 | return mService.setPermittedInputMethods(admin, packageNames); |
| 3543 | } catch (RemoteException e) { |
| 3544 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3545 | } |
| 3546 | } |
| 3547 | return false; |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | /** |
| 3552 | * Returns the list of permitted input methods set by this device or profile owner. |
| 3553 | * |
| 3554 | * <p>An empty list means no input methods except system input methods are allowed. |
| 3555 | * Null means all input methods are allowed. |
| 3556 | * |
| 3557 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3558 | * @return List of input method package names. |
| 3559 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3560 | public List<String> getPermittedInputMethods(@NonNull ComponentName admin) { |
Kenny Guy | fa80a4f | 2014-08-20 19:40:59 +0100 | [diff] [blame] | 3561 | if (mService != null) { |
| 3562 | try { |
| 3563 | return mService.getPermittedInputMethods(admin); |
| 3564 | } catch (RemoteException e) { |
| 3565 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3566 | } |
| 3567 | } |
| 3568 | return null; |
| 3569 | } |
| 3570 | |
| 3571 | /** |
| 3572 | * Returns the list of input methods permitted by the device or profiles |
| 3573 | * owners of the current user. |
| 3574 | * |
| 3575 | * <p>Null means all input methods are allowed, if a non-null list is returned |
| 3576 | * it will contain the intersection of the permitted lists for any device or profile |
| 3577 | * owners that apply to this user. It will also include any system input methods. |
| 3578 | * |
| 3579 | * @return List of input method package names. |
| 3580 | * @hide |
| 3581 | */ |
| 3582 | @SystemApi |
| 3583 | public List<String> getPermittedInputMethodsForCurrentUser() { |
| 3584 | if (mService != null) { |
| 3585 | try { |
| 3586 | return mService.getPermittedInputMethodsForCurrentUser(); |
| 3587 | } catch (RemoteException e) { |
| 3588 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3589 | } |
| 3590 | } |
| 3591 | return null; |
| 3592 | } |
| 3593 | |
| 3594 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3595 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 3596 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 3597 | * created. If you need to persist an identifier for this user, use |
| 3598 | * {@link UserManager#getSerialNumberForUser}. |
| 3599 | * |
| 3600 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3601 | * @param name the user's name |
| 3602 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3603 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 3604 | * user could not be created. |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3605 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3606 | public UserHandle createUser(@NonNull ComponentName admin, String name) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3607 | try { |
| 3608 | return mService.createUser(admin, name); |
| 3609 | } catch (RemoteException re) { |
| 3610 | Log.w(TAG, "Could not create a user", re); |
| 3611 | } |
| 3612 | return null; |
| 3613 | } |
| 3614 | |
| 3615 | /** |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 3616 | * Called by a device owner to create a user with the specified name. The UserHandle returned |
| 3617 | * by this method should not be persisted as user handles are recycled as users are removed and |
| 3618 | * created. If you need to persist an identifier for this user, use |
| 3619 | * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background |
| 3620 | * immediately. |
| 3621 | * |
| 3622 | * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well |
| 3623 | * as registered as an active admin on the new user. The profile owner package will be |
| 3624 | * installed on the new user if it already is installed on the device. |
| 3625 | * |
| 3626 | * <p>If the optionalInitializeData is not null, then the extras will be passed to the |
| 3627 | * profileOwnerComponent when onEnable is called. |
| 3628 | * |
| 3629 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3630 | * @param name the user's name |
| 3631 | * @param ownerName the human readable name of the organisation associated with this DPM. |
| 3632 | * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on |
| 3633 | * the user. |
| 3634 | * @param adminExtras Extras that will be passed to onEnable of the admin receiver |
| 3635 | * on the new user. |
| 3636 | * @see UserHandle |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3637 | * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the |
| 3638 | * user could not be created. |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 3639 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3640 | public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name, |
| 3641 | String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) { |
Jason Monk | 03978a4 | 2014-06-10 15:05:30 -0400 | [diff] [blame] | 3642 | try { |
| 3643 | return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent, |
| 3644 | adminExtras); |
| 3645 | } catch (RemoteException re) { |
| 3646 | Log.w(TAG, "Could not create a user", re); |
| 3647 | } |
| 3648 | return null; |
| 3649 | } |
| 3650 | |
| 3651 | /** |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3652 | * Called by a device owner to remove a user and all associated data. The primary user can |
| 3653 | * not be removed. |
| 3654 | * |
| 3655 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3656 | * @param userHandle the user to remove. |
| 3657 | * @return {@code true} if the user was removed, {@code false} otherwise. |
| 3658 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3659 | public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) { |
Julia Reynolds | 1e95839 | 2014-05-16 14:25:21 -0400 | [diff] [blame] | 3660 | try { |
| 3661 | return mService.removeUser(admin, userHandle); |
| 3662 | } catch (RemoteException re) { |
| 3663 | Log.w(TAG, "Could not remove user ", re); |
| 3664 | return false; |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | /** |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 3669 | * Called by a device owner to switch the specified user to the foreground. |
| 3670 | * |
| 3671 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3672 | * @param userHandle the user to switch to; null will switch to primary. |
| 3673 | * @return {@code true} if the switch was successful, {@code false} otherwise. |
| 3674 | * |
| 3675 | * @see Intent#ACTION_USER_FOREGROUND |
| 3676 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3677 | public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) { |
Jason Monk | 582d911 | 2014-07-09 19:57:08 -0400 | [diff] [blame] | 3678 | try { |
| 3679 | return mService.switchUser(admin, userHandle); |
| 3680 | } catch (RemoteException re) { |
| 3681 | Log.w(TAG, "Could not switch user ", re); |
| 3682 | return false; |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | /** |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3687 | * Called by a profile or device owner to get the application restrictions for a given target |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3688 | * application running in the profile. |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3689 | * |
| 3690 | * <p>The calling device admin must be a profile or device owner; if it is not, a security |
| 3691 | * exception will be thrown. |
| 3692 | * |
| 3693 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3694 | * @param packageName The name of the package to fetch restricted settings of. |
| 3695 | * @return {@link Bundle} of settings corresponding to what was set last time |
| 3696 | * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle} |
| 3697 | * if no restrictions have been set. |
| 3698 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3699 | public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) { |
Robin Lee | 66e5d96 | 2014-04-09 16:44:21 +0100 | [diff] [blame] | 3700 | if (mService != null) { |
| 3701 | try { |
| 3702 | return mService.getApplicationRestrictions(admin, packageName); |
| 3703 | } catch (RemoteException e) { |
| 3704 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3705 | } |
| 3706 | } |
| 3707 | return null; |
| 3708 | } |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3709 | |
| 3710 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3711 | * Called by a profile or device owner to set a user restriction specified by the key. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3712 | * <p> |
| 3713 | * The calling device admin must be a profile or device owner; if it is not, |
| 3714 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3715 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3716 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3717 | * with. |
| 3718 | * @param key The key of the restriction. See the constants in |
| 3719 | * {@link android.os.UserManager} for the list of keys. |
| 3720 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3721 | public void addUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3722 | if (mService != null) { |
| 3723 | try { |
| 3724 | mService.setUserRestriction(admin, key, true); |
| 3725 | } catch (RemoteException e) { |
| 3726 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3727 | } |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3732 | * Called by a profile or device owner to clear a user restriction specified by the key. |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3733 | * <p> |
| 3734 | * The calling device admin must be a profile or device owner; if it is not, |
| 3735 | * a security exception will be thrown. |
Jim Miller | df2258b | 2014-04-27 20:10:26 -0700 | [diff] [blame] | 3736 | * |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3737 | * @param admin Which {@link DeviceAdminReceiver} this request is associated |
| 3738 | * with. |
| 3739 | * @param key The key of the restriction. See the constants in |
| 3740 | * {@link android.os.UserManager} for the list of keys. |
| 3741 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3742 | public void clearUserRestriction(@NonNull ComponentName admin, String key) { |
Amith Yamasani | be46532 | 2014-04-24 13:45:17 -0700 | [diff] [blame] | 3743 | if (mService != null) { |
| 3744 | try { |
| 3745 | mService.setUserRestriction(admin, key, false); |
| 3746 | } catch (RemoteException e) { |
| 3747 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3748 | } |
| 3749 | } |
| 3750 | } |
Adam Connors | 010cfd4 | 2014-04-16 12:48:13 +0100 | [diff] [blame] | 3751 | |
| 3752 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3753 | * Called by profile or device owners to hide or unhide packages. When a package is hidden it |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3754 | * is unavailable for use, but the data and actual package file remain. |
| 3755 | * |
| 3756 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3757 | * @param packageName The name of the package to hide or unhide. |
| 3758 | * @param hidden {@code true} if the package should be hidden, {@code false} if it should be |
| 3759 | * unhidden. |
| 3760 | * @return boolean Whether the hidden setting of the package was successfully updated. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3761 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3762 | public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3763 | boolean hidden) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3764 | if (mService != null) { |
| 3765 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3766 | return mService.setApplicationHidden(admin, packageName, hidden); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3767 | } catch (RemoteException e) { |
| 3768 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3769 | } |
| 3770 | } |
| 3771 | return false; |
| 3772 | } |
| 3773 | |
| 3774 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3775 | * Called by profile or device owners to determine if a package is hidden. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3776 | * |
| 3777 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3778 | * @param packageName The name of the package to retrieve the hidden status of. |
| 3779 | * @return boolean {@code true} if the package is hidden, {@code false} otherwise. |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3780 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3781 | public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) { |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3782 | if (mService != null) { |
| 3783 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 3784 | return mService.isApplicationHidden(admin, packageName); |
Julia Reynolds | 966881e | 2014-05-14 12:23:08 -0400 | [diff] [blame] | 3785 | } catch (RemoteException e) { |
| 3786 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3787 | } |
| 3788 | } |
| 3789 | return false; |
| 3790 | } |
| 3791 | |
| 3792 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3793 | * Called by profile or device owners to re-enable a system app that was disabled by default |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3794 | * when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3795 | * |
| 3796 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3797 | * @param packageName The package to be re-enabled in the current profile. |
| 3798 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3799 | public void enableSystemApp(@NonNull ComponentName admin, String packageName) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3800 | if (mService != null) { |
| 3801 | try { |
| 3802 | mService.enableSystemApp(admin, packageName); |
| 3803 | } catch (RemoteException e) { |
| 3804 | Log.w(TAG, "Failed to install package: " + packageName); |
| 3805 | } |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | /** |
Julia Reynolds | 20118f1 | 2015-02-11 12:34:08 -0500 | [diff] [blame] | 3810 | * Called by profile or device owners to re-enable system apps by intent that were disabled |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 3811 | * by default when the user was initialized. |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3812 | * |
| 3813 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3814 | * @param intent An intent matching the app(s) to be installed. All apps that resolve for this |
| 3815 | * intent will be re-enabled in the current profile. |
| 3816 | * @return int The number of activities that matched the intent and were installed. |
| 3817 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3818 | public int enableSystemApp(@NonNull ComponentName admin, Intent intent) { |
Adam Connors | 655be2a | 2014-07-14 09:01:25 +0000 | [diff] [blame] | 3819 | if (mService != null) { |
| 3820 | try { |
| 3821 | return mService.enableSystemAppWithIntent(admin, intent); |
| 3822 | } catch (RemoteException e) { |
| 3823 | Log.w(TAG, "Failed to install packages matching filter: " + intent); |
| 3824 | } |
| 3825 | } |
| 3826 | return 0; |
| 3827 | } |
| 3828 | |
| 3829 | /** |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3830 | * Called by a device owner or profile owner to disable account management for a specific type |
| 3831 | * of account. |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3832 | * |
Sander Alewijnse | 112e053 | 2014-10-29 13:28:49 +0000 | [diff] [blame] | 3833 | * <p>The calling device admin must be a device owner or profile owner. If it is not, a |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3834 | * security exception will be thrown. |
| 3835 | * |
| 3836 | * <p>When account management is disabled for an account type, adding or removing an account |
| 3837 | * of that type will not be possible. |
| 3838 | * |
| 3839 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3840 | * @param accountType For which account management is disabled or enabled. |
| 3841 | * @param disabled The boolean indicating that account management will be disabled (true) or |
| 3842 | * enabled (false). |
| 3843 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3844 | public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType, |
Sander Alewijnse | 650c334 | 2014-05-08 18:00:50 +0100 | [diff] [blame] | 3845 | boolean disabled) { |
| 3846 | if (mService != null) { |
| 3847 | try { |
| 3848 | mService.setAccountManagementDisabled(admin, accountType, disabled); |
| 3849 | } catch (RemoteException e) { |
| 3850 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3851 | } |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | /** |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3856 | * Gets the array of accounts for which account management is disabled by the profile owner. |
| 3857 | * |
| 3858 | * <p> Account management can be disabled/enabled by calling |
| 3859 | * {@link #setAccountManagementDisabled}. |
| 3860 | * |
| 3861 | * @return a list of account types for which account management has been disabled. |
| 3862 | * |
| 3863 | * @see #setAccountManagementDisabled |
| 3864 | */ |
| 3865 | public String[] getAccountTypesWithManagementDisabled() { |
Zoltan Szatmary-Ban | 3f1ddf8 | 2014-07-02 16:42:05 +0100 | [diff] [blame] | 3866 | return getAccountTypesWithManagementDisabledAsUser(UserHandle.myUserId()); |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * @see #getAccountTypesWithManagementDisabled() |
| 3871 | * @hide |
| 3872 | */ |
| 3873 | public String[] getAccountTypesWithManagementDisabledAsUser(int userId) { |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3874 | if (mService != null) { |
| 3875 | try { |
Alexandra Gherghina | 999d394 | 2014-07-03 11:40:08 +0100 | [diff] [blame] | 3876 | return mService.getAccountTypesWithManagementDisabledAsUser(userId); |
Sander Alewijnse | 5c02db6 | 2014-05-07 10:46:57 +0100 | [diff] [blame] | 3877 | } catch (RemoteException e) { |
| 3878 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | return null; |
| 3883 | } |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3884 | |
| 3885 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3886 | * Sets which packages may enter lock task mode. |
| 3887 | * |
| 3888 | * <p>Any packages that shares uid with an allowed package will also be allowed |
| 3889 | * to activate lock task. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3890 | * |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 3891 | * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task |
| 3892 | * package list results in locked tasks belonging to those packages to be finished. |
| 3893 | * |
Jason Monk | c5185f2 | 2014-06-24 11:12:42 -0400 | [diff] [blame] | 3894 | * This function can only be called by the device owner. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3895 | * @param packages The list of packages allowed to enter lock task mode |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3896 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3897 | * |
| 3898 | * @see Activity#startLockTask() |
Benjamin Franz | 6cdb27e | 2015-02-26 12:26:53 +0000 | [diff] [blame] | 3899 | * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String) |
| 3900 | * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent) |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 3901 | * @see UserManager#DISALLOW_CREATE_WINDOWS |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3902 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3903 | public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages) |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3904 | throws SecurityException { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3905 | if (mService != null) { |
| 3906 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3907 | mService.setLockTaskPackages(admin, packages); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3908 | } catch (RemoteException e) { |
| 3909 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3910 | } |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | /** |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3915 | * 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] | 3916 | * |
| 3917 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3918 | * @hide |
| 3919 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3920 | public String[] getLockTaskPackages(@NonNull ComponentName admin) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3921 | if (mService != null) { |
| 3922 | try { |
Jason Monk | 48aacba | 2014-08-13 16:29:08 -0400 | [diff] [blame] | 3923 | return mService.getLockTaskPackages(admin); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3924 | } catch (RemoteException e) { |
| 3925 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3926 | } |
| 3927 | } |
| 3928 | return null; |
| 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * This function lets the caller know whether the given component is allowed to start the |
| 3933 | * lock task mode. |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3934 | * @param pkg The package to check |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3935 | */ |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3936 | public boolean isLockTaskPermitted(String pkg) { |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3937 | if (mService != null) { |
| 3938 | try { |
Jason Monk | d7b8621 | 2014-06-16 13:15:38 -0400 | [diff] [blame] | 3939 | return mService.isLockTaskPermitted(pkg); |
justinzhang | 511e0d8 | 2014-03-24 16:09:24 -0400 | [diff] [blame] | 3940 | } catch (RemoteException e) { |
| 3941 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3942 | } |
| 3943 | } |
| 3944 | return false; |
| 3945 | } |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3946 | |
| 3947 | /** |
| 3948 | * Called by device owners to update {@link Settings.Global} settings. Validation that the value |
| 3949 | * of the setting is in the correct form for the setting type should be performed by the caller. |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3950 | * <p>The settings that can be updated with this method are: |
| 3951 | * <ul> |
| 3952 | * <li>{@link Settings.Global#ADB_ENABLED}</li> |
| 3953 | * <li>{@link Settings.Global#AUTO_TIME}</li> |
| 3954 | * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li> |
Nicolas Prevot | 41916d4 | 2015-02-24 18:41:50 +0000 | [diff] [blame] | 3955 | * <li>{@link Settings.Global#BLUETOOTH_ON} |
| 3956 | * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use |
| 3957 | * {@link android.bluetooth.BluetoothAdapter#enable()} and |
| 3958 | * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3959 | * <li>{@link Settings.Global#DATA_ROAMING}</li> |
| 3960 | * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li> |
| 3961 | * <li>{@link Settings.Global#MODE_RINGER}</li> |
| 3962 | * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li> |
| 3963 | * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li> |
Nicolas Prevot | 41916d4 | 2015-02-24 18:41:50 +0000 | [diff] [blame] | 3964 | * <li>{@link Settings.Global#WIFI_ON} |
| 3965 | * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use |
| 3966 | * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3967 | * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li> |
Benjamin Franz | 68cc420 | 2015-03-11 15:43:06 +0000 | [diff] [blame] | 3968 | * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} |
| 3969 | * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards |
| 3970 | * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3971 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3972 | * |
| 3973 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 3974 | * @param setting The name of the setting to update. |
| 3975 | * @param value The value to update the setting to. |
| 3976 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 3977 | public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 3978 | if (mService != null) { |
| 3979 | try { |
| 3980 | mService.setGlobalSetting(admin, setting, value); |
| 3981 | } catch (RemoteException e) { |
| 3982 | Log.w(TAG, "Failed talking with device policy service", e); |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | /** |
| 3988 | * Called by profile or device owners to update {@link Settings.Secure} settings. Validation |
| 3989 | * that the value of the setting is in the correct form for the setting type should be performed |
| 3990 | * by the caller. |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3991 | * <p>The settings that can be updated by a profile or device owner with this method are: |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3992 | * <ul> |
| 3993 | * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li> |
Amith Yamasani | 52c39a1 | 2014-10-21 11:14:04 -0700 | [diff] [blame] | 3994 | * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li> |
Julia Reynolds | 9ed66da | 2014-08-26 15:42:03 -0400 | [diff] [blame] | 3995 | * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li> |
| 3996 | * </ul> |
Julia Reynolds | 82735bc | 2014-09-04 16:43:30 -0400 | [diff] [blame] | 3997 | * <p>A device owner can additionally update the following settings: |
| 3998 | * <ul> |
| 3999 | * <li>{@link Settings.Secure#LOCATION_MODE}</li> |
| 4000 | * </ul> |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4001 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4002 | * @param setting The name of the setting to update. |
| 4003 | * @param value The value to update the setting to. |
| 4004 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4005 | public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) { |
Julia Reynolds | da55165 | 2014-05-14 17:15:16 -0400 | [diff] [blame] | 4006 | if (mService != null) { |
| 4007 | try { |
| 4008 | mService.setSecureSetting(admin, setting, value); |
| 4009 | } catch (RemoteException e) { |
| 4010 | Log.w(TAG, "Failed talking with device policy service", e); |
| 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4015 | /** |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4016 | * Designates a specific service component as the provider for |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4017 | * making permission requests of a local or remote administrator of the user. |
| 4018 | * <p/> |
| 4019 | * Only a profile owner can designate the restrictions provider. |
| 4020 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4021 | * @param provider The component name of the service that implements |
Amith Yamasani | d1d7c02 | 2014-08-19 17:03:41 -0700 | [diff] [blame] | 4022 | * {@link RestrictionsReceiver}. If this param is null, |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4023 | * it removes the restrictions provider previously assigned. |
| 4024 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4025 | public void setRestrictionsProvider(@NonNull ComponentName admin, |
| 4026 | @Nullable ComponentName provider) { |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4027 | if (mService != null) { |
| 4028 | try { |
Amith Yamasani | f6e2fcc | 2014-07-10 13:41:55 -0700 | [diff] [blame] | 4029 | mService.setRestrictionsProvider(admin, provider); |
Amith Yamasani | f20d640 | 2014-05-24 15:34:37 -0700 | [diff] [blame] | 4030 | } catch (RemoteException re) { |
| 4031 | Log.w(TAG, "Failed to set permission provider on device policy service"); |
| 4032 | } |
| 4033 | } |
| 4034 | } |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4035 | |
| 4036 | /** |
| 4037 | * Called by profile or device owners to set the master volume mute on or off. |
| 4038 | * |
| 4039 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4040 | * @param on {@code true} to mute master volume, {@code false} to turn mute off. |
| 4041 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4042 | public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4043 | if (mService != null) { |
| 4044 | try { |
| 4045 | mService.setMasterVolumeMuted(admin, on); |
| 4046 | } catch (RemoteException re) { |
| 4047 | Log.w(TAG, "Failed to setMasterMute on device policy service"); |
| 4048 | } |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | /** |
| 4053 | * Called by profile or device owners to check whether the master volume mute is on or off. |
| 4054 | * |
| 4055 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4056 | * @return {@code true} if master volume is muted, {@code false} if it's not. |
| 4057 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4058 | public boolean isMasterVolumeMuted(@NonNull ComponentName admin) { |
Julia Reynolds | 4a21b25 | 2014-06-04 11:11:43 -0400 | [diff] [blame] | 4059 | if (mService != null) { |
| 4060 | try { |
| 4061 | return mService.isMasterVolumeMuted(admin); |
| 4062 | } catch (RemoteException re) { |
| 4063 | Log.w(TAG, "Failed to get isMasterMute on device policy service"); |
| 4064 | } |
| 4065 | } |
| 4066 | return false; |
| 4067 | } |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4068 | |
| 4069 | /** |
| 4070 | * Called by profile or device owners to change whether a user can uninstall |
| 4071 | * a package. |
| 4072 | * |
| 4073 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4074 | * @param packageName package to change. |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4075 | * @param uninstallBlocked true if the user shouldn't be able to uninstall the package. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4076 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4077 | public void setUninstallBlocked(@NonNull ComponentName admin, String packageName, |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4078 | boolean uninstallBlocked) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4079 | if (mService != null) { |
| 4080 | try { |
Esteban Talavera | d5c5c13 | 2014-08-20 11:35:57 +0100 | [diff] [blame] | 4081 | mService.setUninstallBlocked(admin, packageName, uninstallBlocked); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4082 | } catch (RemoteException re) { |
| 4083 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | /** |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4089 | * Check whether the current user has been blocked by device policy from uninstalling a package. |
| 4090 | * Requires the caller to be the profile owner if checking a specific admin's policy. |
Rubin Xu | e1e6faa | 2015-03-10 10:51:59 +0000 | [diff] [blame] | 4091 | * <p> |
| 4092 | * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4093 | * behavior of this API is changed such that passing {@code null} as the {@code admin} |
Rubin Xu | e1e6faa | 2015-03-10 10:51:59 +0000 | [diff] [blame] | 4094 | * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4095 | * {@code null} will cause a NullPointerException to be raised. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4096 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4097 | * @param admin The name of the admin component whose blocking policy will be checked, or |
| 4098 | * {@code null} to check whether any admin has blocked the uninstallation. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4099 | * @param packageName package to check. |
Rubin Xu | a97855b | 2014-11-07 05:41:00 +0000 | [diff] [blame] | 4100 | * @return true if uninstallation is blocked. |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4101 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4102 | public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) { |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4103 | if (mService != null) { |
| 4104 | try { |
Esteban Talavera | 729b2a6 | 2014-08-27 18:01:58 +0100 | [diff] [blame] | 4105 | return mService.isUninstallBlocked(admin, packageName); |
Kenny Guy | c13053b | 2014-05-29 14:17:17 +0100 | [diff] [blame] | 4106 | } catch (RemoteException re) { |
| 4107 | Log.w(TAG, "Failed to call block uninstall on device policy service"); |
| 4108 | } |
| 4109 | } |
| 4110 | return false; |
| 4111 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4112 | |
| 4113 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4114 | * Called by the profile owner of a managed profile to enable widget providers from a |
| 4115 | * given package to be available in the parent profile. As a result the user will be able to |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4116 | * add widgets from the white-listed package running under the profile to a widget |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4117 | * host which runs under the parent profile, for example the home screen. Note that |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4118 | * a package may have zero or more provider components, where each component |
| 4119 | * provides a different widget type. |
| 4120 | * <p> |
| 4121 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4122 | * |
| 4123 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4124 | * @param packageName The package from which widget providers are white-listed. |
| 4125 | * @return Whether the package was added. |
| 4126 | * |
| 4127 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4128 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4129 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4130 | public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4131 | if (mService != null) { |
| 4132 | try { |
| 4133 | return mService.addCrossProfileWidgetProvider(admin, packageName); |
| 4134 | } catch (RemoteException re) { |
| 4135 | Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re); |
| 4136 | } |
| 4137 | } |
| 4138 | return false; |
| 4139 | } |
| 4140 | |
| 4141 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4142 | * Called by the profile owner of a managed profile to disable widget providers from a given |
| 4143 | * package to be available in the parent profile. For this method to take effect the |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4144 | * package should have been added via {@link #addCrossProfileWidgetProvider( |
| 4145 | * android.content.ComponentName, String)}. |
| 4146 | * <p> |
| 4147 | * <strong>Note:</strong> By default no widget provider package is white-listed. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4148 | * |
| 4149 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4150 | * @param packageName The package from which widget providers are no longer |
| 4151 | * white-listed. |
| 4152 | * @return Whether the package was removed. |
| 4153 | * |
| 4154 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4155 | * @see #getCrossProfileWidgetProviders(android.content.ComponentName) |
| 4156 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4157 | public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4158 | if (mService != null) { |
| 4159 | try { |
| 4160 | return mService.removeCrossProfileWidgetProvider(admin, packageName); |
| 4161 | } catch (RemoteException re) { |
| 4162 | Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re); |
| 4163 | } |
| 4164 | } |
| 4165 | return false; |
| 4166 | } |
| 4167 | |
| 4168 | /** |
Amith Yamasani | c34dc7c | 2014-09-18 09:42:42 -0700 | [diff] [blame] | 4169 | * Called by the profile owner of a managed profile to query providers from which packages are |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4170 | * available in the parent profile. |
| 4171 | * |
| 4172 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4173 | * @return The white-listed package list. |
| 4174 | * |
| 4175 | * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4176 | * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String) |
| 4177 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4178 | public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 4179 | if (mService != null) { |
| 4180 | try { |
| 4181 | List<String> providers = mService.getCrossProfileWidgetProviders(admin); |
| 4182 | if (providers != null) { |
| 4183 | return providers; |
| 4184 | } |
| 4185 | } catch (RemoteException re) { |
| 4186 | Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re); |
| 4187 | } |
| 4188 | } |
| 4189 | return Collections.emptyList(); |
| 4190 | } |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4191 | |
| 4192 | /** |
| 4193 | * Called by profile or device owners to set the current user's photo. |
| 4194 | * |
| 4195 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
| 4196 | * @param icon the bitmap to set as the photo. |
| 4197 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4198 | public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) { |
Julia Reynolds | fca04ca | 2015-02-17 13:39:12 -0500 | [diff] [blame] | 4199 | try { |
| 4200 | mService.setUserIcon(admin, icon); |
| 4201 | } catch (RemoteException re) { |
| 4202 | Log.w(TAG, "Could not set the user icon ", re); |
| 4203 | } |
| 4204 | } |
Craig Lafayette | dbe31a6 | 2015-04-02 13:14:39 -0400 | [diff] [blame] | 4205 | |
| 4206 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4207 | * Called by device owners to set a local system update policy. When a new policy is set, |
| 4208 | * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4209 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4210 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All |
| 4211 | * components in the device owner package can set system update policies and the |
| 4212 | * most recent policy takes |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4213 | * effect. |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4214 | * @param policy the new policy, or {@code null} to clear the current policy. |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4215 | * @see SystemUpdatePolicy |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4216 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4217 | public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4218 | if (mService != null) { |
| 4219 | try { |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4220 | mService.setSystemUpdatePolicy(admin, policy); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4221 | } catch (RemoteException re) { |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4222 | Log.w(TAG, "Error calling setSystemUpdatePolicy", re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4223 | } |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | /** |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4228 | * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4229 | * |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4230 | * @return The current policy object, or {@code null} if no policy is set. |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4231 | */ |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4232 | public SystemUpdatePolicy getSystemUpdatePolicy() { |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4233 | if (mService != null) { |
| 4234 | try { |
Rubin Xu | d86d58c | 2015-05-05 16:57:37 +0100 | [diff] [blame] | 4235 | return mService.getSystemUpdatePolicy(); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4236 | } catch (RemoteException re) { |
Rubin Xu | 5faad8e | 2015-04-20 17:43:48 +0100 | [diff] [blame] | 4237 | Log.w(TAG, "Error calling getSystemUpdatePolicy", re); |
Rubin Xu | 8027a4f | 2015-03-10 17:52:37 +0000 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | return null; |
| 4241 | } |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4242 | |
| 4243 | /** |
| 4244 | * Called by a device owner to disable the keyguard altogether. |
| 4245 | * |
| 4246 | * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen |
| 4247 | * lock type. However, this call has no effect if a password, pin or pattern is currently set. |
| 4248 | * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops |
| 4249 | * being disabled. |
| 4250 | * |
| 4251 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4252 | * @param disabled {@code true} disables the keyguard, {@code false} reenables it. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4253 | * |
| 4254 | * @return {@code false} if attempting to disable the keyguard while a lock password was in |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4255 | * place. {@code true} otherwise. |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4256 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4257 | public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4258 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4259 | return mService.setKeyguardDisabled(admin, disabled); |
Benjamin Franz | e36087e | 2015-04-07 16:40:34 +0100 | [diff] [blame] | 4260 | } catch (RemoteException re) { |
| 4261 | Log.w(TAG, "Failed talking with device policy service", re); |
| 4262 | return false; |
| 4263 | } |
| 4264 | } |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4265 | |
| 4266 | /** |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4267 | * Called by device owner to disable the status bar. Disabling the status bar blocks |
| 4268 | * notifications, quick settings and other screen overlays that allow escaping from |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4269 | * a single use device. |
| 4270 | * |
| 4271 | * @param admin Which {@link DeviceAdminReceiver} this request is associated with. |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4272 | * @param disabled {@code true} disables the status bar, {@code false} reenables it. |
| 4273 | * |
| 4274 | * @return {@code false} if attempting to disable the status bar failed. |
| 4275 | * {@code true} otherwise. |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4276 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4277 | public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) { |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4278 | try { |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4279 | return mService.setStatusBarDisabled(admin, disabled); |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4280 | } catch (RemoteException re) { |
| 4281 | Log.w(TAG, "Failed talking with device policy service", re); |
Benjamin Franz | bece806 | 2015-05-06 12:14:31 +0100 | [diff] [blame] | 4282 | return false; |
Benjamin Franz | ea2ec97 | 2015-03-16 17:18:09 +0000 | [diff] [blame] | 4283 | } |
| 4284 | } |
Rubin Xu | dc105cc | 2015-04-14 23:38:01 +0100 | [diff] [blame] | 4285 | |
| 4286 | /** |
| 4287 | * Callable by the system update service to notify device owners about pending updates. |
| 4288 | * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE} |
| 4289 | * permission. |
| 4290 | * |
| 4291 | * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating |
| 4292 | * when the current pending update was first available. -1 if no update is available. |
| 4293 | * @hide |
| 4294 | */ |
| 4295 | @SystemApi |
| 4296 | public void notifyPendingSystemUpdate(long updateReceivedTime) { |
| 4297 | if (mService != null) { |
| 4298 | try { |
| 4299 | mService.notifyPendingSystemUpdate(updateReceivedTime); |
| 4300 | } catch (RemoteException re) { |
| 4301 | Log.w(TAG, "Could not notify device owner about pending system update", re); |
| 4302 | } |
| 4303 | } |
| 4304 | } |
Julia Reynolds | 13c58ba | 2015-04-20 16:42:54 -0400 | [diff] [blame] | 4305 | |
| 4306 | /** |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4307 | * Called by profile or device owners to set the default response for future runtime permission |
| 4308 | * requests by applications. The policy can allow for normal operation which prompts the |
| 4309 | * user to grant a permission, or can allow automatic granting or denying of runtime |
| 4310 | * permission requests by an application. This also applies to new permissions declared by app |
| 4311 | * updates. |
| 4312 | * @param admin Which profile or device owner this request is associated with. |
| 4313 | * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT}, |
| 4314 | * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}. |
| 4315 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4316 | public void setPermissionPolicy(@NonNull ComponentName admin, int policy) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4317 | try { |
| 4318 | mService.setPermissionPolicy(admin, policy); |
| 4319 | } catch (RemoteException re) { |
| 4320 | Log.w(TAG, "Failed talking with device policy service", re); |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * Returns the current runtime permission policy set by the device or profile owner. The |
| 4326 | * default is {@link #PERMISSION_POLICY_PROMPT}. |
| 4327 | * @param admin Which profile or device owner this request is associated with. |
| 4328 | * @return the current policy for future permission requests. |
| 4329 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4330 | public int getPermissionPolicy(@NonNull ComponentName admin) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4331 | try { |
| 4332 | return mService.getPermissionPolicy(admin); |
| 4333 | } catch (RemoteException re) { |
| 4334 | return PERMISSION_POLICY_PROMPT; |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | /** |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 4339 | * Sets the grant state of a runtime permission for a specific application. The state |
| 4340 | * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it |
| 4341 | * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission |
| 4342 | * is denied and the user cannot manage it through the UI, and {@link |
| 4343 | * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the |
| 4344 | * user cannot manage it through the UI. This might affect all permissions in a |
| 4345 | * group that the runtime permission belongs to. This method can only be called |
| 4346 | * by a profile or device owner. |
| 4347 | * |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4348 | * @param admin Which profile or device owner this request is associated with. |
| 4349 | * @param packageName The application to grant or revoke a permission to. |
| 4350 | * @param permission The permission to grant or revoke. |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 4351 | * @param grantState The permission grant state which is one of {@link |
| 4352 | * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT}, |
| 4353 | * {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 4354 | * @return whether the permission was successfully granted or revoked. |
| 4355 | * |
| 4356 | * @see #PERMISSION_GRANT_STATE_DENIED |
| 4357 | * @see #PERMISSION_GRANT_STATE_DEFAULT |
| 4358 | * @see #PERMISSION_GRANT_STATE_GRANTED |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4359 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4360 | public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 4361 | String permission, int grantState) { |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4362 | try { |
Svet Ganov | d8ecc5a | 2015-05-20 10:45:43 -0700 | [diff] [blame] | 4363 | return mService.setPermissionGrantState(admin, packageName, permission, grantState); |
Amith Yamasani | d49489b | 2015-04-28 14:00:26 -0700 | [diff] [blame] | 4364 | } catch (RemoteException re) { |
| 4365 | Log.w(TAG, "Failed talking with device policy service", re); |
| 4366 | return false; |
| 4367 | } |
| 4368 | } |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 4369 | |
| 4370 | /** |
| 4371 | * Returns the current grant state of a runtime permission for a specific application. |
| 4372 | * |
| 4373 | * @param admin Which profile or device owner this request is associated with. |
| 4374 | * @param packageName The application to check the grant state for. |
| 4375 | * @param permission The permission to check for. |
| 4376 | * @return the current grant state specified by device policy. If the profile or device owner |
| 4377 | * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}. |
| 4378 | * This does not indicate whether or not the permission is currently granted for the package. |
| 4379 | * |
| 4380 | * <p/>If a grant state was set by the profile or device owner, then the return value will |
| 4381 | * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED}, |
| 4382 | * which indicates if the permission is currently denied or granted. |
| 4383 | * |
| 4384 | * @see #setPermissionGrantState(ComponentName, String, String, int) |
| 4385 | * @see PackageManager#checkPermission(String, String) |
| 4386 | */ |
Robin Lee | 25e2645 | 2015-06-02 09:56:29 -0700 | [diff] [blame] | 4387 | public int getPermissionGrantState(@NonNull ComponentName admin, String packageName, |
Amith Yamasani | 184b375 | 2015-05-22 13:00:51 -0700 | [diff] [blame] | 4388 | String permission) { |
| 4389 | try { |
| 4390 | return mService.getPermissionGrantState(admin, packageName, permission); |
| 4391 | } catch (RemoteException re) { |
| 4392 | Log.w(TAG, "Failed talking with device policy service", re); |
| 4393 | return PERMISSION_GRANT_STATE_DEFAULT; |
| 4394 | } |
| 4395 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 4396 | } |