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