blob: 7a18df6e4e447c3c1205bcbc72589eb1d5c60ed2 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
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 Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050025import android.annotation.SystemApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000026import android.annotation.UserIdInt;
Jason Monkd7b86212014-06-16 13:15:38 -040027import android.app.Activity;
Michal Karpinski6235a942016-03-15 12:07:23 +000028import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.ComponentName;
30import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010031import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000032import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000034import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000035import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000036import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050037import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040038import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000039import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010040import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070041import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000042import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080043import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.os.RemoteException;
45import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070046import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040047import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000048import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000049import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010050import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070051import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000052import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import android.util.Log;
54
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070055import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040056import com.android.org.conscrypt.TrustedCertificateStore;
57
58import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080059import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000060import java.lang.annotation.Retention;
61import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070062import java.net.InetSocketAddress;
63import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010064import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000065import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010066import java.security.PrivateKey;
67import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040068import java.security.cert.CertificateException;
69import java.security.cert.CertificateFactory;
70import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010071import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000072import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070073import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000074import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070075import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080076import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010077import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080078
79/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000080 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070081 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
82 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
83 * device owner. A given method is accessible to all device administrators unless the documentation
84 * for that method specifies that it is restricted to either device or profile owners. Any
85 * application calling an api may only pass as an argument a device administrator component it
86 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080087 * <div class="special reference">
88 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070089 * <p>
90 * For more information about managing policies for device administration, read the <a href=
91 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
92 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080093 */
94public class DevicePolicyManager {
95 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080096
97 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +000099 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700100
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000101 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000102 this(context,
103 IDevicePolicyManager.Stub.asInterface(
104 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
105 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800106 }
107
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800108 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000110 protected DevicePolicyManager(
111 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700112 mContext = context;
113 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000114 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 }
116
117 /** @hide */
118 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000119 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800120 return me.mService != null ? me : null;
121 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700122
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700123 /** @hide test will override it. */
124 @VisibleForTesting
125 protected int myUserId() {
126 return UserHandle.myUserId();
127 }
128
Dianne Hackbornd6847842010-01-12 18:14:19 -0800129 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000131 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100132 * <p>A managed profile allows data separation for example for the usage of a
133 * device as a personal and corporate device. The user which provisioning is started from and
134 * the managed profile share a launcher.
135 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800136 * <p>This intent will typically be sent by a mobile device management application (MDM).
137 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
138 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100139 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000140 * <p>It is possible to check if provisioning is allowed or not by querying the method
141 * {@link #isProvisioningAllowed(String)}.
142 *
143 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000144 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700145 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000146 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
147 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000148 *
Benjamin Franzea956242016-03-21 15:45:56 +0000149 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000150 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000151 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
152 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
153 * {@link android.os.Build.VERSION_CODES#N}</li>
154 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
155 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
156 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000157 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000158 *
Benjamin Franzea956242016-03-21 15:45:56 +0000159 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000160 * in the provisioning intent. The
161 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
162 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
163 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100164 *
Benjamin Franzea956242016-03-21 15:45:56 +0000165 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100166 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100167 *
168 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
169 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
170 * the provisioning flow was successful, although this doesn't guarantee the full flow will
171 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
172 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000173 */
174 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
175 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100176 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000177
178 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000179 * Activity action: Starts the provisioning flow which sets up a managed user.
180 *
181 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800182 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000183 * owner who has full control over the user. Provisioning can only happen before user setup has
184 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
185 * allowed.
186 *
Benjamin Franzea956242016-03-21 15:45:56 +0000187 * <p>The intent contains the following extras:
188 * <ul>
189 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
190 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
191 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
192 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
193 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
194 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000195 *
Benjamin Franzea956242016-03-21 15:45:56 +0000196 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000197 *
198 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
199 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
200 * the provisioning flow was successful, although this doesn't guarantee the full flow will
201 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
202 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000203 *
204 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000205 */
206 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
207 public static final String ACTION_PROVISION_MANAGED_USER
208 = "android.app.action.PROVISION_MANAGED_USER";
209
210 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100211 * Activity action: Starts the provisioning flow which sets up a managed device.
212 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
213 *
214 * <p> During device owner provisioning a device admin app is set as the owner of the device.
215 * A device owner has full control over the device. The device owner can not be modified by the
216 * user.
217 *
218 * <p> A typical use case would be a device that is owned by a company, but used by either an
219 * employee or client.
220 *
221 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000222 * It is possible to check if provisioning is allowed or not by querying the method
223 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100224 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000225 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100226 * <ul>
227 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
228 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
229 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100230 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000231 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000232 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100233 * </ul>
234 *
Benjamin Franzea956242016-03-21 15:45:56 +0000235 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100236 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
237 * device owner.
238 *
Benjamin Franzea956242016-03-21 15:45:56 +0000239 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 *
Alan Treadway4582f812015-07-28 11:49:35 +0100241 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
242 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
243 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
244 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100245 */
246 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
247 public static final String ACTION_PROVISION_MANAGED_DEVICE
248 = "android.app.action.PROVISION_MANAGED_DEVICE";
249
250 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000251 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000252 *
253 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
254 * the device. A device owner has full control over the device. The device owner can not be
255 * modified by the user and the only way of resetting the device is via factory reset.
256 *
257 * <p>A typical use case would be a device that is owned by a company, but used by either an
258 * employee or client.
259 *
260 * <p>The provisioning message should be sent to an unprovisioned device.
261 *
262 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
263 * by a privileged app with the permission
264 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
265 *
266 * <p>The provisioning intent contains the following properties:
267 * <ul>
268 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
269 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
284 *
285 * @hide
286 */
287 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
288 @SystemApi
289 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
290 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
291
292 /**
293 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000294 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
295 *
296 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
297 * management state that is distinct from that reached by
298 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
299 * user, and only has control over device-wide policies, not individual users and their data.
300 * The primary benefit is that multiple non-system users are supported when provisioning using
301 * this form of device management.
302 *
Benjamin Franzea956242016-03-21 15:45:56 +0000303 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000304 * A device owner has full control over the device. The device owner can not be modified by the
305 * user.
306 *
Benjamin Franzea956242016-03-21 15:45:56 +0000307 * <p>A typical use case would be a device that is owned by a company, but used by either an
Alan Treadway46dd4492015-11-09 13:57:19 +0000308 * employee or client.
309 *
Benjamin Franzea956242016-03-21 15:45:56 +0000310 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000311 * It is possible to check if provisioning is allowed or not by querying the method
312 * {@link #isProvisioningAllowed(String)}.
313 *
314 * <p>The intent contains the following extras:
315 * <ul>
316 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
317 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
319 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000320 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
321 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000322 * </ul>
323 *
Benjamin Franzea956242016-03-21 15:45:56 +0000324 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000325 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
326 * device owner.
327 *
Benjamin Franzea956242016-03-21 15:45:56 +0000328 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000329 *
330 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
331 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
332 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
333 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
334 *
335 * @hide
336 */
337 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
338 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
339 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
340
341 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000342 * Activity action: Finalizes management provisioning, should be used after user-setup
343 * has been completed and {@link #getUserProvisioningState()} returns one of:
344 * <ul>
345 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
346 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
347 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
348 * </ul>
349 *
350 * @hide
351 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000352 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000353 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
354 public static final String ACTION_PROVISION_FINALIZATION
355 = "android.app.action.PROVISION_FINALIZATION";
356
357 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000358 * Action: Bugreport sharing with device owner has been accepted by the user.
359 *
360 * @hide
361 */
362 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
363 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
364
365 /**
366 * Action: Bugreport sharing with device owner has been declined by the user.
367 *
368 * @hide
369 */
370 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
371 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
372
373 /**
374 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
375 *
376 * @hide
377 */
378 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
379 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
380
381 /**
382 * Extra for shared bugreport's SHA-256 hash.
383 *
384 * @hide
385 */
386 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
387 "android.intent.extra.REMOTE_BUGREPORT_HASH";
388
389 /**
390 * Extra for remote bugreport notification shown type.
391 *
392 * @hide
393 */
394 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
395 "android.app.extra.bugreport_notification_type";
396
397 /**
398 * Notification type for a started remote bugreport flow.
399 *
400 * @hide
401 */
402 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
403
404 /**
405 * Notification type for a bugreport that has already been accepted to be shared, but is still
406 * being taken.
407 *
408 * @hide
409 */
410 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
411
412 /**
413 * Notification type for a bugreport that has been taken and can be shared or declined.
414 *
415 * @hide
416 */
417 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
418
419 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100420 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100421 * allows a mobile device management application or NFC programmer application which starts
422 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100423 * <p>
424 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
425 * sends the intent to pass data to itself on the newly created profile.
426 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
427 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100428 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
429 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
430 * message should contain a stringified {@link java.util.Properties} instance, whose string
431 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
432 * management application after provisioning.
433 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100434 * <p>
435 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700436 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
437 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100438 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100439 */
440 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100441 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100442
443 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100444 * A String extra holding the package name of the mobile device management application that
445 * will be set as the profile owner or device owner.
446 *
447 * <p>If an application starts provisioning directly via an intent with action
448 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
449 * application that started provisioning. The package will be set as profile owner in that case.
450 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000451 * <p>This package is set as device owner when device owner provisioning is started by an NFC
452 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000453 *
454 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700455 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000456 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000457 * @see DeviceAdminReceiver
458 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100459 * supported, but only if there is only one device admin receiver in the package that requires
460 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000461 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000462 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000463 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100464 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000465
466 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000467 * A ComponentName extra indicating the device admin receiver of the mobile device management
468 * application that will be set as the profile owner or device owner and active admin.
469 *
470 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100471 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
472 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
473 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000474 *
475 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100476 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
477 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000478 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000479 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000480 *
481 * @see DeviceAdminReceiver
482 */
483 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
484 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
485
486 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000487 * An {@link android.accounts.Account} extra holding the account to migrate during managed
488 * profile provisioning. If the account supplied is present in the primary user, it will be
489 * copied, along with its credentials to the managed profile and removed from the primary user.
490 *
491 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
492 */
493
494 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
495 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
496
497 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100498 * A String extra that, holds the email address of the account which a managed profile is
499 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
500 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100501 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100502 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
503 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100504 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
505 * contains this extra, it is forwarded in the
506 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
507 * device management application that was set as the profile owner during provisioning.
508 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100509 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100510 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
511 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100512
513 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000514 * A integer extra indicating the predominant color to show during the provisioning.
515 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000516 *
517 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
518 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
519 */
520 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
521 "android.app.extra.PROVISIONING_MAIN_COLOR";
522
523 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000524 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700525 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000526 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100527 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
528 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000529 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000530 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
531 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000532
533 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
535 * will be set to.
536 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000537 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
538 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100539 */
540 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100541 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542
543 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100544 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
545 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100546 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000547 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
548 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100549 */
550 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100551 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552
553 /**
554 * A String extra holding the {@link java.util.Locale} that the device will be set to.
555 * Format: xx_yy, where xx is the language code, and yy the country code.
556 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000557 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
558 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100559 */
560 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100561 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562
563 /**
564 * A String extra holding the ssid of the wifi network that should be used during nfc device
565 * owner provisioning for downloading the mobile device management application.
566 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000567 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
568 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 */
570 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100571 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572
573 /**
574 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
575 * is hidden or not.
576 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000577 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
578 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 */
580 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
584 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100585 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
586 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100587 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000588 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
589 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590 */
591 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100592 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100593
594 /**
595 * A String extra holding the password of the wifi network in
596 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
597 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000598 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
599 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100600 */
601 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100602 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100603
604 /**
605 * A String extra holding the proxy host for the wifi network in
606 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
607 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000608 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
609 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610 */
611 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100612 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100613
614 /**
615 * An int extra holding the proxy port for the wifi network in
616 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
617 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000618 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
619 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 */
621 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100622 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623
624 /**
625 * A String extra holding the proxy bypass for the wifi network in
626 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
627 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000628 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
629 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100630 */
631 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100632 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633
634 /**
635 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
636 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
637 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 */
641 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100642 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643
644 /**
645 * A String extra holding a url that specifies the download location of the device admin
646 * package. When not provided it is assumed that the device admin package is already installed.
647 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000648 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
649 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 */
651 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100652 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653
654 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400655 * An int extra holding a minimum required version code for the device admin package. If the
656 * device admin is already installed on the device, it will only be re-downloaded from
657 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
658 * installed package is less than this version code.
659 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400660 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400661 * provisioning via an NFC bump.
662 */
663 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
664 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
665
666 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100667 * A String extra holding a http cookie header which should be used in the http request to the
668 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
669 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000670 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
671 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100672 */
673 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100674 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100675
676 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100677 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
678 * the file at download location specified in
679 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100680 *
Benjamin Franzea956242016-03-21 15:45:56 +0000681 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
682 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100683 * location. If the checksum doesn't match an error will be shown to the user and the user will
684 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100685 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000686 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
687 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100688 *
689 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
690 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700691 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100692 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100693 */
694 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100695 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100696
697 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100698 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100699 * android package archive at the download location specified in {@link
700 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
701 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100702 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100703 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
704 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
705 *
Benjamin Franzea956242016-03-21 15:45:56 +0000706 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
707 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100708 * the download location. If the checksum does not match an error will be shown to the user and
709 * the user will be asked to factory reset the device.
710 *
711 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
712 * provisioning via an NFC bump.
713 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100714 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
715 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100716
717 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000718 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
719 * has completed successfully.
720 *
721 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700722 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000723 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800724 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000725 * corresponds to the account requested to be migrated at provisioning time, if any.
726 */
727 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
728 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
729 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
730
731 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000732 * A boolean extra indicating whether device encryption can be skipped as part of device owner
733 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500734 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400735 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100736 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000737 *
738 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
739 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500740 */
741 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
742 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
743
744 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000745 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
746 * provisioning. If this extra is not passed, a default image will be shown.
747 * <h5>The following URI schemes are accepted:</h5>
748 * <ul>
749 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
750 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
751 * </ul>
752 *
753 * <p> It is the responsability of the caller to provide an image with a reasonable
754 * pixed density for the device.
755 *
756 * <p> If a content: URI is passed, the intent should have the flag
757 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
758 * {@link android.content.ClipData} of the intent too.
759 *
760 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
761 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
762 */
763 public static final String EXTRA_PROVISIONING_LOGO_URI =
764 "android.app.extra.PROVISIONING_LOGO_URI";
765
766 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000767 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
768 * during setup-wizard.
769 *
770 * <p>If unspecified, defaults to {@code true} to match the behavior in
771 * {@link android.os.Build.VERSION_CODES#M} and earlier.
772 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000773 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
774 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000775 *
776 * @hide
777 */
778 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
779 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
780
781 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000782 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100783 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400784 * <p>During device owner provisioning a device admin app is set as the owner of the device.
785 * A device owner has full control over the device. The device owner can not be modified by the
786 * user and the only way of resetting the device is if the device owner app calls a factory
787 * reset.
788 *
789 * <p> A typical use case would be a device that is owned by a company, but used by either an
790 * employee or client.
791 *
Benjamin Franzea956242016-03-21 15:45:56 +0000792 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100793 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000794 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100795 * contains the following properties:
796 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400797 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
798 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100799 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400800 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100801 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
802 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
803 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
804 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
805 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
806 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
807 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
808 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
809 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
810 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100811 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
812 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
813 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100814 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000815 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700816 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400817 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
818 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
819 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400820 */
821 public static final String MIME_TYPE_PROVISIONING_NFC
822 = "application/com.android.managedprovisioning";
823
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100824 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800825 * Activity action: ask the user to add a new device administrator to the system.
826 * The desired policy is the ComponentName of the policy in the
827 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
828 * bring the user through adding the device administrator to the system (or
829 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700830 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800831 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
832 * field to provide the user with additional explanation (in addition
833 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800834 *
835 * <p>If your administrator is already active, this will ordinarily return immediately (without
836 * user intervention). However, if your administrator has been updated and is requesting
837 * additional uses-policy flags, the user will be presented with the new list. New policies
838 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800839 */
840 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
841 public static final String ACTION_ADD_DEVICE_ADMIN
842 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700843
Dianne Hackbornd6847842010-01-12 18:14:19 -0800844 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700845 * @hide
846 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700847 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700848 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700849 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
850 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700851 * to remotely control restrictions on the user.
852 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800853 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700854 * result of whether or not the user approved the action. If approved, the result will
855 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
856 * as a profile owner.
857 *
858 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
859 * field to provide the user with additional explanation (in addition
860 * to your component's description) about what is being added.
861 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700862 * <p>If there is already a profile owner active or the caller is not a system app, the
863 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700864 */
865 @SystemApi
866 public static final String ACTION_SET_PROFILE_OWNER
867 = "android.app.action.SET_PROFILE_OWNER";
868
869 /**
870 * @hide
871 * Name of the profile owner admin that controls the user.
872 */
873 @SystemApi
874 public static final String EXTRA_PROFILE_OWNER_NAME
875 = "android.app.extra.PROFILE_OWNER_NAME";
876
877 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100878 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700879 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700880 *
Jim Miller284b62e2010-06-08 14:27:42 -0700881 * @hide
882 */
883 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
884 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
885
886 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100887 * Broadcast action: sent when the device owner is set or changed.
888 *
889 * This broadcast is sent only to the primary user.
890 * @see #ACTION_PROVISION_MANAGED_DEVICE
891 */
892 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
893 public static final String ACTION_DEVICE_OWNER_CHANGED
894 = "android.app.action.DEVICE_OWNER_CHANGED";
895
896 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800897 * The ComponentName of the administrator component.
898 *
899 * @see #ACTION_ADD_DEVICE_ADMIN
900 */
901 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700902
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800904 * An optional CharSequence providing additional explanation for why the
905 * admin is being added.
906 *
907 * @see #ACTION_ADD_DEVICE_ADMIN
908 */
909 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700910
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800911 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700912 * Activity action: have the user enter a new password. This activity should
913 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
914 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
915 * enter a new password that meets the current requirements. You can use
916 * {@link #isActivePasswordSufficient()} to determine whether you need to
917 * have the user select a new password in order to meet the current
918 * constraints. Upon being resumed from this activity, you can check the new
919 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000920 *
921 * If the intent is launched from within a managed profile with a profile
922 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
923 * this will trigger entering a new password for the parent of the profile.
924 * For all other cases it will trigger entering a new password for the user
925 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000926 *
927 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 */
929 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
930 public static final String ACTION_SET_NEW_PASSWORD
931 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700932
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000933 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000934 * Activity action: have the user enter a new password for the parent profile.
935 * If the intent is launched from within a managed profile, this will trigger
936 * entering a new password for the parent of the profile. In all other cases
937 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
938 */
939 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
940 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
941 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
942
943 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000944 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
945 * the parent profile to access intents sent from the managed profile.
946 * That is, when an app in the managed profile calls
947 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
948 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000949 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100950 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000951
952 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000953 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
954 * the managed profile to access intents sent from the parent profile.
955 * That is, when an app in the parent profile calls
956 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
957 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000958 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100959 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700960
Dianne Hackbornd6847842010-01-12 18:14:19 -0800961 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100962 * Broadcast action: notify that a new local system update policy has been set by the device
963 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000964 */
965 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100966 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
967 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000968
Amith Yamasanid49489b2015-04-28 14:00:26 -0700969 /**
970 * Permission policy to prompt user for new permission requests for runtime permissions.
971 * Already granted or denied permissions are not affected by this.
972 */
973 public static final int PERMISSION_POLICY_PROMPT = 0;
974
975 /**
976 * Permission policy to always grant new permission requests for runtime permissions.
977 * Already granted or denied permissions are not affected by this.
978 */
979 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
980
981 /**
982 * Permission policy to always deny new permission requests for runtime permissions.
983 * Already granted or denied permissions are not affected by this.
984 */
985 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
986
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700987 /**
988 * Runtime permission state: The user can manage the permission
989 * through the UI.
990 */
991 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
992
993 /**
994 * Runtime permission state: The permission is granted to the app
995 * and the user cannot manage the permission through the UI.
996 */
997 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
998
999 /**
1000 * Runtime permission state: The permission is denied to the app
1001 * and the user cannot manage the permission through the UI.
1002 */
1003 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001004
1005 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001006 * No management for current user in-effect. This is the default.
1007 * @hide
1008 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001009 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001010 public static final int STATE_USER_UNMANAGED = 0;
1011
1012 /**
1013 * Management partially setup, user setup needs to be completed.
1014 * @hide
1015 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001016 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001017 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1018
1019 /**
1020 * Management partially setup, user setup completed.
1021 * @hide
1022 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001023 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001024 public static final int STATE_USER_SETUP_COMPLETE = 2;
1025
1026 /**
1027 * Management setup and active on current user.
1028 * @hide
1029 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001030 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001031 public static final int STATE_USER_SETUP_FINALIZED = 3;
1032
1033 /**
1034 * Management partially setup on a managed profile.
1035 * @hide
1036 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001037 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001038 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1039
1040 /**
1041 * @hide
1042 */
1043 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1044 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1045 @Retention(RetentionPolicy.SOURCE)
1046 public @interface UserProvisioningState {}
1047
1048 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001049 * Return true if the given administrator component is currently active (enabled) in the system.
1050 *
1051 * @param admin The administrator component to check for.
1052 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1053 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001054 */
Robin Lee25e26452015-06-02 09:56:29 -07001055 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001056 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001057 }
1058
1059 /**
1060 * @see #isAdminActive(ComponentName)
1061 * @hide
1062 */
Robin Lee25e26452015-06-02 09:56:29 -07001063 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001064 if (mService != null) {
1065 try {
Robin Lee25e26452015-06-02 09:56:29 -07001066 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001067 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001068 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 }
1070 }
1071 return false;
1072 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001073 /**
1074 * Return true if the given administrator component is currently being removed
1075 * for the user.
1076 * @hide
1077 */
Robin Lee25e26452015-06-02 09:56:29 -07001078 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001079 if (mService != null) {
1080 try {
Robin Lee25e26452015-06-02 09:56:29 -07001081 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001082 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001083 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001084 }
1085 }
1086 return false;
1087 }
1088
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001089
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 /**
Robin Lee25e26452015-06-02 09:56:29 -07001091 * Return a list of all currently active device administrators' component
1092 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001093 * returned.
1094 */
1095 public List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001096 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001097 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001098 }
1099
1100 /**
1101 * @see #getActiveAdmins()
1102 * @hide
1103 */
1104 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001105 if (mService != null) {
1106 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001107 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001109 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001110 }
1111 }
1112 return null;
1113 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001114
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001115 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001116 * Used by package administration code to determine if a package can be stopped
1117 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001118 * @hide
1119 */
1120 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001121 return packageHasActiveAdmins(packageName, myUserId());
1122 }
1123
1124 /**
1125 * Used by package administration code to determine if a package can be stopped
1126 * or uninstalled.
1127 * @hide
1128 */
1129 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001130 if (mService != null) {
1131 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001132 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001133 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001134 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001135 }
1136 }
1137 return false;
1138 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001139
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001140 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001141 * Remove a current administration component. This can only be called
1142 * by the application that owns the administration component; if you
1143 * try to remove someone else's component, a security exception will be
1144 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001145 *
1146 * <p>Note that the operation is not synchronous and the admin might still be active (as
1147 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001148 *
1149 * @param admin The administration compononent to remove.
1150 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001151 */
Robin Lee25e26452015-06-02 09:56:29 -07001152 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001153 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 if (mService != null) {
1155 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001156 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001157 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001158 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001159 }
1160 }
1161 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001162
Dianne Hackbornd6847842010-01-12 18:14:19 -08001163 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001164 * Returns true if an administrator has been granted a particular device policy. This can be
1165 * used to check whether the administrator was activated under an earlier set of policies, but
1166 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001167 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1169 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001170 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001171 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001172 */
Robin Lee25e26452015-06-02 09:56:29 -07001173 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001174 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001175 if (mService != null) {
1176 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001177 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001178 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001179 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001180 }
1181 }
1182 return false;
1183 }
1184
1185 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001186 * Returns true if the Profile Challenge is available to use for the given profile user.
1187 *
1188 * @hide
1189 */
1190 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1191 if (mService != null) {
1192 try {
1193 return mService.isSeparateProfileChallengeAllowed(userHandle);
1194 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001195 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001196 }
1197 }
1198 return false;
1199 }
1200
1201 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001202 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1203 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001204 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001205 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001206 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001207
Dianne Hackbornd6847842010-01-12 18:14:19 -08001208 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001209 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1210 * recognition technology. This implies technologies that can recognize the identity of
1211 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1212 * Note that quality constants are ordered so that higher values are more restrictive.
1213 */
1214 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1215
1216 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001217 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001218 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001219 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001220 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001221 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001222
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001223 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001224 * Constant for {@link #setPasswordQuality}: the user must have entered a
1225 * password containing at least numeric characters. Note that quality
1226 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001227 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001228 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001229
Dianne Hackbornd6847842010-01-12 18:14:19 -08001230 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001231 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001232 * password containing at least numeric characters with no repeating (4444)
1233 * or ordered (1234, 4321, 2468) sequences. Note that quality
1234 * constants are ordered so that higher values are more restrictive.
1235 */
1236 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1237
1238 /**
1239 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001240 * password containing at least alphabetic (or other symbol) characters.
1241 * Note that quality constants are ordered so that higher values are more
1242 * restrictive.
1243 */
1244 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001245
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001246 /**
1247 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001248 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001249 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001250 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001251 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001252 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001253
Dianne Hackbornd6847842010-01-12 18:14:19 -08001254 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001255 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001256 * password containing at least a letter, a numerical digit and a special
1257 * symbol, by default. With this password quality, passwords can be
1258 * restricted to contain various sets of characters, like at least an
1259 * uppercase letter, etc. These are specified using various methods,
1260 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1261 * that quality constants are ordered so that higher values are more
1262 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001263 */
1264 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1265
1266 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001267 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1268 * modify password. In case this password quality is set, the password is
1269 * managed by a profile owner. The profile owner can set any password,
1270 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1271 * that quality constants are ordered so that higher values are more
1272 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1273 * the highest.
1274 * @hide
1275 */
1276 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1277
1278 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001279 * Called by an application that is administering the device to set the password restrictions it
1280 * is imposing. After setting this, the user will not be able to enter a new password that is
1281 * not at least as restrictive as what has been set. Note that the current password will remain
1282 * until the user has set a new one, so the change does not take place immediately. To prompt
1283 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001284 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001285 * <p>
1286 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1287 * requested quality constant (between the policy set here, the user's preference, and any other
1288 * considerations) is the one that is in effect.
1289 * <p>
1290 * The calling device admin must have requested
1291 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1292 * not, a security exception will be thrown.
1293 * <p>
1294 * This method can be called on the {@link DevicePolicyManager} instance returned by
1295 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1296 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001297 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001299 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1300 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1301 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1302 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1303 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1304 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001305 */
Robin Lee25e26452015-06-02 09:56:29 -07001306 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001307 if (mService != null) {
1308 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001309 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001310 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001311 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001312 }
1313 }
1314 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001315
Dianne Hackbornd6847842010-01-12 18:14:19 -08001316 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001317 * Retrieve the current minimum password quality for a particular admin or all admins that set
1318 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1319 * a separate challenge are not taken into account.
1320 *
1321 * <p>This method can be called on the {@link DevicePolicyManager} instance
1322 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1323 * restrictions on the parent profile.
1324 *
Robin Lee25e26452015-06-02 09:56:29 -07001325 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001326 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001327 */
Robin Lee25e26452015-06-02 09:56:29 -07001328 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001329 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001330 }
1331
1332 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001333 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001334 if (mService != null) {
1335 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001336 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001337 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001338 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001339 }
1340 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001341 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001342 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001343
Dianne Hackbornd6847842010-01-12 18:14:19 -08001344 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001345 * Called by an application that is administering the device to set the minimum allowed password
1346 * length. After setting this, the user will not be able to enter a new password that is not at
1347 * least as restrictive as what has been set. Note that the current password will remain until
1348 * the user has set a new one, so the change does not take place immediately. To prompt the user
1349 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1350 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1351 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1352 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1353 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1354 * {@link #setPasswordQuality}.
1355 * <p>
1356 * The calling device admin must have requested
1357 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1358 * not, a security exception will be thrown.
1359 * <p>
1360 * This method can be called on the {@link DevicePolicyManager} instance returned by
1361 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1362 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001363 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001365 * @param length The new desired minimum password length. A value of 0 means there is no
1366 * restriction.
1367 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1368 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001369 */
Robin Lee25e26452015-06-02 09:56:29 -07001370 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001371 if (mService != null) {
1372 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001373 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001375 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001376 }
1377 }
1378 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001379
Dianne Hackbornd6847842010-01-12 18:14:19 -08001380 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001381 * Retrieve the current minimum password length for a particular admin or all admins that set
1382 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1383 * a separate challenge are not taken into account.
1384 *
1385 * <p>This method can be called on the {@link DevicePolicyManager} instance
1386 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1387 * restrictions on the parent profile.
1388 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001389 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001390 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001391 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001392 */
Robin Lee25e26452015-06-02 09:56:29 -07001393 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001394 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001395 }
1396
1397 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001398 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001399 if (mService != null) {
1400 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001401 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001402 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001403 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001404 }
1405 }
1406 return 0;
1407 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001408
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001409 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001410 * Called by an application that is administering the device to set the minimum number of upper
1411 * case letters required in the password. After setting this, the user will not be able to enter
1412 * a new password that is not at least as restrictive as what has been set. Note that the
1413 * current password will remain until the user has set a new one, so the change does not take
1414 * place immediately. To prompt the user for a new password, use
1415 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1416 * setting this value. This constraint is only imposed if the administrator has also requested
1417 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001418 * <p>
1419 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001420 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1421 * not, a security exception will be thrown.
1422 * <p>
1423 * This method can be called on the {@link DevicePolicyManager} instance returned by
1424 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1425 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001426 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001427 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1428 * @param length The new desired minimum number of upper case letters required in the password.
1429 * A value of 0 means there is no restriction.
1430 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1431 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001432 */
Robin Lee25e26452015-06-02 09:56:29 -07001433 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001434 if (mService != null) {
1435 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001436 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001438 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001439 }
1440 }
1441 }
1442
1443 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001444 * Retrieve the current number of upper case letters required in the password
1445 * for a particular admin or all admins that set retrictions on this user and
1446 * its participating profiles. Restrictions on profiles that have a separate challenge
1447 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001448 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001449 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001450 * and only applies when the password quality is
1451 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001452 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001453 * <p>This method can be called on the {@link DevicePolicyManager} instance
1454 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1455 * restrictions on the parent profile.
1456 *
Robin Lee25e26452015-06-02 09:56:29 -07001457 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001458 * aggregate all admins.
1459 * @return The minimum number of upper case letters required in the
1460 * password.
1461 */
Robin Lee25e26452015-06-02 09:56:29 -07001462 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001463 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001464 }
1465
1466 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001467 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001468 if (mService != null) {
1469 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001470 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001471 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001472 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001473 }
1474 }
1475 return 0;
1476 }
1477
1478 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001479 * Called by an application that is administering the device to set the minimum number of lower
1480 * case letters required in the password. After setting this, the user will not be able to enter
1481 * a new password that is not at least as restrictive as what has been set. Note that the
1482 * current password will remain until the user has set a new one, so the change does not take
1483 * place immediately. To prompt the user for a new password, use
1484 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1485 * setting this value. This constraint is only imposed if the administrator has also requested
1486 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001487 * <p>
1488 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001489 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1490 * not, a security exception will be thrown.
1491 * <p>
1492 * This method can be called on the {@link DevicePolicyManager} instance returned by
1493 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1494 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001495 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001496 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1497 * @param length The new desired minimum number of lower case letters required in the password.
1498 * A value of 0 means there is no restriction.
1499 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1500 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 */
Robin Lee25e26452015-06-02 09:56:29 -07001502 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001503 if (mService != null) {
1504 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001505 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001506 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001507 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001508 }
1509 }
1510 }
1511
1512 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001513 * Retrieve the current number of lower case letters required in the password
1514 * for a particular admin or all admins that set retrictions on this user
1515 * and its participating profiles. Restrictions on profiles that have
1516 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001517 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001518 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001519 * and only applies when the password quality is
1520 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001521 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001522 * <p>This method can be called on the {@link DevicePolicyManager} instance
1523 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1524 * restrictions on the parent profile.
1525 *
Robin Lee25e26452015-06-02 09:56:29 -07001526 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001527 * aggregate all admins.
1528 * @return The minimum number of lower case letters required in the
1529 * password.
1530 */
Robin Lee25e26452015-06-02 09:56:29 -07001531 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001532 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001533 }
1534
1535 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001536 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001537 if (mService != null) {
1538 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001539 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001540 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001541 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001542 }
1543 }
1544 return 0;
1545 }
1546
1547 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001548 * Called by an application that is administering the device to set the minimum number of
1549 * letters required in the password. After setting this, the user will not be able to enter a
1550 * new password that is not at least as restrictive as what has been set. Note that the current
1551 * password will remain until the user has set a new one, so the change does not take place
1552 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1553 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1554 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1555 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001556 * <p>
1557 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001558 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1559 * not, a security exception will be thrown.
1560 * <p>
1561 * This method can be called on the {@link DevicePolicyManager} instance returned by
1562 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1563 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001564 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1566 * @param length The new desired minimum number of letters required in the password. A value of
1567 * 0 means there is no restriction.
1568 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1569 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001570 */
Robin Lee25e26452015-06-02 09:56:29 -07001571 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001572 if (mService != null) {
1573 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001574 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001575 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001576 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001577 }
1578 }
1579 }
1580
1581 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001582 * Retrieve the current number of letters required in the password
1583 * for a particular admin or all admins that set retrictions on this user
1584 * and its participating profiles. Restrictions on profiles that have
1585 * a separate challenge are not taken into account.
1586 * This is the same value as set by
1587 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001588 * and only applies when the password quality is
1589 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001590 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001591 * <p>This method can be called on the {@link DevicePolicyManager} instance
1592 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1593 * restrictions on the parent profile.
1594 *
Robin Lee25e26452015-06-02 09:56:29 -07001595 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001596 * aggregate all admins.
1597 * @return The minimum number of letters required in the password.
1598 */
Robin Lee25e26452015-06-02 09:56:29 -07001599 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001600 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001601 }
1602
1603 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001604 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001605 if (mService != null) {
1606 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001607 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001608 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001609 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001610 }
1611 }
1612 return 0;
1613 }
1614
1615 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001616 * Called by an application that is administering the device to set the minimum number of
1617 * numerical digits required in the password. After setting this, the user will not be able to
1618 * enter a new password that is not at least as restrictive as what has been set. Note that the
1619 * current password will remain until the user has set a new one, so the change does not take
1620 * place immediately. To prompt the user for a new password, use
1621 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1622 * setting this value. This constraint is only imposed if the administrator has also requested
1623 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001624 * <p>
1625 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001626 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1627 * not, a security exception will be thrown.
1628 * <p>
1629 * This method can be called on the {@link DevicePolicyManager} instance returned by
1630 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1631 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001632 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1634 * @param length The new desired minimum number of numerical digits required in the password. A
1635 * value of 0 means there is no restriction.
1636 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1637 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001638 */
Robin Lee25e26452015-06-02 09:56:29 -07001639 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001640 if (mService != null) {
1641 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001642 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001643 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001644 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001645 }
1646 }
1647 }
1648
1649 /**
1650 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001651 * for a particular admin or all admins that set retrictions on this user
1652 * and its participating profiles. Restrictions on profiles that have
1653 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001654 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001655 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001656 * and only applies when the password quality is
1657 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001658 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001659 * <p>This method can be called on the {@link DevicePolicyManager} instance
1660 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1661 * restrictions on the parent profile.
1662 *
Robin Lee25e26452015-06-02 09:56:29 -07001663 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001664 * aggregate all admins.
1665 * @return The minimum number of numerical digits required in the password.
1666 */
Robin Lee25e26452015-06-02 09:56:29 -07001667 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001668 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001669 }
1670
1671 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001672 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001673 if (mService != null) {
1674 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001675 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001676 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001677 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001678 }
1679 }
1680 return 0;
1681 }
1682
1683 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001684 * Called by an application that is administering the device to set the minimum number of
1685 * symbols required in the password. After setting this, the user will not be able to enter a
1686 * new password that is not at least as restrictive as what has been set. Note that the current
1687 * password will remain until the user has set a new one, so the change does not take place
1688 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1689 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1690 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1691 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001692 * <p>
1693 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001694 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1695 * not, a security exception will be thrown.
1696 * <p>
1697 * This method can be called on the {@link DevicePolicyManager} instance returned by
1698 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1699 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001700 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1702 * @param length The new desired minimum number of symbols required in the password. A value of
1703 * 0 means there is no restriction.
1704 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1705 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001706 */
Robin Lee25e26452015-06-02 09:56:29 -07001707 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001708 if (mService != null) {
1709 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001710 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001712 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001713 }
1714 }
1715 }
1716
1717 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001718 * Retrieve the current number of symbols required in the password
1719 * for a particular admin or all admins that set retrictions on this user
1720 * and its participating profiles. Restrictions on profiles that have
1721 * a separate challenge are not taken into account. This is the same value as
1722 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001723 * and only applies when the password quality is
1724 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001725 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001726 * <p>This method can be called on the {@link DevicePolicyManager} instance
1727 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1728 * restrictions on the parent profile.
1729 *
Robin Lee25e26452015-06-02 09:56:29 -07001730 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001731 * aggregate all admins.
1732 * @return The minimum number of symbols required in the password.
1733 */
Robin Lee25e26452015-06-02 09:56:29 -07001734 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001735 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001736 }
1737
1738 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001739 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001740 if (mService != null) {
1741 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001742 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001744 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001745 }
1746 }
1747 return 0;
1748 }
1749
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001750 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001751 * Called by an application that is administering the device to set the minimum number of
1752 * non-letter characters (numerical digits or symbols) required in the password. After setting
1753 * this, the user will not be able to enter a new password that is not at least as restrictive
1754 * as what has been set. Note that the current password will remain until the user has set a new
1755 * one, so the change does not take place immediately. To prompt the user for a new password,
1756 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1757 * setting this value. This constraint is only imposed if the administrator has also requested
1758 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001759 * <p>
1760 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001761 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1762 * not, a security exception will be thrown.
1763 * <p>
1764 * This method can be called on the {@link DevicePolicyManager} instance returned by
1765 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1766 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001767 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001768 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1769 * @param length The new desired minimum number of letters required in the password. A value of
1770 * 0 means there is no restriction.
1771 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1772 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001773 */
Robin Lee25e26452015-06-02 09:56:29 -07001774 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001775 if (mService != null) {
1776 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001777 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001778 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001779 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001780 }
1781 }
1782 }
1783
1784 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001785 * Retrieve the current number of non-letter characters required in the password
1786 * for a particular admin or all admins that set retrictions on this user
1787 * and its participating profiles. Restrictions on profiles that have
1788 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001789 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001790 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001791 * and only applies when the password quality is
1792 * {@link #PASSWORD_QUALITY_COMPLEX}.
1793 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001794 * <p>This method can be called on the {@link DevicePolicyManager} instance
1795 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1796 * restrictions on the parent profile.
1797 *
Robin Lee25e26452015-06-02 09:56:29 -07001798 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001799 * aggregate all admins.
1800 * @return The minimum number of letters required in the password.
1801 */
Robin Lee25e26452015-06-02 09:56:29 -07001802 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001803 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001804 }
1805
1806 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001807 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001808 if (mService != null) {
1809 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001810 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001811 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001812 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001813 }
1814 }
1815 return 0;
1816 }
1817
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001818 /**
1819 * Called by an application that is administering the device to set the length of the password
1820 * history. After setting this, the user will not be able to enter a new password that is the
1821 * same as any password in the history. Note that the current password will remain until the
1822 * user has set a new one, so the change does not take place immediately. To prompt the user for
1823 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1824 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1825 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1826 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1827 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1828 * <p>
1829 * The calling device admin must have requested
1830 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1831 * not, a security exception will be thrown.
1832 * <p>
1833 * This method can be called on the {@link DevicePolicyManager} instance returned by
1834 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1835 * profile.
1836 *
1837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1838 * @param length The new desired length of password history. A value of 0 means there is no
1839 * restriction.
1840 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1841 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1842 */
Robin Lee25e26452015-06-02 09:56:29 -07001843 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001844 if (mService != null) {
1845 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001846 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001848 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001849 }
1850 }
1851 }
1852
1853 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001854 * Called by a device admin to set the password expiration timeout. Calling this method will
1855 * restart the countdown for password expiration for the given admin, as will changing the
1856 * device password (for all admins).
1857 * <p>
1858 * The provided timeout is the time delta in ms and will be added to the current time. For
1859 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1860 * 432000000 ms for timeout.
1861 * <p>
1862 * To disable password expiration, a value of 0 may be used for timeout.
1863 * <p>
1864 * The calling device admin must have requested
1865 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1866 * not, a security exception will be thrown.
1867 * <p>
1868 * Note that setting the password will automatically reset the expiration time for all active
1869 * admins. Active admins do not need to explicitly call this method in that case.
1870 * <p>
1871 * This method can be called on the {@link DevicePolicyManager} instance returned by
1872 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1873 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001874 *
Jim Millera4e28d12010-11-08 16:15:47 -08001875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001876 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1877 * there is no restriction (unlimited).
1878 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1879 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001880 */
Robin Lee25e26452015-06-02 09:56:29 -07001881 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001882 if (mService != null) {
1883 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001884 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001885 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001886 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001887 }
1888 }
1889 }
1890
1891 /**
Jim Miller6b857682011-02-16 16:27:41 -08001892 * Get the password expiration timeout for the given admin. The expiration timeout is the
1893 * recurring expiration timeout provided in the call to
1894 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001895 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1896 * have set restrictions on profiles that have a separate challenge are not taken into account.
1897 *
1898 * <p>This method can be called on the {@link DevicePolicyManager} instance
1899 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1900 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001901 *
Robin Lee25e26452015-06-02 09:56:29 -07001902 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001903 * @return The timeout for the given admin or the minimum of all timeouts
1904 */
Robin Lee25e26452015-06-02 09:56:29 -07001905 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001906 if (mService != null) {
1907 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001908 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001909 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001910 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001911 }
1912 }
1913 return 0;
1914 }
1915
1916 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001917 * Get the current password expiration time for a particular admin or all admins that set
1918 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1919 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1920 * of all expiration times is returned - which will be the minimum of all of them.
1921 *
1922 * <p>This method can be called on the {@link DevicePolicyManager} instance
1923 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1924 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001925 *
Robin Lee25e26452015-06-02 09:56:29 -07001926 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001927 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001928 */
Robin Lee25e26452015-06-02 09:56:29 -07001929 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001930 if (mService != null) {
1931 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001932 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001933 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001934 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001935 }
1936 }
1937 return 0;
1938 }
1939
1940 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001941 * Retrieve the current password history length for a particular admin or all admins that
1942 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1943 * have a separate challenge are not taken into account.
1944 *
1945 * <p>This method can be called on the {@link DevicePolicyManager} instance
1946 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1947 * restrictions on the parent profile.
1948 *
Robin Lee25e26452015-06-02 09:56:29 -07001949 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001950 * all admins.
1951 * @return The length of the password history
1952 */
Robin Lee25e26452015-06-02 09:56:29 -07001953 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001954 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001955 }
1956
1957 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001958 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001959 if (mService != null) {
1960 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001961 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001962 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001963 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001964 }
1965 }
1966 return 0;
1967 }
1968
Dianne Hackbornd6847842010-01-12 18:14:19 -08001969 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001970 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001971 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001972 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001973 * @return Returns the maximum length that the user can enter.
1974 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001975 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001976 // Kind-of arbitrary.
1977 return 16;
1978 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001979
Dianne Hackborn254cb442010-01-27 19:23:59 -08001980 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001981 * Determine whether the current password the user has set is sufficient to meet the policy
1982 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
1983 * user and its participating profiles. Restrictions on profiles that have a separate challenge
1984 * are not taken into account.
1985 * <p>
1986 * The calling device admin must have requested
1987 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1988 * not, a security exception will be thrown.
1989 * <p>
1990 * This method can be called on the {@link DevicePolicyManager} instance returned by
1991 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
1992 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001993 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001994 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001995 * @throws SecurityException if the calling application does not own an active administrator
1996 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001997 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001998 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001999 if (mService != null) {
2000 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002001 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002002 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002003 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002004 }
2005 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002006 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002007 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002008
Dianne Hackbornd6847842010-01-12 18:14:19 -08002009 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002010 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002011 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002012 * requested by the admins of the parent user and its profiles.
2013 *
2014 * @param userHandle the userId of the profile to check the password for.
2015 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002016 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002017 * @hide
2018 */
2019 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2020 if (mService != null) {
2021 try {
2022 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2023 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002024 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002025 }
2026 }
2027 return false;
2028 }
2029
2030 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002031 * Retrieve the number of times the user has failed at entering a password since that last
2032 * successful password entry.
2033 * <p>
2034 * This method can be called on the {@link DevicePolicyManager} instance returned by
2035 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2036 * password attemts for the parent user.
2037 * <p>
2038 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2039 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002040 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002041 * @return The number of times user has entered an incorrect password since the last correct
2042 * password entry.
2043 * @throws SecurityException if the calling application does not own an active administrator
2044 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002045 */
2046 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002047 return getCurrentFailedPasswordAttempts(myUserId());
2048 }
2049
2050 /**
2051 * Retrieve the number of times the given user has failed at entering a
2052 * password since that last successful password entry.
2053 *
2054 * <p>The calling device admin must have requested
2055 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2056 * not and it is not the system uid, a security exception will be thrown.
2057 *
2058 * @hide
2059 */
2060 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002061 if (mService != null) {
2062 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002063 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002064 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002065 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002066 }
2067 }
2068 return -1;
2069 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002070
2071 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002072 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002073 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002074 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002075 * @hide
2076 */
2077 public boolean getDoNotAskCredentialsOnBoot() {
2078 if (mService != null) {
2079 try {
2080 return mService.getDoNotAskCredentialsOnBoot();
2081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002082 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002083 }
2084 }
2085 return false;
2086 }
2087
2088 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002089 * Setting this to a value greater than zero enables a built-in policy that will perform a
2090 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2091 * This built-in policy combines watching for failed passwords and wiping the device, and
2092 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002093 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002094 * <p>
2095 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2096 * revoking credentials, or reporting the failure to a server), you should implement
2097 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2098 * use this API, because if the maximum count is reached, the device or profile will be wiped
2099 * immediately, and your callback will not be invoked.
2100 * <p>
2101 * This method can be called on the {@link DevicePolicyManager} instance returned by
2102 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2103 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002104 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002106 * @param num The number of failed password attempts at which point the device or profile will
2107 * be wiped.
2108 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2109 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2110 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002111 */
Robin Lee25e26452015-06-02 09:56:29 -07002112 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002113 if (mService != null) {
2114 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002115 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002116 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002117 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002118 }
2119 }
2120 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002121
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002122 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002123 * Retrieve the current maximum number of login attempts that are allowed before the device
2124 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2125 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2126 * not taken into account.
2127 *
2128 * <p>This method can be called on the {@link DevicePolicyManager} instance
2129 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2130 * the value for the parent profile.
2131 *
Robin Lee25e26452015-06-02 09:56:29 -07002132 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002133 * all admins.
2134 */
Robin Lee25e26452015-06-02 09:56:29 -07002135 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002136 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002137 }
2138
2139 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002140 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002141 if (mService != null) {
2142 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002143 return mService.getMaximumFailedPasswordsForWipe(
2144 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002146 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002147 }
2148 }
2149 return 0;
2150 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002151
Dianne Hackborn254cb442010-01-27 19:23:59 -08002152 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002153 * Returns the profile with the smallest maximum failed passwords for wipe,
2154 * for the given user. So for primary user, it might return the primary or
2155 * a managed profile. For a secondary user, it would be the same as the
2156 * user passed in.
2157 * @hide Used only by Keyguard
2158 */
2159 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2160 if (mService != null) {
2161 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002162 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2163 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002165 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002166 }
2167 }
2168 return UserHandle.USER_NULL;
2169 }
2170
2171 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002172 * Flag for {@link #resetPassword}: don't allow other admins to change
2173 * the password again until the user has entered it.
2174 */
2175 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002176
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002177 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002178 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2179 * If the flag is set, the device can be booted without asking for user password.
2180 * The absence of this flag does not change the current boot requirements. This flag
2181 * can be set by the device owner only. If the app is not the device owner, the flag
2182 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2183 * device to factory defaults.
2184 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002185 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002186
2187 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002188 * Force a new device unlock password (the password needed to access the entire device, not for
2189 * individual accounts) on the user. This takes effect immediately.
2190 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002191 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002192 * device admins that are not device owner and not profile owner.
2193 * The password can now only be changed if there is currently no password set. Device owner
2194 * and profile owner can still do this.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002195 * <p>
2196 * The given password must be sufficient for the current password quality and length constraints
2197 * as returned by {@link #getPasswordQuality(ComponentName)} and
2198 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2199 * it will be rejected and false returned. Note that the password may be a stronger quality
2200 * (containing alphanumeric characters when the requested quality is only numeric), in which
2201 * case the currently active quality will be increased to match.
2202 * <p>
2203 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002204 * current password constraints allow it. <em>Note: This will not work in
2205 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2206 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2207 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002208 * <p>
2209 * The calling device admin must have requested
2210 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2211 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002212 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002213 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002214 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002215 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2216 * @return Returns true if the password was applied, or false if it is not acceptable for the
2217 * current constraints or if the user has not been decrypted yet.
2218 * @throws SecurityException if the calling application does not own an active administrator
2219 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002220 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002221 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002222 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002223 if (mService != null) {
2224 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002225 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002226 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002227 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002228 }
2229 }
2230 return false;
2231 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002232
Dianne Hackbornd6847842010-01-12 18:14:19 -08002233 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002234 * Called by an application that is administering the device to set the maximum time for user
2235 * activity until the device will lock. This limits the length that the user can set. It takes
2236 * effect immediately.
2237 * <p>
2238 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2239 * to be able to call this method; if it has not, a security exception will be thrown.
2240 * <p>
2241 * This method can be called on the {@link DevicePolicyManager} instance returned by
2242 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2243 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002244 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002246 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2247 * is no restriction.
2248 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2249 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002250 */
Robin Lee25e26452015-06-02 09:56:29 -07002251 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002252 if (mService != null) {
2253 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002254 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002255 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002256 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002257 }
2258 }
2259 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002260
Dianne Hackbornd6847842010-01-12 18:14:19 -08002261 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002262 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2263 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2264 * a separate challenge are not taken into account.
2265 *
2266 * <p>This method can be called on the {@link DevicePolicyManager} instance
2267 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2268 * restrictions on the parent profile.
2269 *
Robin Lee25e26452015-06-02 09:56:29 -07002270 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002271 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002272 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002273 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002274 */
Robin Lee25e26452015-06-02 09:56:29 -07002275 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002276 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002277 }
2278
2279 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002281 if (mService != null) {
2282 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002283 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002284 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002285 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002286 }
2287 }
2288 return 0;
2289 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002290
Dianne Hackbornd6847842010-01-12 18:14:19 -08002291 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002292 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2293 * do not have a separate timeout to lock for work challenge only.
2294 *
2295 * @hide
2296 */
2297 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2298 if (mService != null) {
2299 try {
2300 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2301 } catch (RemoteException e) {
2302 throw e.rethrowFromSystemServer();
2303 }
2304 }
2305 return 0;
2306 }
2307
2308 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002309 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2310 * this call.
2311 * <p>
2312 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2313 * to be able to call this method; if it has not, a security exception will be thrown.
2314 * <p>
2315 * This method can be called on the {@link DevicePolicyManager} instance returned by
2316 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002317 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002318 * @throws SecurityException if the calling application does not own an active administrator
2319 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002320 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002321 public void lockNow() {
2322 if (mService != null) {
2323 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002324 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002325 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002326 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002327 }
2328 }
2329 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002330
Dianne Hackbornd6847842010-01-12 18:14:19 -08002331 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002332 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002333 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002334 */
2335 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2336
2337 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002338 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2339 * data.
2340 *
Paul Crowley2934b262014-12-02 11:21:13 +00002341 * <p>This flag may only be set by device owner admins; if it is set by
2342 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002343 */
2344 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2345
2346 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002347 * Ask the user data be wiped. Wiping the primary user will cause the device to reboot, erasing
2348 * all user data while next booting up.
2349 * <p>
2350 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2351 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002352 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002353 * @param flags Bit mask of additional options: currently supported flags are
2354 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2355 * @throws SecurityException if the calling application does not own an active administrator
2356 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002357 */
2358 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002359 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002360 if (mService != null) {
2361 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002362 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002364 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002365 }
2366 }
2367 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002368
Dianne Hackbornd6847842010-01-12 18:14:19 -08002369 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002370 * Called by an application that is administering the device to set the
2371 * global proxy and exclusion list.
2372 * <p>
2373 * The calling device admin must have requested
2374 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2375 * this method; if it has not, a security exception will be thrown.
2376 * Only the first device admin can set the proxy. If a second admin attempts
2377 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002378 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002379 * be returned.
2380 * The method can be called repeatedly by the device admin alrady setting the
2381 * proxy to update the proxy and exclusion list.
2382 *
Robin Lee25e26452015-06-02 09:56:29 -07002383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002384 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2385 * Pass Proxy.NO_PROXY to reset the proxy.
2386 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002387 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2388 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002389 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002390 */
Robin Lee25e26452015-06-02 09:56:29 -07002391 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002392 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002393 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002394 if (proxySpec == null) {
2395 throw new NullPointerException();
2396 }
2397 if (mService != null) {
2398 try {
2399 String hostSpec;
2400 String exclSpec;
2401 if (proxySpec.equals(Proxy.NO_PROXY)) {
2402 hostSpec = null;
2403 exclSpec = null;
2404 } else {
2405 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2406 throw new IllegalArgumentException();
2407 }
2408 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2409 String hostName = sa.getHostName();
2410 int port = sa.getPort();
2411 StringBuilder hostBuilder = new StringBuilder();
2412 hostSpec = hostBuilder.append(hostName)
2413 .append(":").append(Integer.toString(port)).toString();
2414 if (exclusionList == null) {
2415 exclSpec = "";
2416 } else {
2417 StringBuilder listBuilder = new StringBuilder();
2418 boolean firstDomain = true;
2419 for (String exclDomain : exclusionList) {
2420 if (!firstDomain) {
2421 listBuilder = listBuilder.append(",");
2422 } else {
2423 firstDomain = false;
2424 }
2425 listBuilder = listBuilder.append(exclDomain.trim());
2426 }
2427 exclSpec = listBuilder.toString();
2428 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002429 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2430 != android.net.Proxy.PROXY_VALID)
2431 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002432 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002433 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002434 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002435 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002436 }
2437 }
2438 return null;
2439 }
2440
2441 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002442 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2443 * HTTP proxies - they are generally network dependent. However if you're doing something
2444 * unusual like general internal filtering this may be useful. On a private network where the
2445 * proxy is not accessible, you may break HTTP using this.
2446 * <p>
2447 * This method requires the caller to be the device owner.
2448 * <p>
2449 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002450 *
Jason Monk03bc9912014-05-13 09:44:57 -04002451 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2453 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2454 * {@code null} value will clear the global HTTP proxy.
2455 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002456 */
Robin Lee25e26452015-06-02 09:56:29 -07002457 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2458 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002459 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002460 if (mService != null) {
2461 try {
2462 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2463 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002464 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002465 }
2466 }
2467 }
2468
2469 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002470 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002471 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2472 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002473 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002474 */
2475 public ComponentName getGlobalProxyAdmin() {
2476 if (mService != null) {
2477 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002478 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002479 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002480 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002481 }
2482 }
2483 return null;
2484 }
2485
2486 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002487 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002488 * indicating that encryption is not supported.
2489 */
2490 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2491
2492 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002493 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002494 * indicating that encryption is supported, but is not currently active.
2495 */
2496 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2497
2498 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002499 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002500 * indicating that encryption is not currently active, but is currently
2501 * being activated. This is only reported by devices that support
2502 * encryption of data and only when the storage is currently
2503 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2504 * to become encrypted will never return this value.
2505 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002506 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002507
2508 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002509 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002510 * indicating that encryption is active.
2511 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002512 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002513
2514 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002515 * Result code for {@link #getStorageEncryptionStatus}:
2516 * indicating that encryption is active, but an encryption key has not
2517 * been set by the user.
2518 */
2519 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2520
2521 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002522 * Result code for {@link #getStorageEncryptionStatus}:
2523 * indicating that encryption is active and the encryption key is tied to the user.
2524 */
2525 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2526
2527 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002528 * Activity action: begin the process of encrypting data on the device. This activity should
2529 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2530 * After resuming from this activity, use {@link #getStorageEncryption}
2531 * to check encryption status. However, on some devices this activity may never return, as
2532 * it may trigger a reboot and in some cases a complete data wipe of the device.
2533 */
2534 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2535 public static final String ACTION_START_ENCRYPTION
2536 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002537 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002538 * Widgets are enabled in keyguard
2539 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002540 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002541
2542 /**
Jim Miller50e62182014-04-23 17:25:00 -07002543 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002544 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002545 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2546
2547 /**
2548 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2549 */
2550 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2551
2552 /**
Jim Miller50e62182014-04-23 17:25:00 -07002553 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2554 */
2555 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2556
2557 /**
2558 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2559 */
2560 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2561
2562 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002563 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002564 * (e.g. PIN/Pattern/Password).
2565 */
2566 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2567
2568 /**
Jim Miller06e34502014-07-17 14:46:05 -07002569 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2570 */
2571 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2572
2573 /**
Jim Miller35207742012-11-02 15:33:20 -07002574 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002575 */
2576 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002577
2578 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002579 * Called by an application that is administering the device to request that the storage system
2580 * be encrypted.
2581 * <p>
2582 * When multiple device administrators attempt to control device encryption, the most secure,
2583 * supported setting will always be used. If any device administrator requests device
2584 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2585 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002586 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002587 * <p>
2588 * This policy controls encryption of the secure (application data) storage area. Data written
2589 * to other storage areas may or may not be encrypted, and this policy does not require or
2590 * control the encryption of any other storage areas. There is one exception: If
2591 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2592 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2593 * written to disk within the encrypted storage area.
2594 * <p>
2595 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2596 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2597 * encryption key may not be fully secured. For maximum security, the administrator should also
2598 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002599 *
2600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2601 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002602 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002603 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2604 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2605 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2606 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2607 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002608 */
Robin Lee25e26452015-06-02 09:56:29 -07002609 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002610 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002611 if (mService != null) {
2612 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002613 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002614 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002615 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002616 }
2617 }
2618 return ENCRYPTION_STATUS_UNSUPPORTED;
2619 }
2620
2621 /**
2622 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002623 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002624 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002625 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2626 * this will return the requested encryption setting as an aggregate of all active
2627 * administrators.
2628 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002629 */
Robin Lee25e26452015-06-02 09:56:29 -07002630 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002631 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002632 if (mService != null) {
2633 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002634 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002635 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002636 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002637 }
2638 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002639 return false;
2640 }
2641
2642 /**
2643 * Called by an application that is administering the device to
2644 * determine the current encryption status of the device.
2645 *
2646 * Depending on the returned status code, the caller may proceed in different
2647 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2648 * storage system does not support encryption. If the
2649 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2650 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002651 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2652 * storage system has enabled encryption but no password is set so further action
2653 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002654 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2655 *
Robin Lee7e678712014-07-24 16:41:31 +01002656 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002657 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002658 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2659 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002660 */
2661 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002662 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002663 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002664 }
2665
2666 /** @hide per-user version */
2667 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002668 if (mService != null) {
2669 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002670 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002671 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002672 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002673 }
2674 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002675 return ENCRYPTION_STATUS_UNSUPPORTED;
2676 }
2677
2678 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00002679 * Mark a CA certificate as approved by the device user. This means that they have been notified
2680 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
2681 * keep the certificate on the device.
2682 *
2683 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
2684 * this certificate.
2685 *
2686 * @hide
2687 */
2688 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
2689 if (mService != null) {
2690 try {
2691 return mService.approveCaCert(alias, userHandle, approval);
2692 } catch (RemoteException e) {
2693 throw e.rethrowFromSystemServer();
2694 }
2695 }
2696 return false;
2697 }
2698
2699 /**
2700 * Check whether a CA certificate has been approved by the device user.
2701 *
2702 * @hide
2703 */
2704 public boolean isCaCertApproved(String alias, int userHandle) {
2705 if (mService != null) {
2706 try {
2707 return mService.isCaCertApproved(alias, userHandle);
2708 } catch (RemoteException e) {
2709 throw e.rethrowFromSystemServer();
2710 }
2711 }
2712 return false;
2713 }
2714
2715 /**
Robin Lee7e678712014-07-24 16:41:31 +01002716 * Installs the given certificate as a user CA.
2717 *
Robin Lee25e26452015-06-02 09:56:29 -07002718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2719 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002720 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002721 *
2722 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002723 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002724 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2725 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002726 */
Robin Lee25e26452015-06-02 09:56:29 -07002727 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002728 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002729 if (mService != null) {
2730 try {
Robin Lee7e678712014-07-24 16:41:31 +01002731 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002732 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002733 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002734 }
2735 }
2736 return false;
2737 }
2738
2739 /**
Robin Lee7e678712014-07-24 16:41:31 +01002740 * Uninstalls the given certificate from trusted user CAs, if present.
2741 *
Robin Lee25e26452015-06-02 09:56:29 -07002742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2743 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002744 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002745 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2746 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002747 */
Robin Lee25e26452015-06-02 09:56:29 -07002748 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002749 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002750 if (mService != null) {
2751 try {
Robin Lee306fe082014-06-19 14:04:24 +00002752 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002753 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002754 } catch (CertificateException e) {
2755 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002756 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002757 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002758 }
2759 }
2760 }
2761
2762 /**
Robin Lee7e678712014-07-24 16:41:31 +01002763 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2764 * If a user has installed any certificates by other means than device policy these will be
2765 * included too.
2766 *
Robin Lee25e26452015-06-02 09:56:29 -07002767 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2768 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002769 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002770 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2771 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002772 */
Robin Lee25e26452015-06-02 09:56:29 -07002773 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002774 List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01002775 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002776 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002777 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002778 mService.enforceCanManageCaCerts(admin);
2779 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2780 for (String alias : certStore.userAliases()) {
2781 try {
2782 certs.add(certStore.getCertificate(alias).getEncoded());
2783 } catch (CertificateException ce) {
2784 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2785 }
2786 }
2787 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002788 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002789 }
2790 }
2791 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002792 }
2793
2794 /**
Robin Lee7e678712014-07-24 16:41:31 +01002795 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2796 * means other than device policy will also be removed, except for system CA certificates.
2797 *
Robin Lee25e26452015-06-02 09:56:29 -07002798 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2799 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002800 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2801 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002802 */
Robin Lee25e26452015-06-02 09:56:29 -07002803 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002804 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01002805 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002806 try {
2807 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2808 .toArray(new String[0]));
2809 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002810 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002811 }
2812 }
2813 }
2814
2815 /**
2816 * Returns whether this certificate is installed as a trusted CA.
2817 *
Robin Lee25e26452015-06-02 09:56:29 -07002818 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2819 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002820 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002821 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2822 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002823 */
Robin Lee25e26452015-06-02 09:56:29 -07002824 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002825 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002826 if (mService != null) {
2827 try {
2828 mService.enforceCanManageCaCerts(admin);
2829 return getCaCertAlias(certBuffer) != null;
2830 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002831 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002832 } catch (CertificateException ce) {
2833 Log.w(TAG, "Could not parse certificate", ce);
2834 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002835 }
2836 return false;
2837 }
2838
2839 /**
Robin Leece3399f2016-02-24 12:08:32 +00002840 * Called by a device or profile owner, or delegated certificate installer, to install a
2841 * certificate and corresponding private key. All apps within the profile will be able to access
2842 * the certificate and use the private key, given direct user approval.
2843 *
2844 * <p>Access to the installed credentials will not be granted to the caller of this API without
2845 * direct user approval. This is for security - should a certificate installer become
2846 * compromised, certificates it had already installed will be protected.
2847 *
2848 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00002849 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002850 *
Robin Lee25e26452015-06-02 09:56:29 -07002851 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2852 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002853 * @param privKey The private key to install.
2854 * @param cert The certificate to install.
2855 * @param alias The private key alias under which to install the certificate. If a certificate
2856 * with that alias already exists, it will be overwritten.
2857 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002858 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2859 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002860 */
Robin Leefbc65642015-08-03 16:21:22 +01002861 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2862 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00002863 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00002864 }
2865
2866 /**
2867 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00002868 * certificate chain and corresponding private key for the leaf certificate. All apps within the
2869 * profile will be able to access the certificate chain and use the private key, given direct
2870 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00002871 *
Robin Leea1b290e2016-03-09 14:38:36 +00002872 * <p>The caller of this API may grant itself access to the certificate and private key
2873 * immediately, without user approval. It is a best practice not to request this unless strictly
2874 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00002875 *
2876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002877 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00002878 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00002879 * @param certs The certificate chain to install. The chain should start with the leaf
2880 * certificate and include the chain of trust in order. This will be returned by
2881 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00002882 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00002883 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00002884 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00002885 * credentials immediately. Otherwise, access to the credentials will be gated by user
2886 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00002887 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002888 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2889 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00002890 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00002891 */
2892 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00002893 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002894 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002895 try {
Rubin Xub4365912016-03-23 12:13:22 +00002896 final byte[] pemCert = Credentials.convertToPem(certs[0]);
2897 byte[] pemChain = null;
2898 if (certs.length > 1) {
2899 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
2900 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01002901 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2902 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00002903 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
2904 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002905 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002906 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01002907 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2908 Log.w(TAG, "Failed to obtain private key material", e);
2909 } catch (CertificateException | IOException e) {
2910 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002911 }
2912 return false;
2913 }
2914
2915 /**
Robin Leea1b290e2016-03-09 14:38:36 +00002916 * Called by a device or profile owner, or delegated certificate installer, to remove a
2917 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002918 *
2919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002920 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01002921 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00002922 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002923 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2924 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01002925 */
2926 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002927 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01002928 try {
2929 return mService.removeKeyPair(admin, alias);
2930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002931 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01002932 }
Robin Leefbc65642015-08-03 16:21:22 +01002933 }
2934
2935 /**
Robin Lee25e26452015-06-02 09:56:29 -07002936 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002937 * doesn't exist.
2938 */
2939 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2940 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2941 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2942 new ByteArrayInputStream(certBuffer));
2943 return new TrustedCertificateStore().getCertificateAlias(cert);
2944 }
2945
2946 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002947 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002948 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002949 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002950 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002951 * <p>
2952 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2953 * it is later cleared by calling this method with a null value or uninstallling the certificate
2954 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002955 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00002956 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2957 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002958 * supplied certificate installer package must be installed when calling this API, otherwise an
2959 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002960 *
Robin Lee25e26452015-06-02 09:56:29 -07002961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002962 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002963 * access. If {@code null} is given the current package will be cleared.
2964 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002965 */
Robin Lee25e26452015-06-02 09:56:29 -07002966 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2967 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002968 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00002969 if (mService != null) {
2970 try {
Robin Lee25e26452015-06-02 09:56:29 -07002971 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002972 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002973 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002974 }
2975 }
2976 }
2977
2978 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002979 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
2980 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002981 *
Robin Lee25e26452015-06-02 09:56:29 -07002982 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002983 * @return The package name of the current delegated certificate installer, or {@code null} if
2984 * none is set.
2985 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002986 */
Robin Lee25e26452015-06-02 09:56:29 -07002987 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002988 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00002989 if (mService != null) {
2990 try {
Robin Lee25e26452015-06-02 09:56:29 -07002991 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002993 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002994 }
2995 }
2996 return null;
2997 }
2998
2999 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003000 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003001 * specific application for the current user. This connection is automatically granted and
3002 * persisted after a reboot.
3003 * <p>
3004 * The designated package should declare a {@link android.net.VpnService} in its manifest
3005 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3006 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003007 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003008 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
3009 * remove an existing always-on VPN configuration.
3010 * @return {@code true} if the package is set as always-on VPN controller; {@code false}
3011 * otherwise.
3012 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003013 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3014 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3015 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003016 */
Robin Leeee5eb932016-04-05 16:27:15 +01003017 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3018 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003019 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003020 if (mService != null) {
3021 try {
Robin Leeee5eb932016-04-05 16:27:15 +01003022 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage)) {
3023 throw new NameNotFoundException(vpnPackage);
3024 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003025 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003026 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003027 }
3028 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003029 }
3030
3031 /**
3032 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003033 * always-on VPN connection for the current user. If there is no such package, or the always-on
3034 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003035 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003036 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3037 * is set.
3038 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003039 */
3040 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003041 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003042 if (mService != null) {
3043 try {
3044 return mService.getAlwaysOnVpnPackage(admin);
3045 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003046 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003047 }
3048 }
3049 return null;
3050 }
3051
3052 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003053 * Called by an application that is administering the device to disable all cameras on the
3054 * device, for this user. After setting this, no applications running as this user will be able
3055 * to access any cameras on the device.
3056 * <p>
3057 * If the caller is device owner, then the restriction will be applied to all users.
3058 * <p>
3059 * The calling device admin must have requested
3060 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3061 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003062 *
3063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3064 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003065 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3066 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003067 */
Robin Lee25e26452015-06-02 09:56:29 -07003068 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003069 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003070 if (mService != null) {
3071 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003072 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003073 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003074 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003075 }
3076 }
3077 }
3078
3079 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003080 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003081 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003082 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Ben Komalo2447edd2011-05-09 16:05:33 -07003083 * have disabled the camera
3084 */
Robin Lee25e26452015-06-02 09:56:29 -07003085 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003086 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003087 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003088 }
3089
3090 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003091 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003092 if (mService != null) {
3093 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003094 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003096 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003097 }
3098 }
3099 return false;
3100 }
3101
3102 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003103 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003104 * <p>
3105 * There must be only one user on the device, managed by the device owner. Otherwise a
3106 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003107 *
3108 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003109 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3110 * wasn't triggered because a previous bugreport operation is still active (either the
3111 * bugreport is still running or waiting for the user to share or decline)
3112 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3113 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003114 */
3115 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003116 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003117 if (mService != null) {
3118 try {
3119 return mService.requestBugreport(admin);
3120 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003121 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003122 }
3123 }
3124 return false;
3125 }
3126
3127 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003128 * Determine whether or not creating a guest user has been disabled for the device
3129 *
3130 * @hide
3131 */
3132 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3133 // Currently guest users can always be created if multi-user is enabled
3134 // TODO introduce a policy for guest user creation
3135 return false;
3136 }
3137
3138 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003139 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3140 * screen capture also prevents the content from being shown on display devices that do not have
3141 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3142 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003143 * <p>
3144 * The calling device admin must be a device or profile owner. If it is not, a security
3145 * exception will be thrown.
3146 * <p>
3147 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3148 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003149 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003150 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003151 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003152 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003153 */
Robin Lee25e26452015-06-02 09:56:29 -07003154 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003155 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003156 if (mService != null) {
3157 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003158 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003160 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003161 }
3162 }
3163 }
3164
3165 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003166 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003167 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003168 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003169 * have disabled screen capture.
3170 */
Robin Lee25e26452015-06-02 09:56:29 -07003171 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003172 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003173 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003174 }
3175
3176 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003177 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003178 if (mService != null) {
3179 try {
3180 return mService.getScreenCaptureDisabled(admin, userHandle);
3181 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003182 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003183 }
3184 }
3185 return false;
3186 }
3187
3188 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003189 * Called by a device owner to set whether auto time is required. If auto time is required the
3190 * user cannot set the date and time, but has to use network date and time.
3191 * <p>
3192 * Note: if auto time is required the user can still manually set the time zone.
3193 * <p>
3194 * The calling device admin must be a device owner. If it is not, a security exception will be
3195 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003196 *
3197 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3198 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003199 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003200 */
Robin Lee25e26452015-06-02 09:56:29 -07003201 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003202 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003203 if (mService != null) {
3204 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003205 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003206 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003207 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003208 }
3209 }
3210 }
3211
3212 /**
3213 * @return true if auto time is required.
3214 */
3215 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003216 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003217 if (mService != null) {
3218 try {
3219 return mService.getAutoTimeRequired();
3220 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003221 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003222 }
3223 }
3224 return false;
3225 }
3226
3227 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003228 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003229 * <p>
3230 * The system user is exempt from this policy - it is never ephemeral.
3231 * <p>
3232 * The calling device admin must be the device owner. If it is not, a security exception will be
3233 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003234 *
3235 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3236 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003237 * subsequently created users will be ephemeral.
3238 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003239 * @hide
3240 */
3241 public void setForceEphemeralUsers(
3242 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003243 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003244 if (mService != null) {
3245 try {
3246 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3247 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003248 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003249 }
3250 }
3251 }
3252
3253 /**
3254 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003255 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003256 * @hide
3257 */
3258 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003259 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003260 if (mService != null) {
3261 try {
3262 return mService.getForceEphemeralUsers(admin);
3263 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003264 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003265 }
3266 }
3267 return false;
3268 }
3269
3270 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003271 * Called by an application that is administering the device to disable keyguard customizations,
3272 * such as widgets. After setting this, keyguard features will be disabled according to the
3273 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003274 * <p>
3275 * The calling device admin must have requested
3276 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3277 * if it has not, a security exception will be thrown.
3278 * <p>
3279 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3280 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3281 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003282 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003283 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003284 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003285 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003286 * there is one, or the parent user otherwise.
3287 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3288 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003289 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003290 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3291 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003292 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3293 * profile.
3294 * <p>
3295 * Requests to disable other features on a managed profile will be ignored.
3296 * <p>
3297 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003298 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003299 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003301 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003302 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3303 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3304 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3305 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3306 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3307 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3308 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003309 */
Robin Lee25e26452015-06-02 09:56:29 -07003310 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003311 if (mService != null) {
3312 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003313 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003314 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003315 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003316 }
3317 }
3318 }
3319
3320 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003321 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003322 * admin, if specified, or all admins that set retrictions on this user and its participating
3323 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3324 *
3325 * <p>This method can be called on the {@link DevicePolicyManager} instance
3326 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3327 * restrictions on the parent profile.
3328 *
Esteban Talavera62399912016-01-11 15:37:55 +00003329 * @param admin The name of the admin component to check, or {@code null} to check whether any
3330 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003331 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3332 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003333 */
Robin Lee25e26452015-06-02 09:56:29 -07003334 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003335 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003336 }
3337
3338 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003339 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003340 if (mService != null) {
3341 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003342 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003343 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003344 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003345 }
3346 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003347 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003348 }
3349
3350 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003351 * @hide
3352 */
Robin Lee25e26452015-06-02 09:56:29 -07003353 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3354 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003355 if (mService != null) {
3356 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003357 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003358 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003359 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003360 }
3361 }
3362 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003363
Dianne Hackbornd6847842010-01-12 18:14:19 -08003364 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003365 * @hide
3366 */
Robin Lee25e26452015-06-02 09:56:29 -07003367 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003368 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003369 }
3370
3371 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003372 * @hide
3373 */
Robin Lee25e26452015-06-02 09:56:29 -07003374 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003375 if (mService != null) {
3376 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003377 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003378 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003379 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003380 }
3381 }
3382 }
3383
3384 /**
3385 * @hide
3386 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003387 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003388 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003389 if (mService != null) {
3390 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003391 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003392 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003393 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003394 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003395 }
3396 }
3397 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003398
Dianne Hackbornd6847842010-01-12 18:14:19 -08003399 /**
3400 * @hide
3401 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003402 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003403 if (mService != null) {
3404 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003405 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003406 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003407 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003408 }
3409 }
3410 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003411
Dianne Hackbornd6847842010-01-12 18:14:19 -08003412 /**
3413 * @hide
3414 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003415 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003416 if (mService != null) {
3417 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003418 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003419 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003420 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003421 }
3422 }
3423 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003424
3425 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003426 * @hide
3427 */
3428 public void reportFailedFingerprintAttempt(int userHandle) {
3429 if (mService != null) {
3430 try {
3431 mService.reportFailedFingerprintAttempt(userHandle);
3432 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003433 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003434 }
3435 }
3436 }
3437
3438 /**
3439 * @hide
3440 */
3441 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3442 if (mService != null) {
3443 try {
3444 mService.reportSuccessfulFingerprintAttempt(userHandle);
3445 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003446 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003447 }
3448 }
3449 }
3450
3451 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003452 * Should be called when keyguard has been dismissed.
3453 * @hide
3454 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003455 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003456 if (mService != null) {
3457 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003458 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003459 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003460 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003461 }
3462 }
3463 }
3464
3465 /**
3466 * Should be called when keyguard view has been shown to the user.
3467 * @hide
3468 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003469 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003470 if (mService != null) {
3471 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003472 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003473 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003474 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003475 }
3476 }
3477 }
3478
3479 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003480 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003481 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003482 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3483 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003484 * @return whether the package was successfully registered as the device owner.
3485 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003486 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003487 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003488 public boolean setDeviceOwner(ComponentName who) {
3489 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003490 }
3491
3492 /**
3493 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003494 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003495 public boolean setDeviceOwner(ComponentName who, int userId) {
3496 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003497 }
3498
3499 /**
3500 * @hide
3501 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003502 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3503 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003504 }
3505
3506 /**
3507 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003508 * Sets the given package as the device owner. The package must already be installed. There
3509 * must not already be a device owner.
3510 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3511 * this method.
3512 * Calling this after the setup phase of the primary user has completed is allowed only if
3513 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003514 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003515 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003516 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003517 * @return whether the package was successfully registered as the device owner.
3518 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003519 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003520 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003521 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003522 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003523 if (mService != null) {
3524 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003525 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003526 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003527 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003528 }
3529 }
3530 return false;
3531 }
3532
3533 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003534 * Used to determine if a particular package has been registered as a Device Owner app.
3535 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003536 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003537 * package is currently registered as the device owner app, pass in the package name from
3538 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003539 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003540 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3541 * the setup process.
3542 * @param packageName the package name of the app, to compare with the registered device owner
3543 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003544 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003545 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003546 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003547 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003548 return isDeviceOwnerAppOnCallingUser(packageName);
3549 }
3550
3551 /**
3552 * @return true if a package is registered as device owner, only when it's running on the
3553 * calling user.
3554 *
3555 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3556 * @hide
3557 */
3558 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3559 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3560 }
3561
3562 /**
3563 * @return true if a package is registered as device owner, even if it's running on a different
3564 * user.
3565 *
3566 * <p>Requires the MANAGE_USERS permission.
3567 *
3568 * @hide
3569 */
3570 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3571 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3572 }
3573
3574 /**
3575 * @return device owner component name, only when it's running on the calling user.
3576 *
3577 * @hide
3578 */
3579 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3580 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3581 }
3582
3583 /**
3584 * @return device owner component name, even if it's running on a different user.
3585 *
3586 * <p>Requires the MANAGE_USERS permission.
3587 *
3588 * @hide
3589 */
3590 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3591 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3592 }
3593
3594 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003595 if (packageName == null) {
3596 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003597 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003598 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003599 if (deviceOwner == null) {
3600 return false;
3601 }
3602 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003603 }
3604
Makoto Onukic8a5a552015-11-19 14:29:12 -08003605 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3606 if (mService != null) {
3607 try {
3608 return mService.getDeviceOwnerComponent(callingUserOnly);
3609 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003610 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003611 }
3612 }
3613 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003614 }
3615
Jason Monkb0dced82014-06-06 14:36:20 -04003616 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003617 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3618 * no device owner.
3619 *
3620 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003621 *
3622 * @hide
3623 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003624 public int getDeviceOwnerUserId() {
3625 if (mService != null) {
3626 try {
3627 return mService.getDeviceOwnerUserId();
3628 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003629 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003630 }
3631 }
3632 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003633 }
3634
3635 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003636 * Clears the current device owner. The caller must be the device owner. This function should be
3637 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3638 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003639 *
3640 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003641 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3642 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003643 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003644 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003645 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04003646 if (mService != null) {
3647 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003648 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003649 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003650 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003651 }
3652 }
3653 }
3654
Makoto Onukia52562c2015-10-01 16:12:31 -07003655 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003656 * Returns the device owner package name, only if it's running on the calling user.
3657 *
3658 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003659 *
3660 * @hide
3661 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003662 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003663 public String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003664 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003665 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3666 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003667 }
3668
3669 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003670 * @return true if the device is managed by any device owner.
3671 *
3672 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003673 *
3674 * @hide
3675 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003676 public boolean isDeviceManaged() {
3677 return getDeviceOwnerComponentOnAnyUser() != null;
3678 }
3679
3680 /**
3681 * Returns the device owner name. Note this method *will* return the device owner
3682 * name when it's running on a different user.
3683 *
3684 * <p>Requires the MANAGE_USERS permission.
3685 *
3686 * @hide
3687 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003688 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003689 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003690 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07003691 if (mService != null) {
3692 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003693 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003694 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003695 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003696 }
3697 }
3698 return null;
3699 }
Adam Connors776c5552014-01-09 10:42:56 +00003700
3701 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003702 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003703 * @deprecated Do not use
3704 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003705 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003706 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003707 @SystemApi
3708 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003709 return null;
3710 }
3711
3712 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003713 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003714 * @deprecated Do not use
3715 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003716 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003717 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003718 @SystemApi
3719 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003720 return null;
3721 }
3722
Julia Reynolds20118f12015-02-11 12:34:08 -05003723 /**
Adam Connors776c5552014-01-09 10:42:56 +00003724 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003725 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303726 * Sets the given component as an active admin and registers the package as the profile
3727 * owner for this user. The package must already be installed and there shouldn't be
3728 * an existing profile owner registered for this user. Also, this method must be called
3729 * before the user setup has been completed.
3730 * <p>
3731 * This method can only be called by system apps that hold MANAGE_USERS permission and
3732 * MANAGE_DEVICE_ADMINS permission.
3733 * @param admin The component to register as an active admin and profile owner.
3734 * @param ownerName The user-visible name of the entity that is managing this user.
3735 * @return whether the admin was successfully registered as the profile owner.
3736 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3737 * the user has already been set up.
3738 */
Justin Morey80440cc2014-07-24 09:16:35 -05003739 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003740 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303741 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003742 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303743 if (mService != null) {
3744 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003745 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303746 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003747 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303748 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003749 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303750 }
3751 }
3752 return false;
3753 }
3754
3755 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003756 * Clears the active profile owner and removes all user restrictions. The caller must be from
3757 * the same package as the active profile owner for this user, otherwise a SecurityException
3758 * will be thrown.
3759 * <p>
3760 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003761 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003762 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003763 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003764 */
Robin Lee25e26452015-06-02 09:56:29 -07003765 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003766 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003767 if (mService != null) {
3768 try {
3769 mService.clearProfileOwner(admin);
3770 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003771 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003772 }
3773 }
3774 }
3775
3776 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003777 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003778 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003779 */
3780 public boolean hasUserSetupCompleted() {
3781 if (mService != null) {
3782 try {
3783 return mService.hasUserSetupCompleted();
3784 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003785 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003786 }
3787 }
3788 return true;
3789 }
3790
3791 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003792 * @hide
3793 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003794 * already be installed. There must not already be a profile owner for this user.
3795 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3796 * this method.
3797 * Calling this after the setup phase of the specified user has completed is allowed only if:
3798 * - the caller is SYSTEM_UID.
3799 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003800 * @param admin the component name to be registered as profile owner.
3801 * @param ownerName the human readable name of the organisation associated with this DPM.
3802 * @param userHandle the userId to set the profile owner for.
3803 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003804 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3805 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003806 */
Robin Lee25e26452015-06-02 09:56:29 -07003807 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003808 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003809 if (mService != null) {
3810 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003811 if (ownerName == null) {
3812 ownerName = "";
3813 }
3814 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003815 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003816 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003817 }
3818 }
3819 return false;
3820 }
3821
3822 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003823 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003824 * <p>
3825 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003826 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003827 * <p>
3828 * If the device owner information contains only whitespaces then the message on the lock screen
3829 * will be blank and the user will not be allowed to change it.
3830 * <p>
3831 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003832 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3833 * and set a new version of this string accordingly.
3834 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003835 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003836 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003837 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003838 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003839 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003840 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003841 if (mService != null) {
3842 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003843 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003844 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003845 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003846 }
3847 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003848 }
3849
3850 /**
3851 * @return The device owner information. If it is not set returns {@code null}.
3852 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003853 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003854 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003855 if (mService != null) {
3856 try {
3857 return mService.getDeviceOwnerLockScreenInfo();
3858 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003859 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003860 }
3861 }
3862 return null;
3863 }
3864
3865 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003866 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003867 * <p>
3868 * A suspended package will not be able to start activities. Its notifications will be hidden,
3869 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
3870 * device.
3871 * <p>
3872 * The package must already be installed. If the package is uninstalled while suspended the
3873 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00003874 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003875 *
3876 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003877 * @param packageNames The package names to suspend or unsuspend.
3878 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003879 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003880 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003881 * this method.
3882 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003883 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003884 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003885 boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003886 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003887 if (mService != null) {
3888 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003889 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003890 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003891 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003892 }
3893 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003894 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003895 }
3896
3897 /**
3898 * Called by device or profile owners to determine if a package is suspended.
3899 *
3900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3901 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003902 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003903 * suspended, could not be found or an error occurred.
3904 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003905 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003906 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003907 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
3908 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003909 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003910 if (mService != null) {
3911 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003912 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003913 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003914 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003915 } catch (IllegalArgumentException ex) {
3916 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003917 }
3918 }
3919 return false;
3920 }
3921
3922 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003923 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3924 * be used. Only the profile owner can call this.
3925 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003926 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003927 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003928 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003929 */
Robin Lee25e26452015-06-02 09:56:29 -07003930 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003931 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003932 if (mService != null) {
3933 try {
3934 mService.setProfileEnabled(admin);
3935 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003936 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003937 }
3938 }
3939 }
3940
3941 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003942 * Sets the name of the profile. In the device owner case it sets the name of the user which it
3943 * is called from. Only a profile owner or device owner can call this. If this is never called
3944 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003945 *
3946 * @see #isProfileOwnerApp
3947 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07003948 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003949 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003950 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003951 */
Robin Lee25e26452015-06-02 09:56:29 -07003952 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003953 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01003954 if (mService != null) {
3955 try {
Robin Lee25e26452015-06-02 09:56:29 -07003956 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003957 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003958 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003959 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003960 }
3961 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003962
3963 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003964 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003965 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003966 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003967 *
3968 * @param packageName The package name of the app to compare with the registered profile owner.
3969 * @return Whether or not the package is registered as the profile owner.
3970 */
3971 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003972 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00003973 if (mService != null) {
3974 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003975 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003976 return profileOwner != null
3977 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003978 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003979 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003980 }
3981 }
3982 return false;
3983 }
3984
3985 /**
3986 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003987 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003988 * owner has been set for that user.
3989 * @throws IllegalArgumentException if the userId is invalid.
3990 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003991 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003992 public ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003993 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003994 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3995 }
3996
3997 /**
3998 * @see #getProfileOwner()
3999 * @hide
4000 */
4001 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004002 if (mService != null) {
4003 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004004 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004005 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004006 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004007 }
4008 }
4009 return null;
4010 }
4011
4012 /**
4013 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004014 * @return the human readable name of the organisation associated with this DPM or {@code null}
4015 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004016 * @throws IllegalArgumentException if the userId is invalid.
4017 */
4018 public String getProfileOwnerName() throws IllegalArgumentException {
4019 if (mService != null) {
4020 try {
4021 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4022 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004023 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004024 }
4025 }
4026 return null;
4027 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004028
4029 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004030 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004031 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004032 * @return the human readable name of the organisation associated with this profile owner or
4033 * null if one is not set.
4034 * @throws IllegalArgumentException if the userId is invalid.
4035 */
4036 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02004037 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004038 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004039 if (mService != null) {
4040 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004041 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004042 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004043 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004044 }
4045 }
4046 return null;
4047 }
4048
4049 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004050 * Called by a profile owner or device owner to add a default intent handler activity for
4051 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004052 * handler even if the set of potential event handlers for the intent filter changes and if the
4053 * intent preferences are reset.
4054 * <p>
4055 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4056 * When the activity is (re)installed, it is automatically reset as default intent handler for
4057 * the filter.
4058 * <p>
4059 * The calling device admin must be a profile owner or device owner. If it is not, a security
4060 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004061 *
4062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4063 * @param filter The IntentFilter for which a default handler is added.
4064 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004065 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004066 */
Robin Lee25e26452015-06-02 09:56:29 -07004067 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4068 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004069 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004070 if (mService != null) {
4071 try {
4072 mService.addPersistentPreferredActivity(admin, filter, activity);
4073 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004074 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004075 }
4076 }
4077 }
4078
4079 /**
4080 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004081 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004082 * <p>
4083 * The calling device admin must be a profile owner. If it is not, a security exception will be
4084 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004085 *
4086 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4087 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004088 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004089 */
Robin Lee25e26452015-06-02 09:56:29 -07004090 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004091 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004092 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004093 if (mService != null) {
4094 try {
4095 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4096 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004097 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004098 }
4099 }
4100 }
Robin Lee66e5d962014-04-09 16:44:21 +01004101
4102 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004103 * Called by a profile owner or device owner to grant permission to a package to manage
4104 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4105 * {@link #getApplicationRestrictions}.
4106 * <p>
4107 * This permission is persistent until it is later cleared by calling this method with a
4108 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004109 * <p>
4110 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004111 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004112 *
4113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4114 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004115 * APIs. If {@code null} is given the current package will be cleared.
4116 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004117 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004118 */
4119 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004120 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004121 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004122 if (mService != null) {
4123 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004124 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4125 throw new NameNotFoundException(packageName);
4126 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004128 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004129 }
4130 }
4131 }
4132
4133 /**
4134 * Called by a profile owner or device owner to retrieve the application restrictions managing
4135 * package for the current user, or {@code null} if none is set.
4136 *
4137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4138 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004139 * {@code null} if none is set.
4140 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004141 */
4142 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004143 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004144 if (mService != null) {
4145 try {
4146 return mService.getApplicationRestrictionsManagingPackage(admin);
4147 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004148 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004149 }
4150 }
4151 return null;
4152 }
4153
4154 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004155 * Called by any application to find out whether it has been granted permission via
4156 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4157 * for the calling user.
4158 *
4159 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4160 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004161 */
4162 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004163 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004164 if (mService != null) {
4165 try {
4166 return mService.isCallerApplicationRestrictionsManagingPackage();
4167 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004168 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004169 }
4170 }
4171 return false;
4172 }
4173
4174 /**
4175 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004176 * <p>
4177 * The caller must be a profile or device owner on that user, or the package allowed to manage
4178 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4179 * security exception will be thrown.
4180 * <p>
4181 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004182 * <ul>
4183 * <li>{@code boolean}
4184 * <li>{@code int}
4185 * <li>{@code String} or {@code String[]}
4186 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4187 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004188 * <p>
4189 * If the restrictions are not available yet, but may be applied in the near future, the caller
4190 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004191 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004192 * <p>
4193 * The application restrictions are only made visible to the target application via
4194 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4195 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004196 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004197 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004199 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004200 * @param packageName The name of the package to update restricted settings for.
4201 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004202 * set of active restrictions.
4203 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004204 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004205 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004206 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004207 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004208 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004209 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004210 if (mService != null) {
4211 try {
4212 mService.setApplicationRestrictions(admin, packageName, settings);
4213 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004214 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004215 }
4216 }
4217 }
4218
4219 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004220 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4221 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4222 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004223 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004224 * <p>
4225 * The calling device admin must have requested
4226 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4227 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004228 * <p>
4229 * This method can be called on the {@link DevicePolicyManager} instance returned by
4230 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4231 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004232 *
4233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004234 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004235 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4236 * strictly disabled according to the state of the
4237 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4238 * <p>
4239 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4240 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4241 * device admins.
4242 * <p>
4243 * Consult documentation for the specific TrustAgent to determine legal options
4244 * parameters.
4245 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4246 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004247 */
Robin Lee25e26452015-06-02 09:56:29 -07004248 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4249 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004250 if (mService != null) {
4251 try {
Tony Mak089d8402016-04-05 17:42:55 +01004252 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004254 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004255 }
4256 }
4257 }
4258
4259 /**
Jim Millere303bf42014-08-26 17:12:29 -07004260 * Gets configuration for the given trust agent based on aggregating all calls to
4261 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4262 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004263 * <p>
4264 * This method can be called on the {@link DevicePolicyManager} instance returned by
4265 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4266 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004267 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4269 * this function returns a list of configurations for all admins that declare
4270 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4271 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4272 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4273 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004274 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004275 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004276 */
Robin Lee25e26452015-06-02 09:56:29 -07004277 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4278 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004279 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004280 }
4281
4282 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004283 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4284 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004285 if (mService != null) {
4286 try {
Tony Mak089d8402016-04-05 17:42:55 +01004287 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4288 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004289 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004290 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004291 }
4292 }
Jim Millere303bf42014-08-26 17:12:29 -07004293 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004294 }
4295
4296 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004297 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4298 * managed profile will be shown in the parent profile, for incoming calls.
4299 * <p>
4300 * The calling device admin must be a profile owner. If it is not, a security exception will be
4301 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004302 *
Robin Lee25e26452015-06-02 09:56:29 -07004303 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004304 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004305 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004306 */
Robin Lee25e26452015-06-02 09:56:29 -07004307 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004308 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004309 if (mService != null) {
4310 try {
Robin Lee25e26452015-06-02 09:56:29 -07004311 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004312 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004313 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004314 }
4315 }
4316 }
4317
4318 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004319 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4320 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004321 * <p>
4322 * The calling device admin must be a profile owner. If it is not, a security exception will be
4323 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004324 *
Robin Lee25e26452015-06-02 09:56:29 -07004325 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004326 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004327 */
Robin Lee25e26452015-06-02 09:56:29 -07004328 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004329 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004330 if (mService != null) {
4331 try {
Robin Lee25e26452015-06-02 09:56:29 -07004332 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004333 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004334 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004335 }
4336 }
4337 return false;
4338 }
4339
4340 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004341 * Determine whether or not caller-Id information has been disabled.
4342 *
4343 * @param userHandle The user for whom to check the caller-id permission
4344 * @hide
4345 */
4346 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4347 if (mService != null) {
4348 try {
4349 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4350 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004351 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004352 }
4353 }
4354 return false;
4355 }
4356
4357 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004358 * Called by a profile owner of a managed profile to set whether contacts search from the
4359 * managed profile will be shown in the parent profile, for incoming calls.
4360 * <p>
4361 * The calling device admin must be a profile owner. If it is not, a security exception will be
4362 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004363 *
4364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4365 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004366 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004367 */
4368 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4369 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004370 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004371 if (mService != null) {
4372 try {
4373 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004375 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004376 }
4377 }
4378 }
4379
4380 /**
4381 * Called by a profile owner of a managed profile to determine whether or not contacts search
4382 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004383 * <p>
4384 * The calling device admin must be a profile owner. If it is not, a security exception will be
4385 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004386 *
4387 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004388 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004389 */
4390 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004391 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004392 if (mService != null) {
4393 try {
4394 return mService.getCrossProfileContactsSearchDisabled(admin);
4395 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004396 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004397 }
4398 }
4399 return false;
4400 }
4401
4402
4403 /**
4404 * Determine whether or not contacts search has been disabled.
4405 *
4406 * @param userHandle The user for whom to check the contacts search permission
4407 * @hide
4408 */
4409 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4410 if (mService != null) {
4411 try {
4412 return mService
4413 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4414 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004415 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004416 }
4417 }
4418 return false;
4419 }
4420
4421 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004422 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004423 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004424 * @hide
4425 */
4426 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004427 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004428 if (mService != null) {
4429 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004430 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4431 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004432 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004433 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004434 }
4435 }
4436 }
4437
4438 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004439 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004440 * @hide
4441 */
4442 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4443 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004444 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004445 originalIntent);
4446 }
4447
4448 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004449 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4450 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004451 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004452 * The calling device admin must be a profile owner. If it is not, a security exception will be
4453 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004454 * <p>
4455 * This API works on managed profile only.
4456 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004457 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4458 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4459 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004460 */
Robin Lee25e26452015-06-02 09:56:29 -07004461 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004462 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004463 if (mService != null) {
4464 try {
Robin Lee25e26452015-06-02 09:56:29 -07004465 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004466 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004467 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004468 }
4469 }
4470 }
4471
4472 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004473 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4474 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004475 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004476 * The calling device admin must be a profile owner. If it is not, a security exception will be
4477 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004478 * <p>
4479 * This API works on managed profile only.
4480 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004481 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4482 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004483 */
Robin Lee25e26452015-06-02 09:56:29 -07004484 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004485 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004486 if (mService != null) {
4487 try {
Robin Lee25e26452015-06-02 09:56:29 -07004488 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004489 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004490 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004491 }
4492 }
4493 return true;
4494 }
4495
4496 /**
4497 * Determine whether or not Bluetooth devices cannot access contacts.
4498 * <p>
4499 * This API works on managed profile UserHandle only.
4500 *
4501 * @param userHandle The user for whom to check the caller-id permission
4502 * @hide
4503 */
4504 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4505 if (mService != null) {
4506 try {
4507 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4508 .getIdentifier());
4509 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004510 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004511 }
4512 }
4513 return true;
4514 }
4515
4516 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004517 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004518 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4519 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004520 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004521 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004522 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004523 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004524 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004525 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4526 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004527 */
Robin Lee25e26452015-06-02 09:56:29 -07004528 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004529 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004530 if (mService != null) {
4531 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004532 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004533 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004534 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004535 }
4536 }
4537 }
4538
4539 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004540 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4541 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004542 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004543 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004545 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004546 */
Robin Lee25e26452015-06-02 09:56:29 -07004547 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004548 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004549 if (mService != null) {
4550 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004551 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004552 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004553 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004554 }
4555 }
4556 }
4557
4558 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004559 * Called by a profile or device owner to set the permitted accessibility services. When set by
4560 * a device owner or profile owner the restriction applies to all profiles of the user the
4561 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4562 * service. When zero or more packages have been added, accessiblity services that are not in
4563 * the list and not part of the system can not be enabled by the user.
4564 * <p>
4565 * Calling with a null value for the list disables the restriction so that all services can be
4566 * used, calling with an empty list only allows the builtin system's services.
4567 * <p>
4568 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004569 *
4570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4571 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004572 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4573 * accessibility services enabled, that are not in the list.
4574 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004575 */
Robin Lee25e26452015-06-02 09:56:29 -07004576 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004577 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004578 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004579 if (mService != null) {
4580 try {
4581 return mService.setPermittedAccessibilityServices(admin, packageNames);
4582 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004583 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004584 }
4585 }
4586 return false;
4587 }
4588
4589 /**
4590 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004591 * <p>
4592 * An empty list means no accessibility services except system services are allowed. Null means
4593 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004594 *
4595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4596 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004597 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004598 */
Robin Lee25e26452015-06-02 09:56:29 -07004599 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004600 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004601 if (mService != null) {
4602 try {
4603 return mService.getPermittedAccessibilityServices(admin);
4604 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004605 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004606 }
4607 }
4608 return null;
4609 }
4610
4611 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004612 * Called by the system to check if a specific accessibility service is disabled by admin.
4613 *
4614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4615 * @param packageName Accessibility service package name that needs to be checked.
4616 * @param userHandle user id the admin is running as.
4617 * @return true if the accessibility service is permitted, otherwise false.
4618 *
4619 * @hide
4620 */
4621 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4622 @NonNull String packageName, int userHandle) {
4623 if (mService != null) {
4624 try {
4625 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4626 userHandle);
4627 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004628 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004629 }
4630 }
4631 return false;
4632 }
4633
4634 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004635 * Returns the list of accessibility services permitted by the device or profiles
4636 * owners of this user.
4637 *
4638 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4639 * it will contain the intersection of the permitted lists for any device or profile
4640 * owners that apply to this user. It will also include any system accessibility services.
4641 *
4642 * @param userId which user to check for.
4643 * @return List of accessiblity service package names.
4644 * @hide
4645 */
4646 @SystemApi
4647 public List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004648 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004649 if (mService != null) {
4650 try {
4651 return mService.getPermittedAccessibilityServicesForUser(userId);
4652 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004653 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004654 }
4655 }
4656 return null;
4657 }
4658
4659 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004660 * Called by a profile or device owner to set the permitted input methods services. When set by
4661 * a device owner or profile owner the restriction applies to all profiles of the user the
4662 * device owner or profile owner is an admin for. By default the user can use any input method.
4663 * When zero or more packages have been added, input method that are not in the list and not
4664 * part of the system can not be enabled by the user. This method will fail if it is called for
4665 * a admin that is not for the foreground user or a profile of the foreground user.
4666 * <p>
4667 * Calling with a null value for the list disables the restriction so that all input methods can
4668 * be used, calling with an empty list disables all but the system's own input methods.
4669 * <p>
4670 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004671 *
4672 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4673 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004674 * @return true if setting the restriction succeeded. It will fail if there are one or more
4675 * non-system input methods currently enabled that are not in the packageNames list.
4676 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004677 */
Robin Lee25e26452015-06-02 09:56:29 -07004678 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004679 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004680 if (mService != null) {
4681 try {
4682 return mService.setPermittedInputMethods(admin, packageNames);
4683 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004684 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004685 }
4686 }
4687 return false;
4688 }
4689
4690
4691 /**
4692 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004693 * <p>
4694 * An empty list means no input methods except system input methods are allowed. Null means all
4695 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004696 *
4697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4698 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004699 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004700 */
Robin Lee25e26452015-06-02 09:56:29 -07004701 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004702 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004703 if (mService != null) {
4704 try {
4705 return mService.getPermittedInputMethods(admin);
4706 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004707 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004708 }
4709 }
4710 return null;
4711 }
4712
4713 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004714 * Called by the system to check if a specific input method is disabled by admin.
4715 *
4716 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4717 * @param packageName Input method package name that needs to be checked.
4718 * @param userHandle user id the admin is running as.
4719 * @return true if the input method is permitted, otherwise false.
4720 *
4721 * @hide
4722 */
4723 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4724 @NonNull String packageName, int userHandle) {
4725 if (mService != null) {
4726 try {
4727 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4728 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004729 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004730 }
4731 }
4732 return false;
4733 }
4734
4735 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004736 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004737 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004738 *
4739 * <p>Null means all input methods are allowed, if a non-null list is returned
4740 * it will contain the intersection of the permitted lists for any device or profile
4741 * owners that apply to this user. It will also include any system input methods.
4742 *
4743 * @return List of input method package names.
4744 * @hide
4745 */
4746 @SystemApi
4747 public List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004748 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004749 if (mService != null) {
4750 try {
4751 return mService.getPermittedInputMethodsForCurrentUser();
4752 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004753 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004754 }
4755 }
4756 return null;
4757 }
4758
4759 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004760 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4761 * currently installed it.
4762 *
4763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4764 *
4765 * @return List of package names to keep cached.
4766 * @hide
4767 */
4768 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004769 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004770 if (mService != null) {
4771 try {
4772 return mService.getKeepUninstalledPackages(admin);
4773 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004774 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004775 }
4776 }
4777 return null;
4778 }
4779
4780 /**
4781 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4782 * currently installed it.
4783 *
4784 * <p>Please note that setting this policy does not imply that specified apps will be
4785 * automatically pre-cached.</p>
4786 *
4787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4788 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004789 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004790 * @hide
4791 */
4792 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4793 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004794 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004795 if (mService != null) {
4796 try {
4797 mService.setKeepUninstalledPackages(admin, packageNames);
4798 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004799 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004800 }
4801 }
4802 }
4803
4804 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004805 * Called by a device owner to create a user with the specified name. The UserHandle returned
4806 * by this method should not be persisted as user handles are recycled as users are removed and
4807 * created. If you need to persist an identifier for this user, use
4808 * {@link UserManager#getSerialNumberForUser}.
4809 *
4810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4811 * @param name the user's name
4812 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004813 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4814 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004815 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004816 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004817 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004818 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004819 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004820 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004821 return null;
4822 }
4823
4824 /**
Jason Monk03978a42014-06-10 15:05:30 -04004825 * Called by a device owner to create a user with the specified name. The UserHandle returned
4826 * by this method should not be persisted as user handles are recycled as users are removed and
4827 * created. If you need to persist an identifier for this user, use
4828 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4829 * immediately.
4830 *
4831 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4832 * as registered as an active admin on the new user. The profile owner package will be
4833 * installed on the new user if it already is installed on the device.
4834 *
4835 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4836 * profileOwnerComponent when onEnable is called.
4837 *
4838 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4839 * @param name the user's name
4840 * @param ownerName the human readable name of the organisation associated with this DPM.
4841 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4842 * the user.
4843 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4844 * on the new user.
4845 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004846 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4847 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004848 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004849 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004850 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004851 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004852 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004853 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4854 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004855 return null;
4856 }
4857
4858 /**
phweissa92e1212016-01-25 17:14:10 +01004859 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004860 */
4861 public static final int SKIP_SETUP_WIZARD = 0x0001;
4862
4863 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004864 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4865 * ephemeral.
4866 * @hide
4867 */
4868 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4869
4870 /**
phweissa92e1212016-01-25 17:14:10 +01004871 * Called by a device owner to create a user with the specified name and a given component of
4872 * the calling package as profile owner. The UserHandle returned by this method should not be
4873 * persisted as user handles are recycled as users are removed and created. If you need to
4874 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4875 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004876 * <p>
4877 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
4878 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
4879 * be registered as an active admin on the new user. The profile owner package will be installed
4880 * on the new user.
4881 * <p>
4882 * If the adminExtras are not null, they will be stored on the device until the user is started
4883 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01004884 *
4885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4886 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004887 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004888 * same package as admin, otherwise no user is created and an
4889 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01004890 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004891 * user.
phweissa92e1212016-01-25 17:14:10 +01004892 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004893 * @see UserHandle
4894 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4895 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004896 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01004897 */
4898 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004899 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4900 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004901 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01004902 try {
phweissa92e1212016-01-25 17:14:10 +01004903 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004904 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004905 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01004906 }
phweiss343fb332016-01-25 14:48:59 +01004907 }
4908
4909 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004910 * Called by a device owner to remove a user and all associated data. The primary user can not
4911 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04004912 *
4913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4914 * @param userHandle the user to remove.
4915 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004916 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04004917 */
Robin Lee25e26452015-06-02 09:56:29 -07004918 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004919 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04004920 try {
4921 return mService.removeUser(admin, userHandle);
4922 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004923 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04004924 }
4925 }
4926
4927 /**
Jason Monk582d9112014-07-09 19:57:08 -04004928 * Called by a device owner to switch the specified user to the foreground.
4929 *
4930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4931 * @param userHandle the user to switch to; null will switch to primary.
4932 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004933 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04004934 * @see Intent#ACTION_USER_FOREGROUND
4935 */
Robin Lee25e26452015-06-02 09:56:29 -07004936 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004937 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04004938 try {
4939 return mService.switchUser(admin, userHandle);
4940 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004941 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04004942 }
4943 }
4944
4945 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004946 * Retrieves the application restrictions for a given target application running in the calling
4947 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004948 * <p>
4949 * The caller must be a profile or device owner on that user, or the package allowed to manage
4950 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4951 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004952 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004954 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004955 * @param packageName The name of the package to fetch restricted settings of.
4956 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004957 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
4958 * {@link Bundle} if no restrictions have been set.
4959 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004960 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004961 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004962 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004963 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004964 if (mService != null) {
4965 try {
4966 return mService.getApplicationRestrictions(admin, packageName);
4967 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004968 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004969 }
4970 }
4971 return null;
4972 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004973
4974 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004975 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004976 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004977 * The calling device admin must be a profile or device owner; if it is not, a security
4978 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004979 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4981 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
4982 * for the list of keys.
4983 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07004984 */
Robin Lee25e26452015-06-02 09:56:29 -07004985 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004986 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07004987 if (mService != null) {
4988 try {
4989 mService.setUserRestriction(admin, key, true);
4990 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004991 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004992 }
4993 }
4994 }
4995
4996 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004997 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004998 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004999 * The calling device admin must be a profile or device owner; if it is not, a security
5000 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005001 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5003 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5004 * for the list of keys.
5005 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005006 */
Robin Lee25e26452015-06-02 09:56:29 -07005007 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005008 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005009 if (mService != null) {
5010 try {
5011 mService.setUserRestriction(admin, key, false);
5012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005013 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005014 }
5015 }
5016 }
Adam Connors010cfd42014-04-16 12:48:13 +01005017
5018 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005019 * Called by a profile or device owner to get user restrictions set with
5020 * {@link #addUserRestriction(ComponentName, String)}.
5021 * <p>
5022 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005023 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005024 * {@link UserManager#getUserRestrictions()}.
5025 *
5026 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005027 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005028 */
5029 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005030 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005031 Bundle ret = null;
5032 if (mService != null) {
5033 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005034 ret = mService.getUserRestrictions(admin);
5035 } catch (RemoteException e) {
5036 throw e.rethrowFromSystemServer();
5037 }
5038 }
5039 return ret == null ? new Bundle() : ret;
5040 }
5041
5042 /**
5043 * Called by the system to get the user restrictions for a user.
5044 *
5045 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5046 * @param userHandle user id the admin is running as.
5047 *
5048 * @hide
5049 */
5050 public Bundle getUserRestrictionsForUser(@NonNull ComponentName admin, int userHandle) {
5051 Bundle ret = null;
5052 if (mService != null) {
5053 try {
5054 ret = mService.getUserRestrictionsForUser(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005055 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005056 throw e.rethrowFromSystemServer();
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005057 }
5058 }
5059 return ret == null ? new Bundle() : ret;
5060 }
5061
5062 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005063 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5064 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005065 *
5066 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005067 * @param packageName The name of the package to hide or unhide.
5068 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005069 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005070 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005071 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005072 */
Robin Lee25e26452015-06-02 09:56:29 -07005073 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005074 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005075 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005076 if (mService != null) {
5077 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005078 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005079 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005080 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005081 }
5082 }
5083 return false;
5084 }
5085
5086 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005087 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005088 *
5089 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005090 * @param packageName The name of the package to retrieve the hidden status of.
5091 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005092 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005093 */
Robin Lee25e26452015-06-02 09:56:29 -07005094 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005095 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005096 if (mService != null) {
5097 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005098 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005100 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005101 }
5102 }
5103 return false;
5104 }
5105
5106 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005107 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005108 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005109 *
5110 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005111 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005112 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005113 */
Robin Lee25e26452015-06-02 09:56:29 -07005114 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005115 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005116 if (mService != null) {
5117 try {
5118 mService.enableSystemApp(admin, packageName);
5119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005120 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005121 }
5122 }
5123 }
5124
5125 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005126 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5127 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005128 *
5129 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5130 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005131 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005132 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005133 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005134 */
Robin Lee25e26452015-06-02 09:56:29 -07005135 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005136 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005137 if (mService != null) {
5138 try {
5139 return mService.enableSystemAppWithIntent(admin, intent);
5140 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005141 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005142 }
5143 }
5144 return 0;
5145 }
5146
5147 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005148 * Called by a device owner or profile owner to disable account management for a specific type
5149 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005150 * <p>
5151 * The calling device admin must be a device owner or profile owner. If it is not, a security
5152 * exception will be thrown.
5153 * <p>
5154 * When account management is disabled for an account type, adding or removing an account of
5155 * that type will not be possible.
5156 * <p>
5157 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005158 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5159 * management for a specific type is disabled.
5160 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005161 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5162 * @param accountType For which account management is disabled or enabled.
5163 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005164 * enabled (false).
5165 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005166 */
Robin Lee25e26452015-06-02 09:56:29 -07005167 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005168 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005169 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005170 if (mService != null) {
5171 try {
5172 mService.setAccountManagementDisabled(admin, accountType, disabled);
5173 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005174 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005175 }
5176 }
5177 }
5178
5179 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005180 * Gets the array of accounts for which account management is disabled by the profile owner.
5181 *
5182 * <p> Account management can be disabled/enabled by calling
5183 * {@link #setAccountManagementDisabled}.
5184 *
5185 * @return a list of account types for which account management has been disabled.
5186 *
5187 * @see #setAccountManagementDisabled
5188 */
5189 public String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005190 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005191 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005192 }
5193
5194 /**
5195 * @see #getAccountTypesWithManagementDisabled()
5196 * @hide
5197 */
5198 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005199 if (mService != null) {
5200 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005201 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005203 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005204 }
5205 }
5206
5207 return null;
5208 }
justinzhang511e0d82014-03-24 16:09:24 -04005209
5210 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005211 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005212 * <p>
5213 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5214 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5215 * package list results in locked tasks belonging to those packages to be finished. This
5216 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005217 *
Jason Monkd7b86212014-06-16 13:15:38 -04005218 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005219 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005220 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005221 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005222 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5223 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005224 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005225 */
Robin Lee25e26452015-06-02 09:56:29 -07005226 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005227 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005228 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005229 if (mService != null) {
5230 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005231 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005232 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005233 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005234 }
5235 }
5236 }
5237
5238 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005239 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005240 *
5241 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005242 * @hide
5243 */
Robin Lee25e26452015-06-02 09:56:29 -07005244 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005245 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005246 if (mService != null) {
5247 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005248 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005249 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005250 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005251 }
5252 }
5253 return null;
5254 }
5255
5256 /**
5257 * This function lets the caller know whether the given component is allowed to start the
5258 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005259 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005260 */
Jason Monkd7b86212014-06-16 13:15:38 -04005261 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005262 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005263 if (mService != null) {
5264 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005265 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005266 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005267 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005268 }
5269 }
5270 return false;
5271 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005272
5273 /**
5274 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5275 * of the setting is in the correct form for the setting type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005276 * <p>
5277 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005278 * <ul>
5279 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5280 * <li>{@link Settings.Global#AUTO_TIME}</li>
5281 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005282 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005283 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005284 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005285 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5286 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5287 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5288 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5289 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005290 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005291 * <p>
5292 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005293 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005294 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5295 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5296 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005297 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005298 * <li>{@link Settings.Global#MODE_RINGER}. Use
5299 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005300 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005301 * <li>{@link Settings.Global#WIFI_ON}. Use
5302 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005303 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005304 *
5305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5306 * @param setting The name of the setting to update.
5307 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005308 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005309 */
Robin Lee25e26452015-06-02 09:56:29 -07005310 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005311 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005312 if (mService != null) {
5313 try {
5314 mService.setGlobalSetting(admin, setting, value);
5315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005316 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005317 }
5318 }
5319 }
5320
5321 /**
5322 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5323 * that the value of the setting is in the correct form for the setting type should be performed
5324 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005325 * <p>
5326 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005327 * <ul>
5328 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005329 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005330 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5331 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005332 * <p>
5333 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005334 * <ul>
5335 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5336 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005337 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5339 * @param setting The name of the setting to update.
5340 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005341 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005342 */
Robin Lee25e26452015-06-02 09:56:29 -07005343 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005344 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005345 if (mService != null) {
5346 try {
5347 mService.setSecureSetting(admin, setting, value);
5348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005349 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005350 }
5351 }
5352 }
5353
Amith Yamasanif20d6402014-05-24 15:34:37 -07005354 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005355 * Designates a specific service component as the provider for making permission requests of a
5356 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005357 * <p/>
5358 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005359 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005360 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005361 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005362 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5363 * provider previously assigned.
5364 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005365 */
Robin Lee25e26452015-06-02 09:56:29 -07005366 public void setRestrictionsProvider(@NonNull ComponentName admin,
5367 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005368 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005369 if (mService != null) {
5370 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005371 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005372 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005373 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005374 }
5375 }
5376 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005377
5378 /**
5379 * Called by profile or device owners to set the master volume mute on or off.
5380 *
5381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5382 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005383 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005384 */
Robin Lee25e26452015-06-02 09:56:29 -07005385 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005386 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005387 if (mService != null) {
5388 try {
5389 mService.setMasterVolumeMuted(admin, on);
5390 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005391 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005392 }
5393 }
5394 }
5395
5396 /**
5397 * Called by profile or device owners to check whether the master volume mute is on or off.
5398 *
5399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5400 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005401 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005402 */
Robin Lee25e26452015-06-02 09:56:29 -07005403 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005404 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005405 if (mService != null) {
5406 try {
5407 return mService.isMasterVolumeMuted(admin);
5408 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005409 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005410 }
5411 }
5412 return false;
5413 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005414
5415 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005416 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005417 *
5418 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5419 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005420 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005421 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005422 */
Robin Lee25e26452015-06-02 09:56:29 -07005423 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005424 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005425 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005426 if (mService != null) {
5427 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005428 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005429 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005430 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005431 }
5432 }
5433 }
5434
5435 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005436 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005437 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005438 * <p>
5439 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005440 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5441 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5442 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005443 *
Robin Lee25e26452015-06-02 09:56:29 -07005444 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005445 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005446 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005447 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005448 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005449 */
Robin Lee25e26452015-06-02 09:56:29 -07005450 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005451 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005452 if (mService != null) {
5453 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005454 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005455 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005456 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005457 }
5458 }
5459 return false;
5460 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005461
5462 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005463 * Called by the profile owner of a managed profile to enable widget providers from a given
5464 * package to be available in the parent profile. As a result the user will be able to add
5465 * widgets from the white-listed package running under the profile to a widget host which runs
5466 * under the parent profile, for example the home screen. Note that a package may have zero or
5467 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005468 * <p>
5469 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005470 *
5471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5472 * @param packageName The package from which widget providers are white-listed.
5473 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005474 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005475 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5476 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5477 */
Robin Lee25e26452015-06-02 09:56:29 -07005478 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005479 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005480 if (mService != null) {
5481 try {
5482 return mService.addCrossProfileWidgetProvider(admin, packageName);
5483 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005484 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005485 }
5486 }
5487 return false;
5488 }
5489
5490 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005491 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005492 * package to be available in the parent profile. For this method to take effect the package
5493 * should have been added via
5494 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005495 * <p>
5496 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005497 *
5498 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005499 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005500 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005501 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005502 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5503 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5504 */
Esteban Talavera62399912016-01-11 15:37:55 +00005505 public boolean removeCrossProfileWidgetProvider(
5506 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005507 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005508 if (mService != null) {
5509 try {
5510 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5511 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005512 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005513 }
5514 }
5515 return false;
5516 }
5517
5518 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005519 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005520 * available in the parent profile.
5521 *
5522 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5523 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005524 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5525 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005526 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005527 */
Robin Lee25e26452015-06-02 09:56:29 -07005528 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005529 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005530 if (mService != null) {
5531 try {
5532 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5533 if (providers != null) {
5534 return providers;
5535 }
5536 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005537 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005538 }
5539 }
5540 return Collections.emptyList();
5541 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005542
5543 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005544 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005545 *
5546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5547 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005548 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005549 */
Robin Lee25e26452015-06-02 09:56:29 -07005550 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005551 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005552 try {
5553 mService.setUserIcon(admin, icon);
5554 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005555 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005556 }
5557 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005558
5559 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005560 * Called by device owners to set a local system update policy. When a new policy is set,
5561 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005562 *
Robin Lee25e26452015-06-02 09:56:29 -07005563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005564 * components in the device owner package can set system update policies and the most
5565 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005566 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005567 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005568 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005569 */
Robin Lee25e26452015-06-02 09:56:29 -07005570 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005571 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005572 if (mService != null) {
5573 try {
Robin Lee25e26452015-06-02 09:56:29 -07005574 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005575 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005576 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005577 }
5578 }
5579 }
5580
5581 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005582 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005583 *
Robin Lee25e26452015-06-02 09:56:29 -07005584 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005585 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005586 public SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005587 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005588 if (mService != null) {
5589 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005590 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005591 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005592 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005593 }
5594 }
5595 return null;
5596 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005597
5598 /**
5599 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005600 * <p>
5601 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5602 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5603 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5604 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005605 *
5606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005607 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005608 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005609 * place. {@code true} otherwise.
5610 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005611 */
Robin Lee25e26452015-06-02 09:56:29 -07005612 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005613 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005614 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005615 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005616 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005617 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005618 }
5619 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005620
5621 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005622 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005623 * notifications, quick settings and other screen overlays that allow escaping from a single use
5624 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005625 *
5626 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005627 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005628 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5629 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005630 */
Robin Lee25e26452015-06-02 09:56:29 -07005631 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005632 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005633 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005634 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005635 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005636 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005637 }
5638 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005639
5640 /**
5641 * Callable by the system update service to notify device owners about pending updates.
5642 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5643 * permission.
5644 *
5645 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5646 * when the current pending update was first available. -1 if no update is available.
5647 * @hide
5648 */
5649 @SystemApi
5650 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005651 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01005652 if (mService != null) {
5653 try {
5654 mService.notifyPendingSystemUpdate(updateReceivedTime);
5655 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005656 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005657 }
5658 }
5659 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005660
5661 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005662 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005663 * requests by applications. The policy can allow for normal operation which prompts the user to
5664 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5665 * by an application. This also applies to new permissions declared by app updates. When a
5666 * permission is denied or granted this way, the effect is equivalent to setting the permission
5667 * grant state via {@link #setPermissionGrantState}.
5668 * <p/>
5669 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005670 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005671 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005672 * @param admin Which profile or device owner this request is associated with.
5673 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005674 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5675 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005676 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005677 */
Robin Lee25e26452015-06-02 09:56:29 -07005678 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005679 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005680 try {
5681 mService.setPermissionPolicy(admin, policy);
5682 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005683 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005684 }
5685 }
5686
5687 /**
5688 * Returns the current runtime permission policy set by the device or profile owner. The
5689 * default is {@link #PERMISSION_POLICY_PROMPT}.
5690 * @param admin Which profile or device owner this request is associated with.
5691 * @return the current policy for future permission requests.
5692 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005693 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005694 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005695 try {
5696 return mService.getPermissionPolicy(admin);
5697 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005698 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005699 }
5700 }
5701
5702 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005703 * Sets the grant state of a runtime permission for a specific application. The state can be
5704 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5705 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5706 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5707 * the permission is granted and the user cannot manage it through the UI. This might affect all
5708 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005709 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005710 * <p/>
5711 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5712 * the permission. It retains the previous grant, if any.
5713 * <p/>
5714 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005715 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005716 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005717 * @param admin Which profile or device owner this request is associated with.
5718 * @param packageName The application to grant or revoke a permission to.
5719 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005720 * @param grantState The permission grant state which is one of
5721 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5722 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005723 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005724 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005725 * @see #PERMISSION_GRANT_STATE_DENIED
5726 * @see #PERMISSION_GRANT_STATE_DEFAULT
5727 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005728 */
Robin Lee25e26452015-06-02 09:56:29 -07005729 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005730 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005731 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005732 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005733 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005734 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005735 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005736 }
5737 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005738
5739 /**
5740 * Returns the current grant state of a runtime permission for a specific application.
5741 *
5742 * @param admin Which profile or device owner this request is associated with.
5743 * @param packageName The application to check the grant state for.
5744 * @param permission The permission to check for.
5745 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005746 * has not set a grant state, the return value is
5747 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5748 * permission is currently granted for the package.
5749 * <p/>
5750 * If a grant state was set by the profile or device owner, then the return value will
5751 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5752 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5753 * currently denied or granted.
5754 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005755 * @see #setPermissionGrantState(ComponentName, String, String, int)
5756 * @see PackageManager#checkPermission(String, String)
5757 */
Robin Lee25e26452015-06-02 09:56:29 -07005758 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005759 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005760 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07005761 try {
5762 return mService.getPermissionGrantState(admin, packageName, permission);
5763 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005764 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005765 }
5766 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005767
5768 /**
5769 * Returns if provisioning a managed profile or device is possible or not.
5770 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5771 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005772 * @return if provisioning a managed profile or device is possible or not.
5773 * @throws IllegalArgumentException if the supplied action is not valid.
5774 */
5775 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005776 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005777 try {
5778 return mService.isProvisioningAllowed(action);
5779 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005780 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005781 }
5782 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005783
5784 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005785 * Return if this user is a managed profile of another user. An admin can become the profile
5786 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01005787 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005788 * @param admin Which profile owner this request is associated with.
5789 * @return if this user is a managed profile of another user.
5790 */
5791 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005792 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005793 try {
5794 return mService.isManagedProfile(admin);
5795 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005796 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005797 }
5798 }
5799
5800 /**
5801 * @hide
5802 * Return if this user is a system-only user. An admin can manage a device from a system only
5803 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5804 * @param admin Which device owner this request is associated with.
5805 * @return if this user is a system-only user.
5806 */
5807 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5808 try {
5809 return mService.isSystemOnlyUser(admin);
5810 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005811 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005812 }
5813 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005814
5815 /**
5816 * Called by device owner to get the MAC address of the Wi-Fi device.
5817 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005818 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005819 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5820 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5821 * <p>
5822 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5823 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005824 */
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005825 public String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005826 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005827 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005828 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005830 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005831 }
5832 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005833
5834 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005835 * Called by device owner to reboot the device. If there is an ongoing call on the device,
5836 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005837 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005838 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005839 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005840 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005841 */
5842 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005843 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005844 try {
5845 mService.reboot(admin);
5846 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005847 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005848 }
5849 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005850
5851 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005852 * Called by a device admin to set the short support message. This will be displayed to the user
5853 * in settings screens where funtionality has been disabled by the admin. The message should be
5854 * limited to a short statement such as "This setting is disabled by your administrator. Contact
5855 * someone@example.com for support." If the message is longer than 200 characters it may be
5856 * truncated.
5857 * <p>
5858 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005859 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5860 * and set a new version of this string accordingly.
5861 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005862 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005864 * @param message Short message to be displayed to the user in settings or null to clear the
5865 * existing message.
5866 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005867 */
5868 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005869 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005870 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00005871 if (mService != null) {
5872 try {
5873 mService.setShortSupportMessage(admin, message);
5874 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005875 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005876 }
5877 }
5878 }
5879
5880 /**
5881 * Called by a device admin to get the short support message.
5882 *
5883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005884 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
5885 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005886 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005887 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005888 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005889 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00005890 if (mService != null) {
5891 try {
5892 return mService.getShortSupportMessage(admin);
5893 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005894 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005895 }
5896 }
5897 return null;
5898 }
5899
5900 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005901 * Called by a device admin to set the long support message. This will be displayed to the user
5902 * in the device administators settings screen.
5903 * <p>
5904 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005905 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5906 * and set a new version of this string accordingly.
5907 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005908 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005910 * @param message Long message to be displayed to the user in settings or null to clear the
5911 * existing message.
5912 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005913 */
5914 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005915 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005916 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00005917 if (mService != null) {
5918 try {
5919 mService.setLongSupportMessage(admin, message);
5920 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005921 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005922 }
5923 }
5924 }
5925
5926 /**
5927 * Called by a device admin to get the long support message.
5928 *
5929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005930 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
5931 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005932 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005933 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005934 public CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005935 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00005936 if (mService != null) {
5937 try {
5938 return mService.getLongSupportMessage(admin);
5939 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005940 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005941 }
5942 }
5943 return null;
5944 }
5945
5946 /**
5947 * Called by the system to get the short support message.
5948 *
5949 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5950 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005951 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00005952 *
5953 * @hide
5954 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005955 public CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
5956 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00005957 if (mService != null) {
5958 try {
5959 return mService.getShortSupportMessageForUser(admin, userHandle);
5960 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005961 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005962 }
5963 }
5964 return null;
5965 }
5966
5967
5968 /**
5969 * Called by the system to get the long support message.
5970 *
5971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5972 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005973 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00005974 *
5975 * @hide
5976 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005977 public CharSequence getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00005978 if (mService != null) {
5979 try {
5980 return mService.getLongSupportMessageForUser(admin, userHandle);
5981 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005982 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005983 }
5984 }
5985 return null;
5986 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005987
5988 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005989 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5990 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01005991 *
5992 * <p>The following methods are supported for the parent instance, all other methods will
5993 * throw a SecurityException when called on the parent instance:
5994 * <ul>
5995 * <li>{@link #getPasswordQuality}</li>
5996 * <li>{@link #setPasswordQuality}</li>
5997 * <li>{@link #getPasswordMinimumLength}</li>
5998 * <li>{@link #setPasswordMinimumLength}</li>
5999 * <li>{@link #getPasswordMinimumUpperCase}</li>
6000 * <li>{@link #setPasswordMinimumUpperCase}</li>
6001 * <li>{@link #getPasswordMinimumLowerCase}</li>
6002 * <li>{@link #setPasswordMinimumLowerCase}</li>
6003 * <li>{@link #getPasswordMinimumLetters}</li>
6004 * <li>{@link #setPasswordMinimumLetters}</li>
6005 * <li>{@link #getPasswordMinimumNumeric}</li>
6006 * <li>{@link #setPasswordMinimumNumeric}</li>
6007 * <li>{@link #getPasswordMinimumSymbols}</li>
6008 * <li>{@link #setPasswordMinimumSymbols}</li>
6009 * <li>{@link #getPasswordMinimumNonLetter}</li>
6010 * <li>{@link #setPasswordMinimumNonLetter}</li>
6011 * <li>{@link #getPasswordHistoryLength}</li>
6012 * <li>{@link #setPasswordHistoryLength}</li>
6013 * <li>{@link #getPasswordExpirationTimeout}</li>
6014 * <li>{@link #setPasswordExpirationTimeout}</li>
6015 * <li>{@link #getPasswordExpiration}</li>
6016 * <li>{@link #isActivePasswordSufficient}</li>
6017 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6018 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6019 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6020 * <li>{@link #getMaximumTimeToLock}</li>
6021 * <li>{@link #setMaximumTimeToLock}</li>
6022 * <li>{@link #lockNow}</li>
6023 * <li>{@link #getKeyguardDisabledFeatures}</li>
6024 * <li>{@link #setKeyguardDisabledFeatures}</li>
6025 * <li>{@link #getTrustAgentConfiguration}</li>
6026 * <li>{@link #setTrustAgentConfiguration}</li>
6027 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006028 *
6029 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006030 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006031 */
6032 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006033 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006034 try {
6035 if (!mService.isManagedProfile(admin)) {
6036 throw new SecurityException("The current user does not have a parent profile.");
6037 }
6038 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006039 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006040 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006041 }
6042 }
6043
6044 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006045 * Called by device owner to control the security logging feature. Logging can only be
6046 * enabled on single user devices where the sole user is managed by the device owner.
6047 *
6048 * <p> Security logs contain various information intended for security auditing purposes.
6049 * See {@link SecurityEvent} for details.
6050 *
6051 * <p>There must be only one user on the device, managed by the device owner.
6052 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006053 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006054 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006055 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006056 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006057 * @see #retrieveSecurityLogs
6058 */
6059 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006060 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006061 try {
6062 mService.setSecurityLoggingEnabled(admin, enabled);
6063 } catch (RemoteException re) {
6064 throw re.rethrowFromSystemServer();
6065 }
6066 }
6067
6068 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006069 * Return whether security logging is enabled or not by the device owner.
6070 *
6071 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6072 * thrown.
6073 *
6074 * @param admin Which device owner this request is associated with.
6075 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6076 * @throws SecurityException if {@code admin} is not a device owner.
6077 */
6078 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006079 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006080 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006081 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006082 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006083 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006084 }
6085 }
6086
6087 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006088 * Called by device owner to retrieve all new security logging entries since the last call to
6089 * this API after device boots.
6090 *
6091 * <p> Access to the logs is rate limited and it will only return new logs after the device
6092 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6093 *
6094 * <p>There must be only one user on the device, managed by the device owner.
6095 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006096 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006097 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006098 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6099 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006100 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006101 */
Michal Karpinski6235a942016-03-15 12:07:23 +00006102 public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006103 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006104 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006105 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006106 if (list != null) {
6107 return list.getList();
6108 } else {
6109 // Rate limit exceeded.
6110 return null;
6111 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006112 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006113 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006114 }
6115 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006116
6117 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006118 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6119 * profile.
6120 *
6121 * @hide
6122 */
6123 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
6124 mContext.checkSelfPermission(
6125 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6126 if (!uInfo.isManagedProfile()) {
6127 throw new SecurityException("The user " + uInfo.id
6128 + " does not have a parent profile.");
6129 }
6130 return new DevicePolicyManager(mContext, true);
6131 }
6132
6133 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006134 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006135 * <p>
6136 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006137 * corruption-free during power cycles, due to hardware variations and limitations. As a result,
Michal Karpinskie0e100982016-03-30 15:02:26 +01006138 * this API is provided as best-effort and the returned logs may be empty or contain corrupted
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006139 * data. </strong>
6140 * <p>
6141 * There must be only one user on the device, managed by the device owner. Otherwise a
6142 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006143 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006144 * @param admin Which device owner this request is associated with.
6145 * @return Device logs from before the latest reboot of the system.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006146 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006147 */
Michal Karpinski6235a942016-03-15 12:07:23 +00006148 public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006149 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006150 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006151 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006152 return list.getList();
6153 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006154 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006155 }
6156 }
6157
6158 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006159 * Called by a profile owner of a managed profile to set the color used for customization. This
6160 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006161 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006162 * <p>
6163 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006164 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6165 *
6166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006167 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006168 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006169 */
6170 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006171 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006172 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006173 // always enforce alpha channel to have 100% opacity
6174 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006175 mService.setOrganizationColor(admin, color);
6176 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006177 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006178 }
6179 }
6180
6181 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006182 * @hide
6183 *
6184 * Sets the color used for customization.
6185 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006186 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006187 * @param userId which user to set the color to.
6188 * @RequiresPermission(allOf = {
6189 * Manifest.permission.MANAGE_USERS,
6190 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6191 */
6192 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6193 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006194 // always enforce alpha channel to have 100% opacity
6195 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006196 mService.setOrganizationColorForUser(color, userId);
6197 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006198 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006199 }
6200 }
6201
6202 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006203 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6204 * This color is used as background color of the confirm credentials screen for that user.
6205 *
6206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006207 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006208 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006209 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006210 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006211 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006212 try {
6213 return mService.getOrganizationColor(admin);
6214 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006215 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006216 }
6217 }
6218
6219 /**
6220 * @hide
6221 * Retrieve the customization color for a given user.
6222 *
6223 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006224 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006225 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006226 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006227 try {
6228 return mService.getOrganizationColorForUser(userHandle);
6229 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006230 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006231 }
6232 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006233
6234 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006235 * Called by a profile owner of a managed profile to set the name of the organization under
6236 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006237 * <p>
6238 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006239 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6240 * and set a new version of this string accordingly.
6241 *
6242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6243 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006244 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006245 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006246 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006247 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006248 try {
6249 mService.setOrganizationName(admin, title);
6250 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006251 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006252 }
6253 }
6254
6255 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006256 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6257 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006258 *
6259 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6260 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006261 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006262 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006263 public CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006264 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006265 try {
6266 return mService.getOrganizationName(admin);
6267 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006268 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006269 }
6270 }
6271
6272 /**
6273 * Retrieve the default title message used in the confirm credentials screen for a given user.
6274 *
6275 * @param userHandle The user id of the user we're interested in.
6276 * @return The organization name or {@code null} if none is set.
6277 *
6278 * @hide
6279 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006280 public CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006281 try {
6282 return mService.getOrganizationNameForUser(userHandle);
6283 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006284 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006285 }
6286 }
6287
6288 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006289 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6290 * return {@link #STATE_USER_UNMANAGED}
6291 * @hide
6292 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006293 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006294 @UserProvisioningState
6295 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006296 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006297 if (mService != null) {
6298 try {
6299 return mService.getUserProvisioningState();
6300 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006301 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006302 }
6303 }
6304 return STATE_USER_UNMANAGED;
6305 }
6306
6307 /**
6308 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6309 *
6310 * @param state to store
6311 * @param userHandle for user
6312 * @hide
6313 */
6314 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6315 if (mService != null) {
6316 try {
6317 mService.setUserProvisioningState(state, userHandle);
6318 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006319 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006320 }
6321 }
6322 }
6323
6324 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006325 * @hide
6326 * Indicates the entity that controls the device or profile owner. A user/profile is considered
6327 * affiliated if it is managed by the same entity as the device.
6328 *
6329 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
6330 * user/profile is considered affiliated if the following conditions are both met:
6331 * <ul>
6332 * <li>The device owner and the user's/profile's profile owner have called this method,
6333 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
6334 * and a profile owner intersect, they must have come from the same source, which means that
6335 * the device owner and profile owner are controlled by the same entity.</li>
6336 * <li>The device owner's and profile owner's package names are the same.</li>
6337 * </ul>
6338 *
6339 * @param admin Which profile or device owner this request is associated with.
6340 * @param ids A set of opaque affiliation ids.
6341 */
6342 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006343 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006344 try {
6345 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
6346 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006347 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006348 }
6349 }
6350
6351 /**
6352 * @hide
6353 * Returns whether this user/profile is affiliated with the device. See
6354 * {@link #setAffiliationIds} for the definition of affiliation.
6355 *
6356 * @return whether this user/profile is affiliated with the device.
6357 */
6358 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006359 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006360 try {
6361 return mService != null && mService.isAffiliatedUser();
6362 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006363 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006364 }
6365 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006366
6367 /**
6368 * @hide
6369 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6370 * to be started
6371 * @param packageName the package to check for
6372 * @return whether the uninstall intent for {@code packageName} is pending
6373 */
6374 public boolean isUninstallInQueue(String packageName) {
6375 try {
6376 return mService.isUninstallInQueue(packageName);
6377 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006378 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006379 }
6380 }
6381
6382 /**
6383 * @hide
6384 * @param packageName the package containing active DAs to be uninstalled
6385 */
6386 public void uninstallPackageWithActiveAdmins(String packageName) {
6387 try {
6388 mService.uninstallPackageWithActiveAdmins(packageName);
6389 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006390 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006391 }
6392 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006393
6394 private void throwIfParentInstance(String functionName) {
6395 if (mParentInstance) {
6396 throw new SecurityException(functionName + " cannot be called on the parent instance");
6397 }
6398 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006399}