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