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