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