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