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