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