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