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