blob: 45aa6b44a8f137360c8f98365dd84d5dfe57c1cf [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() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001096 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001097 }
1098
1099 /**
1100 * @see #getActiveAdmins()
1101 * @hide
1102 */
1103 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001104 if (mService != null) {
1105 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001106 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001108 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001109 }
1110 }
1111 return null;
1112 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001114 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001115 * Used by package administration code to determine if a package can be stopped
1116 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001117 * @hide
1118 */
1119 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001120 return packageHasActiveAdmins(packageName, myUserId());
1121 }
1122
1123 /**
1124 * Used by package administration code to determine if a package can be stopped
1125 * or uninstalled.
1126 * @hide
1127 */
1128 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001129 if (mService != null) {
1130 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001131 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001133 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001134 }
1135 }
1136 return false;
1137 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001138
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001139 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001140 * Remove a current administration component. This can only be called
1141 * by the application that owns the administration component; if you
1142 * try to remove someone else's component, a security exception will be
1143 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001144 *
1145 * <p>Note that the operation is not synchronous and the admin might still be active (as
1146 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001147 *
1148 * @param admin The administration compononent to remove.
1149 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001150 */
Robin Lee25e26452015-06-02 09:56:29 -07001151 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001152 if (mService != null) {
1153 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001154 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001155 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001156 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001157 }
1158 }
1159 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001160
Dianne Hackbornd6847842010-01-12 18:14:19 -08001161 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001162 * Returns true if an administrator has been granted a particular device policy. This can be
1163 * used to check whether the administrator was activated under an earlier set of policies, but
1164 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001165 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1167 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001168 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001169 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001170 */
Robin Lee25e26452015-06-02 09:56:29 -07001171 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001172 if (mService != null) {
1173 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001174 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001175 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001176 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001177 }
1178 }
1179 return false;
1180 }
1181
1182 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001183 * Returns true if the Profile Challenge is available to use for the given profile user.
1184 *
1185 * @hide
1186 */
1187 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1188 if (mService != null) {
1189 try {
1190 return mService.isSeparateProfileChallengeAllowed(userHandle);
1191 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001192 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001193 }
1194 }
1195 return false;
1196 }
1197
1198 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001199 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1200 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001201 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001202 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001203 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001204
Dianne Hackbornd6847842010-01-12 18:14:19 -08001205 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001206 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1207 * recognition technology. This implies technologies that can recognize the identity of
1208 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1209 * Note that quality constants are ordered so that higher values are more restrictive.
1210 */
1211 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1212
1213 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001214 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001215 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001216 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001217 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001218 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001219
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001220 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001221 * Constant for {@link #setPasswordQuality}: the user must have entered a
1222 * password containing at least numeric characters. Note that quality
1223 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001224 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001225 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001226
Dianne Hackbornd6847842010-01-12 18:14:19 -08001227 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001228 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001229 * password containing at least numeric characters with no repeating (4444)
1230 * or ordered (1234, 4321, 2468) sequences. Note that quality
1231 * constants are ordered so that higher values are more restrictive.
1232 */
1233 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1234
1235 /**
1236 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001237 * password containing at least alphabetic (or other symbol) characters.
1238 * Note that quality constants are ordered so that higher values are more
1239 * restrictive.
1240 */
1241 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001242
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001243 /**
1244 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001245 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001246 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001247 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001248 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001249 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001250
Dianne Hackbornd6847842010-01-12 18:14:19 -08001251 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001253 * password containing at least a letter, a numerical digit and a special
1254 * symbol, by default. With this password quality, passwords can be
1255 * restricted to contain various sets of characters, like at least an
1256 * uppercase letter, etc. These are specified using various methods,
1257 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1258 * that quality constants are ordered so that higher values are more
1259 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 */
1261 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1262
1263 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001264 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1265 * modify password. In case this password quality is set, the password is
1266 * managed by a profile owner. The profile owner can set any password,
1267 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1268 * that quality constants are ordered so that higher values are more
1269 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1270 * the highest.
1271 * @hide
1272 */
1273 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1274
1275 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001276 * Called by an application that is administering the device to set the password restrictions it
1277 * is imposing. After setting this, the user will not be able to enter a new password that is
1278 * not at least as restrictive as what has been set. Note that the current password will remain
1279 * until the user has set a new one, so the change does not take place immediately. To prompt
1280 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001281 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001282 * <p>
1283 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1284 * requested quality constant (between the policy set here, the user's preference, and any other
1285 * considerations) is the one that is in effect.
1286 * <p>
1287 * The calling device admin must have requested
1288 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1289 * not, a security exception will be thrown.
1290 * <p>
1291 * This method can be called on the {@link DevicePolicyManager} instance returned by
1292 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1293 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001294 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001295 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001296 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1297 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1298 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1299 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1300 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1301 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001302 */
Robin Lee25e26452015-06-02 09:56:29 -07001303 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001304 if (mService != null) {
1305 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001306 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001307 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001308 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001309 }
1310 }
1311 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001312
Dianne Hackbornd6847842010-01-12 18:14:19 -08001313 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001314 * Retrieve the current minimum password quality for a particular admin or all admins that set
1315 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1316 * a separate challenge are not taken into account.
1317 *
1318 * <p>This method can be called on the {@link DevicePolicyManager} instance
1319 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1320 * restrictions on the parent profile.
1321 *
Robin Lee25e26452015-06-02 09:56:29 -07001322 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001323 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001324 */
Robin Lee25e26452015-06-02 09:56:29 -07001325 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001326 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001327 }
1328
1329 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001330 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001331 if (mService != null) {
1332 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001333 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001334 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001335 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001336 }
1337 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001338 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001339 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001340
Dianne Hackbornd6847842010-01-12 18:14:19 -08001341 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001342 * Called by an application that is administering the device to set the minimum allowed password
1343 * length. After setting this, the user will not be able to enter a new password that is not at
1344 * least as restrictive as what has been set. Note that the current password will remain until
1345 * the user has set a new one, so the change does not take place immediately. To prompt the user
1346 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1347 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1348 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1349 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1350 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1351 * {@link #setPasswordQuality}.
1352 * <p>
1353 * The calling device admin must have requested
1354 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1355 * not, a security exception will be thrown.
1356 * <p>
1357 * This method can be called on the {@link DevicePolicyManager} instance returned by
1358 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1359 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001360 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001361 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001362 * @param length The new desired minimum password length. A value of 0 means there is no
1363 * restriction.
1364 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1365 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001366 */
Robin Lee25e26452015-06-02 09:56:29 -07001367 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001368 if (mService != null) {
1369 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001370 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001371 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001372 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001373 }
1374 }
1375 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001376
Dianne Hackbornd6847842010-01-12 18:14:19 -08001377 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001378 * Retrieve the current minimum password length for a particular admin or all admins that set
1379 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1380 * a separate challenge are not taken into account.
1381 *
1382 * <p>This method can be called on the {@link DevicePolicyManager} instance
1383 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1384 * restrictions on the parent profile.
1385 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001386 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001387 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001388 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001389 */
Robin Lee25e26452015-06-02 09:56:29 -07001390 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001391 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001392 }
1393
1394 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001395 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001396 if (mService != null) {
1397 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001398 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001400 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001401 }
1402 }
1403 return 0;
1404 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001405
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001406 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001407 * Called by an application that is administering the device to set the minimum number of upper
1408 * case letters required in the password. After setting this, the user will not be able to enter
1409 * a new password that is not at least as restrictive as what has been set. Note that the
1410 * current password will remain until the user has set a new one, so the change does not take
1411 * place immediately. To prompt the user for a new password, use
1412 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1413 * setting this value. This constraint is only imposed if the administrator has also requested
1414 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001415 * <p>
1416 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001417 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1418 * not, a security exception will be thrown.
1419 * <p>
1420 * This method can be called on the {@link DevicePolicyManager} instance returned by
1421 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1422 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001423 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001424 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1425 * @param length The new desired minimum number of upper case letters required in the password.
1426 * A value of 0 means there is no restriction.
1427 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1428 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001429 */
Robin Lee25e26452015-06-02 09:56:29 -07001430 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001431 if (mService != null) {
1432 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001433 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001434 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001435 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001436 }
1437 }
1438 }
1439
1440 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001441 * Retrieve the current number of upper case letters required in the password
1442 * for a particular admin or all admins that set retrictions on this user and
1443 * its participating profiles. Restrictions on profiles that have a separate challenge
1444 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001445 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001446 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001447 * and only applies when the password quality is
1448 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001449 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001450 * <p>This method can be called on the {@link DevicePolicyManager} instance
1451 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1452 * restrictions on the parent profile.
1453 *
Robin Lee25e26452015-06-02 09:56:29 -07001454 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001455 * aggregate all admins.
1456 * @return The minimum number of upper case letters required in the
1457 * password.
1458 */
Robin Lee25e26452015-06-02 09:56:29 -07001459 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001460 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001461 }
1462
1463 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001464 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001465 if (mService != null) {
1466 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001467 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001468 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001469 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001470 }
1471 }
1472 return 0;
1473 }
1474
1475 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001476 * Called by an application that is administering the device to set the minimum number of lower
1477 * case letters required in the password. After setting this, the user will not be able to enter
1478 * a new password that is not at least as restrictive as what has been set. Note that the
1479 * current password will remain until the user has set a new one, so the change does not take
1480 * place immediately. To prompt the user for a new password, use
1481 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1482 * setting this value. This constraint is only imposed if the administrator has also requested
1483 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001484 * <p>
1485 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001486 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1487 * not, a security exception will be thrown.
1488 * <p>
1489 * This method can be called on the {@link DevicePolicyManager} instance returned by
1490 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1491 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001492 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1494 * @param length The new desired minimum number of lower case letters required in the password.
1495 * A value of 0 means there is no restriction.
1496 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1497 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001498 */
Robin Lee25e26452015-06-02 09:56:29 -07001499 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001500 if (mService != null) {
1501 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001502 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001504 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001505 }
1506 }
1507 }
1508
1509 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001510 * Retrieve the current number of lower case letters required in the password
1511 * for a particular admin or all admins that set retrictions on this user
1512 * and its participating profiles. Restrictions on profiles that have
1513 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001514 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001515 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001516 * and only applies when the password quality is
1517 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001518 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001519 * <p>This method can be called on the {@link DevicePolicyManager} instance
1520 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1521 * restrictions on the parent profile.
1522 *
Robin Lee25e26452015-06-02 09:56:29 -07001523 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001524 * aggregate all admins.
1525 * @return The minimum number of lower case letters required in the
1526 * password.
1527 */
Robin Lee25e26452015-06-02 09:56:29 -07001528 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001529 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001530 }
1531
1532 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001533 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001534 if (mService != null) {
1535 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001536 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001537 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001538 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001539 }
1540 }
1541 return 0;
1542 }
1543
1544 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001545 * Called by an application that is administering the device to set the minimum number of
1546 * letters required in the password. After setting this, the user will not be able to enter a
1547 * new password that is not at least as restrictive as what has been set. Note that the current
1548 * password will remain until the user has set a new one, so the change does not take place
1549 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1550 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1551 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1552 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001553 * <p>
1554 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001555 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1556 * not, a security exception will be thrown.
1557 * <p>
1558 * This method can be called on the {@link DevicePolicyManager} instance returned by
1559 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1560 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001561 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001562 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1563 * @param length The new desired minimum number of letters required in the password. A value of
1564 * 0 means there is no restriction.
1565 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1566 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001567 */
Robin Lee25e26452015-06-02 09:56:29 -07001568 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001569 if (mService != null) {
1570 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001571 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001572 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001573 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001574 }
1575 }
1576 }
1577
1578 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001579 * Retrieve the current number of letters required in the password
1580 * for a particular admin or all admins that set retrictions on this user
1581 * and its participating profiles. Restrictions on profiles that have
1582 * a separate challenge are not taken into account.
1583 * This is the same value as set by
1584 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001585 * and only applies when the password quality is
1586 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001587 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001588 * <p>This method can be called on the {@link DevicePolicyManager} instance
1589 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1590 * restrictions on the parent profile.
1591 *
Robin Lee25e26452015-06-02 09:56:29 -07001592 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001593 * aggregate all admins.
1594 * @return The minimum number of letters required in the password.
1595 */
Robin Lee25e26452015-06-02 09:56:29 -07001596 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001597 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001598 }
1599
1600 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001601 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001602 if (mService != null) {
1603 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001604 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001605 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001606 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001607 }
1608 }
1609 return 0;
1610 }
1611
1612 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001613 * Called by an application that is administering the device to set the minimum number of
1614 * numerical digits required in the password. After setting this, the user will not be able to
1615 * enter a new password that is not at least as restrictive as what has been set. Note that the
1616 * current password will remain until the user has set a new one, so the change does not take
1617 * place immediately. To prompt the user for a new password, use
1618 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1619 * setting this value. This constraint is only imposed if the administrator has also requested
1620 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001621 * <p>
1622 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001623 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1624 * not, a security exception will be thrown.
1625 * <p>
1626 * This method can be called on the {@link DevicePolicyManager} instance returned by
1627 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1628 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001629 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1631 * @param length The new desired minimum number of numerical digits required in the password. A
1632 * value of 0 means there is no restriction.
1633 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1634 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001635 */
Robin Lee25e26452015-06-02 09:56:29 -07001636 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001637 if (mService != null) {
1638 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001639 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001640 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001641 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001642 }
1643 }
1644 }
1645
1646 /**
1647 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001648 * for a particular admin or all admins that set retrictions on this user
1649 * and its participating profiles. Restrictions on profiles that have
1650 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001651 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001652 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001653 * and only applies when the password quality is
1654 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001655 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001656 * <p>This method can be called on the {@link DevicePolicyManager} instance
1657 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1658 * restrictions on the parent profile.
1659 *
Robin Lee25e26452015-06-02 09:56:29 -07001660 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001661 * aggregate all admins.
1662 * @return The minimum number of numerical digits required in the password.
1663 */
Robin Lee25e26452015-06-02 09:56:29 -07001664 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001665 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001666 }
1667
1668 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001669 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001670 if (mService != null) {
1671 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001672 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001673 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001674 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001675 }
1676 }
1677 return 0;
1678 }
1679
1680 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001681 * Called by an application that is administering the device to set the minimum number of
1682 * symbols required in the password. After setting this, the user will not be able to enter a
1683 * new password that is not at least as restrictive as what has been set. Note that the current
1684 * password will remain until the user has set a new one, so the change does not take place
1685 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1686 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1687 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1688 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001689 * <p>
1690 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001691 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1692 * not, a security exception will be thrown.
1693 * <p>
1694 * This method can be called on the {@link DevicePolicyManager} instance returned by
1695 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1696 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001697 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001698 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1699 * @param length The new desired minimum number of symbols required in the password. A value of
1700 * 0 means there is no restriction.
1701 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1702 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001705 if (mService != null) {
1706 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001707 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001709 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001710 }
1711 }
1712 }
1713
1714 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001715 * Retrieve the current number of symbols required in the password
1716 * for a particular admin or all admins that set retrictions on this user
1717 * and its participating profiles. Restrictions on profiles that have
1718 * a separate challenge are not taken into account. This is the same value as
1719 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001720 * and only applies when the password quality is
1721 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001722 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001723 * <p>This method can be called on the {@link DevicePolicyManager} instance
1724 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1725 * restrictions on the parent profile.
1726 *
Robin Lee25e26452015-06-02 09:56:29 -07001727 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001728 * aggregate all admins.
1729 * @return The minimum number of symbols required in the password.
1730 */
Robin Lee25e26452015-06-02 09:56:29 -07001731 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001732 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001733 }
1734
1735 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001736 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001737 if (mService != null) {
1738 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001739 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001740 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001741 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001742 }
1743 }
1744 return 0;
1745 }
1746
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001747 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001748 * Called by an application that is administering the device to set the minimum number of
1749 * non-letter characters (numerical digits or symbols) required in the password. After setting
1750 * this, the user will not be able to enter a new password that is not at least as restrictive
1751 * as what has been set. Note that the current password will remain until the user has set a new
1752 * one, so the change does not take place immediately. To prompt the user for a new password,
1753 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1754 * setting this value. This constraint is only imposed if the administrator has also requested
1755 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001756 * <p>
1757 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001758 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1759 * not, a security exception will be thrown.
1760 * <p>
1761 * This method can be called on the {@link DevicePolicyManager} instance returned by
1762 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1763 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001764 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1766 * @param length The new desired minimum number of letters required in the password. A value of
1767 * 0 means there is no restriction.
1768 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1769 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001770 */
Robin Lee25e26452015-06-02 09:56:29 -07001771 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001772 if (mService != null) {
1773 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001774 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001776 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001777 }
1778 }
1779 }
1780
1781 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001782 * Retrieve the current number of non-letter characters required in the password
1783 * for a particular admin or all admins that set retrictions on this user
1784 * and its participating profiles. Restrictions on profiles that have
1785 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001786 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001787 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001788 * and only applies when the password quality is
1789 * {@link #PASSWORD_QUALITY_COMPLEX}.
1790 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001791 * <p>This method can be called on the {@link DevicePolicyManager} instance
1792 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1793 * restrictions on the parent profile.
1794 *
Robin Lee25e26452015-06-02 09:56:29 -07001795 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001796 * aggregate all admins.
1797 * @return The minimum number of letters required in the password.
1798 */
Robin Lee25e26452015-06-02 09:56:29 -07001799 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001800 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001801 }
1802
1803 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001804 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001805 if (mService != null) {
1806 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001807 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001809 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001810 }
1811 }
1812 return 0;
1813 }
1814
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001815 /**
1816 * Called by an application that is administering the device to set the length of the password
1817 * history. After setting this, the user will not be able to enter a new password that is the
1818 * same as any password in the history. Note that the current password will remain until the
1819 * user has set a new one, so the change does not take place immediately. To prompt the user for
1820 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1821 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1822 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1823 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1824 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1825 * <p>
1826 * The calling device admin must have requested
1827 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1828 * not, a security exception will be thrown.
1829 * <p>
1830 * This method can be called on the {@link DevicePolicyManager} instance returned by
1831 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1832 * profile.
1833 *
1834 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1835 * @param length The new desired length of password history. A value of 0 means there is no
1836 * restriction.
1837 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1838 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1839 */
Robin Lee25e26452015-06-02 09:56:29 -07001840 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001841 if (mService != null) {
1842 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001843 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001844 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001845 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001846 }
1847 }
1848 }
1849
1850 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001851 * Called by a device admin to set the password expiration timeout. Calling this method will
1852 * restart the countdown for password expiration for the given admin, as will changing the
1853 * device password (for all admins).
1854 * <p>
1855 * The provided timeout is the time delta in ms and will be added to the current time. For
1856 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1857 * 432000000 ms for timeout.
1858 * <p>
1859 * To disable password expiration, a value of 0 may be used for timeout.
1860 * <p>
1861 * The calling device admin must have requested
1862 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1863 * not, a security exception will be thrown.
1864 * <p>
1865 * Note that setting the password will automatically reset the expiration time for all active
1866 * admins. Active admins do not need to explicitly call this method in that case.
1867 * <p>
1868 * This method can be called on the {@link DevicePolicyManager} instance returned by
1869 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1870 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001871 *
Jim Millera4e28d12010-11-08 16:15:47 -08001872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001873 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1874 * there is no restriction (unlimited).
1875 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1876 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001877 */
Robin Lee25e26452015-06-02 09:56:29 -07001878 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001879 if (mService != null) {
1880 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001881 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001882 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001883 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001884 }
1885 }
1886 }
1887
1888 /**
Jim Miller6b857682011-02-16 16:27:41 -08001889 * Get the password expiration timeout for the given admin. The expiration timeout is the
1890 * recurring expiration timeout provided in the call to
1891 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001892 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1893 * have set restrictions on profiles that have a separate challenge are not taken into account.
1894 *
1895 * <p>This method can be called on the {@link DevicePolicyManager} instance
1896 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1897 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001898 *
Robin Lee25e26452015-06-02 09:56:29 -07001899 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001900 * @return The timeout for the given admin or the minimum of all timeouts
1901 */
Robin Lee25e26452015-06-02 09:56:29 -07001902 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001903 if (mService != null) {
1904 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001905 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001906 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001907 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001908 }
1909 }
1910 return 0;
1911 }
1912
1913 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001914 * Get the current password expiration time for a particular admin or all admins that set
1915 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1916 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1917 * of all expiration times is returned - which will be the minimum of all of them.
1918 *
1919 * <p>This method can be called on the {@link DevicePolicyManager} instance
1920 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1921 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001922 *
Robin Lee25e26452015-06-02 09:56:29 -07001923 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001924 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001925 */
Robin Lee25e26452015-06-02 09:56:29 -07001926 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001927 if (mService != null) {
1928 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001929 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001931 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001932 }
1933 }
1934 return 0;
1935 }
1936
1937 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001938 * Retrieve the current password history length for a particular admin or all admins that
1939 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1940 * have a separate challenge are not taken into account.
1941 *
1942 * <p>This method can be called on the {@link DevicePolicyManager} instance
1943 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1944 * restrictions on the parent profile.
1945 *
Robin Lee25e26452015-06-02 09:56:29 -07001946 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001947 * all admins.
1948 * @return The length of the password history
1949 */
Robin Lee25e26452015-06-02 09:56:29 -07001950 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001951 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001952 }
1953
1954 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001955 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001956 if (mService != null) {
1957 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001958 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001959 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001960 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001961 }
1962 }
1963 return 0;
1964 }
1965
Dianne Hackbornd6847842010-01-12 18:14:19 -08001966 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001967 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001968 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001969 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001970 * @return Returns the maximum length that the user can enter.
1971 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001972 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001973 // Kind-of arbitrary.
1974 return 16;
1975 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001976
Dianne Hackborn254cb442010-01-27 19:23:59 -08001977 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001978 * Determine whether the current password the user has set is sufficient to meet the policy
1979 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
1980 * user and its participating profiles. Restrictions on profiles that have a separate challenge
1981 * are not taken into account.
1982 * <p>
1983 * The calling device admin must have requested
1984 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1985 * not, a security exception will be thrown.
1986 * <p>
1987 * This method can be called on the {@link DevicePolicyManager} instance returned by
1988 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
1989 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001990 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001991 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001992 * @throws SecurityException if the calling application does not own an active administrator
1993 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001994 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001995 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001996 if (mService != null) {
1997 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001998 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001999 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002000 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002001 }
2002 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002003 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002004 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002005
Dianne Hackbornd6847842010-01-12 18:14:19 -08002006 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002007 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002008 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002009 * requested by the admins of the parent user and its profiles.
2010 *
2011 * @param userHandle the userId of the profile to check the password for.
2012 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002013 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002014 * @hide
2015 */
2016 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2017 if (mService != null) {
2018 try {
2019 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002021 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002022 }
2023 }
2024 return false;
2025 }
2026
2027 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002028 * Retrieve the number of times the user has failed at entering a password since that last
2029 * successful password entry.
2030 * <p>
2031 * This method can be called on the {@link DevicePolicyManager} instance returned by
2032 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2033 * password attemts for the parent user.
2034 * <p>
2035 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2036 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002037 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002038 * @return The number of times user has entered an incorrect password since the last correct
2039 * password entry.
2040 * @throws SecurityException if the calling application does not own an active administrator
2041 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002042 */
2043 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002044 return getCurrentFailedPasswordAttempts(myUserId());
2045 }
2046
2047 /**
2048 * Retrieve the number of times the given user has failed at entering a
2049 * password since that last successful password entry.
2050 *
2051 * <p>The calling device admin must have requested
2052 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2053 * not and it is not the system uid, a security exception will be thrown.
2054 *
2055 * @hide
2056 */
2057 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002058 if (mService != null) {
2059 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002060 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002061 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002062 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002063 }
2064 }
2065 return -1;
2066 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002067
2068 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002069 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002070 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002071 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002072 * @hide
2073 */
2074 public boolean getDoNotAskCredentialsOnBoot() {
2075 if (mService != null) {
2076 try {
2077 return mService.getDoNotAskCredentialsOnBoot();
2078 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002079 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002080 }
2081 }
2082 return false;
2083 }
2084
2085 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002086 * Setting this to a value greater than zero enables a built-in policy that will perform a
2087 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2088 * This built-in policy combines watching for failed passwords and wiping the device, and
2089 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002090 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002091 * <p>
2092 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2093 * revoking credentials, or reporting the failure to a server), you should implement
2094 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2095 * use this API, because if the maximum count is reached, the device or profile will be wiped
2096 * immediately, and your callback will not be invoked.
2097 * <p>
2098 * This method can be called on the {@link DevicePolicyManager} instance returned by
2099 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2100 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002101 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002103 * @param num The number of failed password attempts at which point the device or profile will
2104 * be wiped.
2105 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2106 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2107 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002108 */
Robin Lee25e26452015-06-02 09:56:29 -07002109 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002110 if (mService != null) {
2111 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002112 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002114 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002115 }
2116 }
2117 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002118
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002119 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002120 * Retrieve the current maximum number of login attempts that are allowed before the device
2121 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2122 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2123 * not taken into account.
2124 *
2125 * <p>This method can be called on the {@link DevicePolicyManager} instance
2126 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2127 * the value for the parent profile.
2128 *
Robin Lee25e26452015-06-02 09:56:29 -07002129 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002130 * all admins.
2131 */
Robin Lee25e26452015-06-02 09:56:29 -07002132 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002133 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002134 }
2135
2136 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002137 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002138 if (mService != null) {
2139 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002140 return mService.getMaximumFailedPasswordsForWipe(
2141 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002142 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002143 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002144 }
2145 }
2146 return 0;
2147 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002148
Dianne Hackborn254cb442010-01-27 19:23:59 -08002149 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002150 * Returns the profile with the smallest maximum failed passwords for wipe,
2151 * for the given user. So for primary user, it might return the primary or
2152 * a managed profile. For a secondary user, it would be the same as the
2153 * user passed in.
2154 * @hide Used only by Keyguard
2155 */
2156 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2157 if (mService != null) {
2158 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002159 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2160 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002161 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002162 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002163 }
2164 }
2165 return UserHandle.USER_NULL;
2166 }
2167
2168 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002169 * Flag for {@link #resetPassword}: don't allow other admins to change
2170 * the password again until the user has entered it.
2171 */
2172 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002173
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002174 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002175 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2176 * If the flag is set, the device can be booted without asking for user password.
2177 * The absence of this flag does not change the current boot requirements. This flag
2178 * can be set by the device owner only. If the app is not the device owner, the flag
2179 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2180 * device to factory defaults.
2181 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002182 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002183
2184 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002185 * Force a new device unlock password (the password needed to access the entire device, not for
2186 * individual accounts) on the user. This takes effect immediately.
2187 * <p>
2188 * Calling this from a managed profile that shares the password with the owner profile will
2189 * throw a security exception.
2190 * <p>
2191 * <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
2204 * current password constraints allow it. <em>Note: This will not
Makoto Onuki70f929e2015-11-11 12:40:15 -08002205 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2206 * device owner and not profile owner. Once set, the password cannot be changed to null or
2207 * empty, except by device owner or profile owner.</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) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002222 if (mParentInstance) {
2223 throw new SecurityException("Reset password does not work across profiles.");
2224 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002225 if (mService != null) {
2226 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002227 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002229 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002230 }
2231 }
2232 return false;
2233 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002234
Dianne Hackbornd6847842010-01-12 18:14:19 -08002235 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002236 * Called by an application that is administering the device to set the maximum time for user
2237 * activity until the device will lock. This limits the length that the user can set. It takes
2238 * effect immediately.
2239 * <p>
2240 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2241 * to be able to call this method; if it has not, a security exception will be thrown.
2242 * <p>
2243 * This method can be called on the {@link DevicePolicyManager} instance returned by
2244 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2245 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002246 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002248 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2249 * is no restriction.
2250 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2251 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002252 */
Robin Lee25e26452015-06-02 09:56:29 -07002253 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002254 if (mService != null) {
2255 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002256 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002257 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002258 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002259 }
2260 }
2261 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002262
Dianne Hackbornd6847842010-01-12 18:14:19 -08002263 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002264 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2265 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2266 * a separate challenge are not taken into account.
2267 *
2268 * <p>This method can be called on the {@link DevicePolicyManager} instance
2269 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2270 * restrictions on the parent profile.
2271 *
Robin Lee25e26452015-06-02 09:56:29 -07002272 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002273 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002274 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002275 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002276 */
Robin Lee25e26452015-06-02 09:56:29 -07002277 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002278 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002279 }
2280
2281 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002282 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002283 if (mService != null) {
2284 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002285 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002286 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002287 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002288 }
2289 }
2290 return 0;
2291 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002292
Dianne Hackbornd6847842010-01-12 18:14:19 -08002293 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002294 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2295 * this call.
2296 * <p>
2297 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2298 * to be able to call this method; if it has not, a security exception will be thrown.
2299 * <p>
2300 * This method can be called on the {@link DevicePolicyManager} instance returned by
2301 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002302 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002303 * @throws SecurityException if the calling application does not own an active administrator
2304 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002305 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002306 public void lockNow() {
2307 if (mService != null) {
2308 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002309 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002310 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002311 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002312 }
2313 }
2314 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002315
Dianne Hackbornd6847842010-01-12 18:14:19 -08002316 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002317 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002318 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002319 */
2320 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2321
2322 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002323 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2324 * data.
2325 *
Paul Crowley2934b262014-12-02 11:21:13 +00002326 * <p>This flag may only be set by device owner admins; if it is set by
2327 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002328 */
2329 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2330
2331 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002332 * Ask the user data be wiped. Wiping the primary user will cause the device to reboot, erasing
2333 * all user data while next booting up.
2334 * <p>
2335 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2336 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002337 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002338 * @param flags Bit mask of additional options: currently supported flags are
2339 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2340 * @throws SecurityException if the calling application does not own an active administrator
2341 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002342 */
2343 public void wipeData(int flags) {
2344 if (mService != null) {
2345 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002346 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002347 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002348 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002349 }
2350 }
2351 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002352
Dianne Hackbornd6847842010-01-12 18:14:19 -08002353 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002354 * Called by an application that is administering the device to set the
2355 * global proxy and exclusion list.
2356 * <p>
2357 * The calling device admin must have requested
2358 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2359 * this method; if it has not, a security exception will be thrown.
2360 * Only the first device admin can set the proxy. If a second admin attempts
2361 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002362 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002363 * be returned.
2364 * The method can be called repeatedly by the device admin alrady setting the
2365 * proxy to update the proxy and exclusion list.
2366 *
Robin Lee25e26452015-06-02 09:56:29 -07002367 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002368 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2369 * Pass Proxy.NO_PROXY to reset the proxy.
2370 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002371 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2372 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002373 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002374 */
Robin Lee25e26452015-06-02 09:56:29 -07002375 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002376 List<String> exclusionList ) {
2377 if (proxySpec == null) {
2378 throw new NullPointerException();
2379 }
2380 if (mService != null) {
2381 try {
2382 String hostSpec;
2383 String exclSpec;
2384 if (proxySpec.equals(Proxy.NO_PROXY)) {
2385 hostSpec = null;
2386 exclSpec = null;
2387 } else {
2388 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2389 throw new IllegalArgumentException();
2390 }
2391 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2392 String hostName = sa.getHostName();
2393 int port = sa.getPort();
2394 StringBuilder hostBuilder = new StringBuilder();
2395 hostSpec = hostBuilder.append(hostName)
2396 .append(":").append(Integer.toString(port)).toString();
2397 if (exclusionList == null) {
2398 exclSpec = "";
2399 } else {
2400 StringBuilder listBuilder = new StringBuilder();
2401 boolean firstDomain = true;
2402 for (String exclDomain : exclusionList) {
2403 if (!firstDomain) {
2404 listBuilder = listBuilder.append(",");
2405 } else {
2406 firstDomain = false;
2407 }
2408 listBuilder = listBuilder.append(exclDomain.trim());
2409 }
2410 exclSpec = listBuilder.toString();
2411 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002412 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2413 != android.net.Proxy.PROXY_VALID)
2414 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002415 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002416 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002417 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002418 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002419 }
2420 }
2421 return null;
2422 }
2423
2424 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002425 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2426 * HTTP proxies - they are generally network dependent. However if you're doing something
2427 * unusual like general internal filtering this may be useful. On a private network where the
2428 * proxy is not accessible, you may break HTTP using this.
2429 * <p>
2430 * This method requires the caller to be the device owner.
2431 * <p>
2432 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002433 *
Jason Monk03bc9912014-05-13 09:44:57 -04002434 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002435 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2436 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2437 * {@code null} value will clear the global HTTP proxy.
2438 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002439 */
Robin Lee25e26452015-06-02 09:56:29 -07002440 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2441 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002442 if (mService != null) {
2443 try {
2444 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2445 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002446 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002447 }
2448 }
2449 }
2450
2451 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002452 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002453 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2454 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002455 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002456 */
2457 public ComponentName getGlobalProxyAdmin() {
2458 if (mService != null) {
2459 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002460 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002461 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002462 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002463 }
2464 }
2465 return null;
2466 }
2467
2468 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002469 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002470 * indicating that encryption is not supported.
2471 */
2472 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2473
2474 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002475 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002476 * indicating that encryption is supported, but is not currently active.
2477 */
2478 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2479
2480 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002481 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002482 * indicating that encryption is not currently active, but is currently
2483 * being activated. This is only reported by devices that support
2484 * encryption of data and only when the storage is currently
2485 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2486 * to become encrypted will never return this value.
2487 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002488 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002489
2490 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002491 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002492 * indicating that encryption is active.
2493 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002494 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002495
2496 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002497 * Result code for {@link #getStorageEncryptionStatus}:
2498 * indicating that encryption is active, but an encryption key has not
2499 * been set by the user.
2500 */
2501 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2502
2503 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002504 * Result code for {@link #getStorageEncryptionStatus}:
2505 * indicating that encryption is active and the encryption key is tied to the user.
2506 */
2507 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2508
2509 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002510 * Activity action: begin the process of encrypting data on the device. This activity should
2511 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2512 * After resuming from this activity, use {@link #getStorageEncryption}
2513 * to check encryption status. However, on some devices this activity may never return, as
2514 * it may trigger a reboot and in some cases a complete data wipe of the device.
2515 */
2516 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2517 public static final String ACTION_START_ENCRYPTION
2518 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002519 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002520 * Widgets are enabled in keyguard
2521 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002522 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002523
2524 /**
Jim Miller50e62182014-04-23 17:25:00 -07002525 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002526 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002527 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2528
2529 /**
2530 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2531 */
2532 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2533
2534 /**
Jim Miller50e62182014-04-23 17:25:00 -07002535 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2536 */
2537 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2538
2539 /**
2540 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2541 */
2542 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2543
2544 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002545 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002546 * (e.g. PIN/Pattern/Password).
2547 */
2548 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2549
2550 /**
Jim Miller06e34502014-07-17 14:46:05 -07002551 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2552 */
2553 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2554
2555 /**
Jim Miller35207742012-11-02 15:33:20 -07002556 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002557 */
2558 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002559
2560 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002561 * Called by an application that is administering the device to request that the storage system
2562 * be encrypted.
2563 * <p>
2564 * When multiple device administrators attempt to control device encryption, the most secure,
2565 * supported setting will always be used. If any device administrator requests device
2566 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2567 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002568 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002569 * <p>
2570 * This policy controls encryption of the secure (application data) storage area. Data written
2571 * to other storage areas may or may not be encrypted, and this policy does not require or
2572 * control the encryption of any other storage areas. There is one exception: If
2573 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2574 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2575 * written to disk within the encrypted storage area.
2576 * <p>
2577 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2578 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2579 * encryption key may not be fully secured. For maximum security, the administrator should also
2580 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002581 *
2582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2583 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002584 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002585 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2586 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2587 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2588 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2589 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002590 */
Robin Lee25e26452015-06-02 09:56:29 -07002591 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002592 if (mService != null) {
2593 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002594 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002596 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002597 }
2598 }
2599 return ENCRYPTION_STATUS_UNSUPPORTED;
2600 }
2601
2602 /**
2603 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002604 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002605 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2607 * this will return the requested encryption setting as an aggregate of all active
2608 * administrators.
2609 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002610 */
Robin Lee25e26452015-06-02 09:56:29 -07002611 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002612 if (mService != null) {
2613 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002614 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002615 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002616 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002617 }
2618 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002619 return false;
2620 }
2621
2622 /**
2623 * Called by an application that is administering the device to
2624 * determine the current encryption status of the device.
2625 *
2626 * Depending on the returned status code, the caller may proceed in different
2627 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2628 * storage system does not support encryption. If the
2629 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2630 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002631 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2632 * storage system has enabled encryption but no password is set so further action
2633 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002634 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2635 *
Robin Lee7e678712014-07-24 16:41:31 +01002636 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002637 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002638 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2639 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002640 */
2641 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002642 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002643 }
2644
2645 /** @hide per-user version */
2646 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002647 if (mService != null) {
2648 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002649 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002650 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002651 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002652 }
2653 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002654 return ENCRYPTION_STATUS_UNSUPPORTED;
2655 }
2656
2657 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00002658 * Mark a CA certificate as approved by the device user. This means that they have been notified
2659 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
2660 * keep the certificate on the device.
2661 *
2662 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
2663 * this certificate.
2664 *
2665 * @hide
2666 */
2667 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
2668 if (mService != null) {
2669 try {
2670 return mService.approveCaCert(alias, userHandle, approval);
2671 } catch (RemoteException e) {
2672 throw e.rethrowFromSystemServer();
2673 }
2674 }
2675 return false;
2676 }
2677
2678 /**
2679 * Check whether a CA certificate has been approved by the device user.
2680 *
2681 * @hide
2682 */
2683 public boolean isCaCertApproved(String alias, int userHandle) {
2684 if (mService != null) {
2685 try {
2686 return mService.isCaCertApproved(alias, userHandle);
2687 } catch (RemoteException e) {
2688 throw e.rethrowFromSystemServer();
2689 }
2690 }
2691 return false;
2692 }
2693
2694 /**
Robin Lee7e678712014-07-24 16:41:31 +01002695 * Installs the given certificate as a user CA.
2696 *
Robin Lee25e26452015-06-02 09:56:29 -07002697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2698 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002699 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002700 *
2701 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002702 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002703 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2704 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002705 */
Robin Lee25e26452015-06-02 09:56:29 -07002706 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002707 if (mService != null) {
2708 try {
Robin Lee7e678712014-07-24 16:41:31 +01002709 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002710 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002711 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002712 }
2713 }
2714 return false;
2715 }
2716
2717 /**
Robin Lee7e678712014-07-24 16:41:31 +01002718 * Uninstalls the given certificate from trusted user CAs, if present.
2719 *
Robin Lee25e26452015-06-02 09:56:29 -07002720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2721 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002722 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002723 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2724 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002725 */
Robin Lee25e26452015-06-02 09:56:29 -07002726 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002727 if (mService != null) {
2728 try {
Robin Lee306fe082014-06-19 14:04:24 +00002729 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002730 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002731 } catch (CertificateException e) {
2732 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002733 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002734 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002735 }
2736 }
2737 }
2738
2739 /**
Robin Lee7e678712014-07-24 16:41:31 +01002740 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2741 * If a user has installed any certificates by other means than device policy these will be
2742 * included too.
2743 *
Robin Lee25e26452015-06-02 09:56:29 -07002744 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2745 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002746 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002747 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2748 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002749 */
Robin Lee25e26452015-06-02 09:56:29 -07002750 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002751 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002752 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002753 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002754 mService.enforceCanManageCaCerts(admin);
2755 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2756 for (String alias : certStore.userAliases()) {
2757 try {
2758 certs.add(certStore.getCertificate(alias).getEncoded());
2759 } catch (CertificateException ce) {
2760 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2761 }
2762 }
2763 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002764 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002765 }
2766 }
2767 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002768 }
2769
2770 /**
Robin Lee7e678712014-07-24 16:41:31 +01002771 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2772 * means other than device policy will also be removed, except for system CA certificates.
2773 *
Robin Lee25e26452015-06-02 09:56:29 -07002774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2775 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002776 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2777 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002778 */
Robin Lee25e26452015-06-02 09:56:29 -07002779 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002780 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002781 try {
2782 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2783 .toArray(new String[0]));
2784 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002785 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002786 }
2787 }
2788 }
2789
2790 /**
2791 * Returns whether this certificate is installed as a trusted CA.
2792 *
Robin Lee25e26452015-06-02 09:56:29 -07002793 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2794 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002795 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002796 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2797 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002798 */
Robin Lee25e26452015-06-02 09:56:29 -07002799 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002800 if (mService != null) {
2801 try {
2802 mService.enforceCanManageCaCerts(admin);
2803 return getCaCertAlias(certBuffer) != null;
2804 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002805 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002806 } catch (CertificateException ce) {
2807 Log.w(TAG, "Could not parse certificate", ce);
2808 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002809 }
2810 return false;
2811 }
2812
2813 /**
Robin Leece3399f2016-02-24 12:08:32 +00002814 * Called by a device or profile owner, or delegated certificate installer, to install a
2815 * certificate and corresponding private key. All apps within the profile will be able to access
2816 * the certificate and use the private key, given direct user approval.
2817 *
2818 * <p>Access to the installed credentials will not be granted to the caller of this API without
2819 * direct user approval. This is for security - should a certificate installer become
2820 * compromised, certificates it had already installed will be protected.
2821 *
2822 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00002823 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002824 *
Robin Lee25e26452015-06-02 09:56:29 -07002825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2826 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002827 * @param privKey The private key to install.
2828 * @param cert The certificate to install.
2829 * @param alias The private key alias under which to install the certificate. If a certificate
2830 * with that alias already exists, it will be overwritten.
2831 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002832 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2833 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002834 */
Robin Leefbc65642015-08-03 16:21:22 +01002835 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2836 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00002837 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00002838 }
2839
2840 /**
2841 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00002842 * certificate chain and corresponding private key for the leaf certificate. All apps within the
2843 * profile will be able to access the certificate chain and use the private key, given direct
2844 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00002845 *
Robin Leea1b290e2016-03-09 14:38:36 +00002846 * <p>The caller of this API may grant itself access to the certificate and private key
2847 * immediately, without user approval. It is a best practice not to request this unless strictly
2848 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00002849 *
2850 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002851 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00002852 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00002853 * @param certs The certificate chain to install. The chain should start with the leaf
2854 * certificate and include the chain of trust in order. This will be returned by
2855 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00002856 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00002857 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00002858 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00002859 * credentials immediately. Otherwise, access to the credentials will be gated by user
2860 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00002861 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002862 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2863 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00002864 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00002865 */
2866 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00002867 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002868 try {
Rubin Xub4365912016-03-23 12:13:22 +00002869 final byte[] pemCert = Credentials.convertToPem(certs[0]);
2870 byte[] pemChain = null;
2871 if (certs.length > 1) {
2872 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
2873 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01002874 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2875 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00002876 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
2877 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002878 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002879 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01002880 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2881 Log.w(TAG, "Failed to obtain private key material", e);
2882 } catch (CertificateException | IOException e) {
2883 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002884 }
2885 return false;
2886 }
2887
2888 /**
Robin Leea1b290e2016-03-09 14:38:36 +00002889 * Called by a device or profile owner, or delegated certificate installer, to remove a
2890 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002891 *
2892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002893 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01002894 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00002895 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002896 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2897 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01002898 */
2899 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2900 try {
2901 return mService.removeKeyPair(admin, alias);
2902 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002903 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01002904 }
Robin Leefbc65642015-08-03 16:21:22 +01002905 }
2906
2907 /**
Robin Lee25e26452015-06-02 09:56:29 -07002908 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002909 * doesn't exist.
2910 */
2911 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2912 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2913 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2914 new ByteArrayInputStream(certBuffer));
2915 return new TrustedCertificateStore().getCertificateAlias(cert);
2916 }
2917
2918 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002919 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002920 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002921 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002922 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002923 * <p>
2924 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2925 * it is later cleared by calling this method with a null value or uninstallling the certificate
2926 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002927 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00002928 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2929 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002930 * supplied certificate installer package must be installed when calling this API, otherwise an
2931 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002932 *
Robin Lee25e26452015-06-02 09:56:29 -07002933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002934 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002935 * access. If {@code null} is given the current package will be cleared.
2936 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002937 */
Robin Lee25e26452015-06-02 09:56:29 -07002938 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2939 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002940 if (mService != null) {
2941 try {
Robin Lee25e26452015-06-02 09:56:29 -07002942 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002943 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002944 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002945 }
2946 }
2947 }
2948
2949 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002950 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
2951 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002952 *
Robin Lee25e26452015-06-02 09:56:29 -07002953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002954 * @return The package name of the current delegated certificate installer, or {@code null} if
2955 * none is set.
2956 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002957 */
Robin Lee25e26452015-06-02 09:56:29 -07002958 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002959 if (mService != null) {
2960 try {
Robin Lee25e26452015-06-02 09:56:29 -07002961 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002962 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002963 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002964 }
2965 }
2966 return null;
2967 }
2968
2969 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002970 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002971 * specific application for the current user. This connection is automatically granted and
2972 * persisted after a reboot.
2973 * <p>
2974 * The designated package should declare a {@link android.net.VpnService} in its manifest
2975 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
2976 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00002977 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002978 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
2979 * remove an existing always-on VPN configuration.
2980 * @return {@code true} if the package is set as always-on VPN controller; {@code false}
2981 * otherwise.
2982 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00002983 */
2984 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2985 @Nullable String vpnPackage) {
2986 if (mService != null) {
2987 try {
2988 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002990 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002991 }
2992 }
2993 return false;
2994 }
2995
2996 /**
2997 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002998 * always-on VPN connection for the current user. If there is no such package, or the always-on
2999 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003000 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003001 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3002 * is set.
3003 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003004 */
3005 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
3006 if (mService != null) {
3007 try {
3008 return mService.getAlwaysOnVpnPackage(admin);
3009 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003010 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003011 }
3012 }
3013 return null;
3014 }
3015
3016 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003017 * Called by an application that is administering the device to disable all cameras on the
3018 * device, for this user. After setting this, no applications running as this user will be able
3019 * to access any cameras on the device.
3020 * <p>
3021 * If the caller is device owner, then the restriction will be applied to all users.
3022 * <p>
3023 * The calling device admin must have requested
3024 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3025 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003026 *
3027 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3028 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003029 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3030 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003031 */
Robin Lee25e26452015-06-02 09:56:29 -07003032 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003033 if (mService != null) {
3034 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003035 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003036 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003037 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003038 }
3039 }
3040 }
3041
3042 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003043 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003044 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003045 * @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 -07003046 * have disabled the camera
3047 */
Robin Lee25e26452015-06-02 09:56:29 -07003048 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003049 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003050 }
3051
3052 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003053 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003054 if (mService != null) {
3055 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003056 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003057 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003058 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003059 }
3060 }
3061 return false;
3062 }
3063
3064 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003065 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003066 * <p>
3067 * There must be only one user on the device, managed by the device owner. Otherwise a
3068 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003069 *
3070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003071 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3072 * wasn't triggered because a previous bugreport operation is still active (either the
3073 * bugreport is still running or waiting for the user to share or decline)
3074 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3075 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003076 */
3077 public boolean requestBugreport(@NonNull ComponentName admin) {
3078 if (mService != null) {
3079 try {
3080 return mService.requestBugreport(admin);
3081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003082 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003083 }
3084 }
3085 return false;
3086 }
3087
3088 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003089 * Determine whether or not creating a guest user has been disabled for the device
3090 *
3091 * @hide
3092 */
3093 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3094 // Currently guest users can always be created if multi-user is enabled
3095 // TODO introduce a policy for guest user creation
3096 return false;
3097 }
3098
3099 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003100 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3101 * screen capture also prevents the content from being shown on display devices that do not have
3102 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3103 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003104 * <p>
3105 * The calling device admin must be a device or profile owner. If it is not, a security
3106 * exception will be thrown.
3107 * <p>
3108 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3109 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003110 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003111 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003112 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003113 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003114 */
Robin Lee25e26452015-06-02 09:56:29 -07003115 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003116 if (mService != null) {
3117 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003118 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003120 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003121 }
3122 }
3123 }
3124
3125 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003126 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003127 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003128 * @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 +01003129 * have disabled screen capture.
3130 */
Robin Lee25e26452015-06-02 09:56:29 -07003131 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003132 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003133 }
3134
3135 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003136 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003137 if (mService != null) {
3138 try {
3139 return mService.getScreenCaptureDisabled(admin, userHandle);
3140 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003141 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003142 }
3143 }
3144 return false;
3145 }
3146
3147 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003148 * Called by a device owner to set whether auto time is required. If auto time is required the
3149 * user cannot set the date and time, but has to use network date and time.
3150 * <p>
3151 * Note: if auto time is required the user can still manually set the time zone.
3152 * <p>
3153 * The calling device admin must be a device owner. If it is not, a security exception will be
3154 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003155 *
3156 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3157 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003158 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003159 */
Robin Lee25e26452015-06-02 09:56:29 -07003160 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003161 if (mService != null) {
3162 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003163 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003165 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003166 }
3167 }
3168 }
3169
3170 /**
3171 * @return true if auto time is required.
3172 */
3173 public boolean getAutoTimeRequired() {
3174 if (mService != null) {
3175 try {
3176 return mService.getAutoTimeRequired();
3177 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003178 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003179 }
3180 }
3181 return false;
3182 }
3183
3184 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003185 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003186 * <p>
3187 * The system user is exempt from this policy - it is never ephemeral.
3188 * <p>
3189 * The calling device admin must be the device owner. If it is not, a security exception will be
3190 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003191 *
3192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3193 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003194 * subsequently created users will be ephemeral.
3195 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003196 * @hide
3197 */
3198 public void setForceEphemeralUsers(
3199 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3200 if (mService != null) {
3201 try {
3202 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003204 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003205 }
3206 }
3207 }
3208
3209 /**
3210 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003211 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003212 * @hide
3213 */
3214 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3215 if (mService != null) {
3216 try {
3217 return mService.getForceEphemeralUsers(admin);
3218 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003219 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003220 }
3221 }
3222 return false;
3223 }
3224
3225 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003226 * Called by an application that is administering the device to disable keyguard customizations,
3227 * such as widgets. After setting this, keyguard features will be disabled according to the
3228 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003229 * <p>
3230 * The calling device admin must have requested
3231 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3232 * if it has not, a security exception will be thrown.
3233 * <p>
3234 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3235 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3236 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003237 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003238 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003239 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003240 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003241 * there is one, or the parent user otherwise.
3242 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3243 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003244 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003245 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3246 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003247 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3248 * profile.
3249 * <p>
3250 * Requests to disable other features on a managed profile will be ignored.
3251 * <p>
3252 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003253 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003254 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003256 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003257 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3258 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3259 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3260 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3261 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3262 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3263 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003264 */
Robin Lee25e26452015-06-02 09:56:29 -07003265 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003266 if (mService != null) {
3267 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003268 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003269 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003270 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003271 }
3272 }
3273 }
3274
3275 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003276 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003277 * admin, if specified, or all admins that set retrictions on this user and its participating
3278 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3279 *
3280 * <p>This method can be called on the {@link DevicePolicyManager} instance
3281 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3282 * restrictions on the parent profile.
3283 *
Esteban Talavera62399912016-01-11 15:37:55 +00003284 * @param admin The name of the admin component to check, or {@code null} to check whether any
3285 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003286 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3287 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003288 */
Robin Lee25e26452015-06-02 09:56:29 -07003289 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003290 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003291 }
3292
3293 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003294 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003295 if (mService != null) {
3296 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003297 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003298 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003299 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003300 }
3301 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003302 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003303 }
3304
3305 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003306 * @hide
3307 */
Robin Lee25e26452015-06-02 09:56:29 -07003308 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3309 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003310 if (mService != null) {
3311 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003312 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003313 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003314 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003315 }
3316 }
3317 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003318
Dianne Hackbornd6847842010-01-12 18:14:19 -08003319 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003320 * @hide
3321 */
Robin Lee25e26452015-06-02 09:56:29 -07003322 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003323 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003324 }
3325
3326 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003327 * @hide
3328 */
Robin Lee25e26452015-06-02 09:56:29 -07003329 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003330 if (mService != null) {
3331 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003332 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003333 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003334 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003335 }
3336 }
3337 }
3338
3339 /**
3340 * @hide
3341 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003342 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003343 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003344 if (mService != null) {
3345 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003346 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003347 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003349 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003350 }
3351 }
3352 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003353
Dianne Hackbornd6847842010-01-12 18:14:19 -08003354 /**
3355 * @hide
3356 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003357 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003358 if (mService != null) {
3359 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003360 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003361 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003362 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003363 }
3364 }
3365 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003366
Dianne Hackbornd6847842010-01-12 18:14:19 -08003367 /**
3368 * @hide
3369 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003370 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003371 if (mService != null) {
3372 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003373 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003375 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003376 }
3377 }
3378 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003379
3380 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003381 * @hide
3382 */
3383 public void reportFailedFingerprintAttempt(int userHandle) {
3384 if (mService != null) {
3385 try {
3386 mService.reportFailedFingerprintAttempt(userHandle);
3387 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003388 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003389 }
3390 }
3391 }
3392
3393 /**
3394 * @hide
3395 */
3396 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3397 if (mService != null) {
3398 try {
3399 mService.reportSuccessfulFingerprintAttempt(userHandle);
3400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003401 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003402 }
3403 }
3404 }
3405
3406 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003407 * Should be called when keyguard has been dismissed.
3408 * @hide
3409 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003410 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003411 if (mService != null) {
3412 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003413 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003414 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003415 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003416 }
3417 }
3418 }
3419
3420 /**
3421 * Should be called when keyguard view has been shown to the user.
3422 * @hide
3423 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003424 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003425 if (mService != null) {
3426 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003427 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003428 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003429 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003430 }
3431 }
3432 }
3433
3434 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003435 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003436 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003437 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3438 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003439 * @return whether the package was successfully registered as the device owner.
3440 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003441 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003442 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003443 public boolean setDeviceOwner(ComponentName who) {
3444 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003445 }
3446
3447 /**
3448 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003449 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003450 public boolean setDeviceOwner(ComponentName who, int userId) {
3451 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003452 }
3453
3454 /**
3455 * @hide
3456 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003457 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3458 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003459 }
3460
3461 /**
3462 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003463 * Sets the given package as the device owner. The package must already be installed. There
3464 * must not already be a device owner.
3465 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3466 * this method.
3467 * Calling this after the setup phase of the primary user has completed is allowed only if
3468 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003469 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003470 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003471 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003472 * @return whether the package was successfully registered as the device owner.
3473 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003474 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003475 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003476 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003477 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003478 if (mService != null) {
3479 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003480 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003481 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003482 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003483 }
3484 }
3485 return false;
3486 }
3487
3488 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003489 * Used to determine if a particular package has been registered as a Device Owner app.
3490 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003491 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003492 * package is currently registered as the device owner app, pass in the package name from
3493 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003494 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003495 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3496 * the setup process.
3497 * @param packageName the package name of the app, to compare with the registered device owner
3498 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003499 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003500 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003501 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003502 return isDeviceOwnerAppOnCallingUser(packageName);
3503 }
3504
3505 /**
3506 * @return true if a package is registered as device owner, only when it's running on the
3507 * calling user.
3508 *
3509 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3510 * @hide
3511 */
3512 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3513 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3514 }
3515
3516 /**
3517 * @return true if a package is registered as device owner, even if it's running on a different
3518 * user.
3519 *
3520 * <p>Requires the MANAGE_USERS permission.
3521 *
3522 * @hide
3523 */
3524 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3525 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3526 }
3527
3528 /**
3529 * @return device owner component name, only when it's running on the calling user.
3530 *
3531 * @hide
3532 */
3533 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3534 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3535 }
3536
3537 /**
3538 * @return device owner component name, even if it's running on a different user.
3539 *
3540 * <p>Requires the MANAGE_USERS permission.
3541 *
3542 * @hide
3543 */
3544 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3545 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3546 }
3547
3548 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003549 if (packageName == null) {
3550 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003551 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003552 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003553 if (deviceOwner == null) {
3554 return false;
3555 }
3556 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003557 }
3558
Makoto Onukic8a5a552015-11-19 14:29:12 -08003559 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3560 if (mService != null) {
3561 try {
3562 return mService.getDeviceOwnerComponent(callingUserOnly);
3563 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003564 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003565 }
3566 }
3567 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003568 }
3569
Jason Monkb0dced82014-06-06 14:36:20 -04003570 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003571 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3572 * no device owner.
3573 *
3574 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003575 *
3576 * @hide
3577 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003578 public int getDeviceOwnerUserId() {
3579 if (mService != null) {
3580 try {
3581 return mService.getDeviceOwnerUserId();
3582 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003583 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003584 }
3585 }
3586 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003587 }
3588
3589 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003590 * Clears the current device owner. The caller must be the device owner. This function should be
3591 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3592 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003593 *
3594 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003595 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3596 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003597 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003598 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003599 if (mService != null) {
3600 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003601 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003602 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003603 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003604 }
3605 }
3606 }
3607
Makoto Onukia52562c2015-10-01 16:12:31 -07003608 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003609 * Returns the device owner package name, only if it's running on the calling user.
3610 *
3611 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003612 *
3613 * @hide
3614 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003615 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003616 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003617 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3618 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003619 }
3620
3621 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003622 * @return true if the device is managed by any device owner.
3623 *
3624 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003625 *
3626 * @hide
3627 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003628 public boolean isDeviceManaged() {
3629 return getDeviceOwnerComponentOnAnyUser() != null;
3630 }
3631
3632 /**
3633 * Returns the device owner name. Note this method *will* return the device owner
3634 * name when it's running on a different user.
3635 *
3636 * <p>Requires the MANAGE_USERS permission.
3637 *
3638 * @hide
3639 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003640 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003641 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003642 if (mService != null) {
3643 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003644 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003645 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003646 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003647 }
3648 }
3649 return null;
3650 }
Adam Connors776c5552014-01-09 10:42:56 +00003651
3652 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003653 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003654 * @deprecated Do not use
3655 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003656 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003657 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003658 @SystemApi
3659 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003660 return null;
3661 }
3662
3663 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003664 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003665 * @deprecated Do not use
3666 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003667 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003668 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003669 @SystemApi
3670 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003671 return null;
3672 }
3673
Julia Reynolds20118f12015-02-11 12:34:08 -05003674 /**
Adam Connors776c5552014-01-09 10:42:56 +00003675 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003676 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303677 * Sets the given component as an active admin and registers the package as the profile
3678 * owner for this user. The package must already be installed and there shouldn't be
3679 * an existing profile owner registered for this user. Also, this method must be called
3680 * before the user setup has been completed.
3681 * <p>
3682 * This method can only be called by system apps that hold MANAGE_USERS permission and
3683 * MANAGE_DEVICE_ADMINS permission.
3684 * @param admin The component to register as an active admin and profile owner.
3685 * @param ownerName The user-visible name of the entity that is managing this user.
3686 * @return whether the admin was successfully registered as the profile owner.
3687 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3688 * the user has already been set up.
3689 */
Justin Morey80440cc2014-07-24 09:16:35 -05003690 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003691 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303692 throws IllegalArgumentException {
3693 if (mService != null) {
3694 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003695 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303696 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003697 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303698 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003699 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303700 }
3701 }
3702 return false;
3703 }
3704
3705 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003706 * Clears the active profile owner and removes all user restrictions. The caller must be from
3707 * the same package as the active profile owner for this user, otherwise a SecurityException
3708 * will be thrown.
3709 * <p>
3710 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003711 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003712 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003713 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003714 */
Robin Lee25e26452015-06-02 09:56:29 -07003715 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003716 if (mService != null) {
3717 try {
3718 mService.clearProfileOwner(admin);
3719 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003720 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003721 }
3722 }
3723 }
3724
3725 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003726 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003727 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003728 */
3729 public boolean hasUserSetupCompleted() {
3730 if (mService != null) {
3731 try {
3732 return mService.hasUserSetupCompleted();
3733 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003734 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003735 }
3736 }
3737 return true;
3738 }
3739
3740 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003741 * @hide
3742 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003743 * already be installed. There must not already be a profile owner for this user.
3744 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3745 * this method.
3746 * Calling this after the setup phase of the specified user has completed is allowed only if:
3747 * - the caller is SYSTEM_UID.
3748 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003749 * @param admin the component name to be registered as profile owner.
3750 * @param ownerName the human readable name of the organisation associated with this DPM.
3751 * @param userHandle the userId to set the profile owner for.
3752 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003753 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3754 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003755 */
Robin Lee25e26452015-06-02 09:56:29 -07003756 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003757 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003758 if (mService != null) {
3759 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003760 if (ownerName == null) {
3761 ownerName = "";
3762 }
3763 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003764 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003765 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003766 }
3767 }
3768 return false;
3769 }
3770
3771 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003772 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003773 * <p>
3774 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003775 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003776 * <p>
3777 * If the device owner information contains only whitespaces then the message on the lock screen
3778 * will be blank and the user will not be allowed to change it.
3779 * <p>
3780 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003781 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3782 * and set a new version of this string accordingly.
3783 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003784 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003785 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003786 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003787 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003788 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003789 if (mService != null) {
3790 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003791 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003792 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003793 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003794 }
3795 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003796 }
3797
3798 /**
3799 * @return The device owner information. If it is not set returns {@code null}.
3800 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003801 public CharSequence getDeviceOwnerLockScreenInfo() {
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003802 if (mService != null) {
3803 try {
3804 return mService.getDeviceOwnerLockScreenInfo();
3805 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003806 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003807 }
3808 }
3809 return null;
3810 }
3811
3812 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003813 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003814 * <p>
3815 * A suspended package will not be able to start activities. Its notifications will be hidden,
3816 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
3817 * device.
3818 * <p>
3819 * The package must already be installed. If the package is uninstalled while suspended the
3820 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00003821 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003822 *
3823 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003824 * @param packageNames The package names to suspend or unsuspend.
3825 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003826 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003827 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003828 * this method.
3829 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003830 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003831 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003832 boolean suspended) {
3833 if (mService != null) {
3834 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003835 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003836 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003837 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003838 }
3839 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003840 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003841 }
3842
3843 /**
3844 * Called by device or profile owners to determine if a package is suspended.
3845 *
3846 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3847 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003848 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003849 * suspended, could not be found or an error occurred.
3850 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003851 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003852 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003853 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
3854 throws NameNotFoundException {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003855 if (mService != null) {
3856 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003857 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003858 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003859 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003860 } catch (IllegalArgumentException ex) {
3861 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003862 }
3863 }
3864 return false;
3865 }
3866
3867 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003868 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3869 * be used. Only the profile owner can call this.
3870 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003871 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003873 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003874 */
Robin Lee25e26452015-06-02 09:56:29 -07003875 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003876 if (mService != null) {
3877 try {
3878 mService.setProfileEnabled(admin);
3879 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003880 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003881 }
3882 }
3883 }
3884
3885 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003886 * Sets the name of the profile. In the device owner case it sets the name of the user which it
3887 * is called from. Only a profile owner or device owner can call this. If this is never called
3888 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003889 *
3890 * @see #isProfileOwnerApp
3891 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07003892 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003893 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003894 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003895 */
Robin Lee25e26452015-06-02 09:56:29 -07003896 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003897 if (mService != null) {
3898 try {
Robin Lee25e26452015-06-02 09:56:29 -07003899 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003900 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003901 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003902 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003903 }
3904 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003905
3906 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003907 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003908 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003909 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003910 *
3911 * @param packageName The package name of the app to compare with the registered profile owner.
3912 * @return Whether or not the package is registered as the profile owner.
3913 */
3914 public boolean isProfileOwnerApp(String packageName) {
3915 if (mService != null) {
3916 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003917 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003918 return profileOwner != null
3919 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003920 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003921 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003922 }
3923 }
3924 return false;
3925 }
3926
3927 /**
3928 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003929 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003930 * owner has been set for that user.
3931 * @throws IllegalArgumentException if the userId is invalid.
3932 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003933 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003934 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003935 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3936 }
3937
3938 /**
3939 * @see #getProfileOwner()
3940 * @hide
3941 */
3942 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003943 if (mService != null) {
3944 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003945 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003946 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003947 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003948 }
3949 }
3950 return null;
3951 }
3952
3953 /**
3954 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003955 * @return the human readable name of the organisation associated with this DPM or {@code null}
3956 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003957 * @throws IllegalArgumentException if the userId is invalid.
3958 */
3959 public String getProfileOwnerName() throws IllegalArgumentException {
3960 if (mService != null) {
3961 try {
3962 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3963 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003964 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003965 }
3966 }
3967 return null;
3968 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003969
3970 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003971 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003972 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003973 * @return the human readable name of the organisation associated with this profile owner or
3974 * null if one is not set.
3975 * @throws IllegalArgumentException if the userId is invalid.
3976 */
3977 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003978 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003979 if (mService != null) {
3980 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003981 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003982 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003983 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07003984 }
3985 }
3986 return null;
3987 }
3988
3989 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003990 * Called by a profile owner or device owner to add a default intent handler activity for
3991 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003992 * handler even if the set of potential event handlers for the intent filter changes and if the
3993 * intent preferences are reset.
3994 * <p>
3995 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
3996 * When the activity is (re)installed, it is automatically reset as default intent handler for
3997 * the filter.
3998 * <p>
3999 * The calling device admin must be a profile owner or device owner. If it is not, a security
4000 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004001 *
4002 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4003 * @param filter The IntentFilter for which a default handler is added.
4004 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004005 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004006 */
Robin Lee25e26452015-06-02 09:56:29 -07004007 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4008 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004009 if (mService != null) {
4010 try {
4011 mService.addPersistentPreferredActivity(admin, filter, activity);
4012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004013 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004014 }
4015 }
4016 }
4017
4018 /**
4019 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004020 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004021 * <p>
4022 * The calling device admin must be a profile owner. If it is not, a security exception will be
4023 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004024 *
4025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4026 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004027 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004028 */
Robin Lee25e26452015-06-02 09:56:29 -07004029 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004030 String packageName) {
4031 if (mService != null) {
4032 try {
4033 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004035 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004036 }
4037 }
4038 }
Robin Lee66e5d962014-04-09 16:44:21 +01004039
4040 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004041 * Called by a profile owner or device owner to grant permission to a package to manage
4042 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4043 * {@link #getApplicationRestrictions}.
4044 * <p>
4045 * This permission is persistent until it is later cleared by calling this method with a
4046 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004047 * <p>
4048 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004049 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004050 *
4051 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4052 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004053 * APIs. If {@code null} is given the current package will be cleared.
4054 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004055 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004056 */
4057 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004058 @Nullable String packageName) throws NameNotFoundException {
Esteban Talaverabf60f722015-12-10 16:26:44 +00004059 if (mService != null) {
4060 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004061 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4062 throw new NameNotFoundException(packageName);
4063 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004064 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004065 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004066 }
4067 }
4068 }
4069
4070 /**
4071 * Called by a profile owner or device owner to retrieve the application restrictions managing
4072 * package for the current user, or {@code null} if none is set.
4073 *
4074 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4075 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004076 * {@code null} if none is set.
4077 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004078 */
4079 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
4080 if (mService != null) {
4081 try {
4082 return mService.getApplicationRestrictionsManagingPackage(admin);
4083 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004084 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004085 }
4086 }
4087 return null;
4088 }
4089
4090 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004091 * Called by any application to find out whether it has been granted permission via
4092 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4093 * for the calling user.
4094 *
4095 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4096 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004097 */
4098 public boolean isCallerApplicationRestrictionsManagingPackage() {
4099 if (mService != null) {
4100 try {
4101 return mService.isCallerApplicationRestrictionsManagingPackage();
4102 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004103 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004104 }
4105 }
4106 return false;
4107 }
4108
4109 /**
4110 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004111 * <p>
4112 * The caller must be a profile or device owner on that user, or the package allowed to manage
4113 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4114 * security exception will be thrown.
4115 * <p>
4116 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004117 * <ul>
4118 * <li>{@code boolean}
4119 * <li>{@code int}
4120 * <li>{@code String} or {@code String[]}
4121 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4122 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004123 * <p>
4124 * If the restrictions are not available yet, but may be applied in the near future, the caller
4125 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004126 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004127 * <p>
4128 * The application restrictions are only made visible to the target application via
4129 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4130 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004131 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004132 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004134 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004135 * @param packageName The name of the package to update restricted settings for.
4136 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004137 * set of active restrictions.
4138 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004139 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004140 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004141 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004142 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004143 Bundle settings) {
4144 if (mService != null) {
4145 try {
4146 mService.setApplicationRestrictions(admin, packageName, settings);
4147 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004148 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004149 }
4150 }
4151 }
4152
4153 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004154 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4155 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4156 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004157 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004158 * <p>
4159 * The calling device admin must have requested
4160 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4161 * if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07004162 *
4163 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004164 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004165 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4166 * strictly disabled according to the state of the
4167 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4168 * <p>
4169 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4170 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4171 * device admins.
4172 * <p>
4173 * Consult documentation for the specific TrustAgent to determine legal options
4174 * parameters.
4175 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4176 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004177 */
Robin Lee25e26452015-06-02 09:56:29 -07004178 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4179 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004180 if (mService != null) {
4181 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004182 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004183 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004184 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004185 }
4186 }
4187 }
4188
4189 /**
Jim Millere303bf42014-08-26 17:12:29 -07004190 * Gets configuration for the given trust agent based on aggregating all calls to
4191 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4192 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004193 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004194 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4195 * this function returns a list of configurations for all admins that declare
4196 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4197 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4198 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4199 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004200 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004201 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004202 */
Robin Lee25e26452015-06-02 09:56:29 -07004203 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4204 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004205 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004206 }
4207
4208 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004209 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4210 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004211 if (mService != null) {
4212 try {
Jim Millere303bf42014-08-26 17:12:29 -07004213 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004214 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004215 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004216 }
4217 }
Jim Millere303bf42014-08-26 17:12:29 -07004218 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004219 }
4220
4221 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004222 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4223 * managed profile will be shown in the parent profile, for incoming calls.
4224 * <p>
4225 * The calling device admin must be a profile owner. If it is not, a security exception will be
4226 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004227 *
Robin Lee25e26452015-06-02 09:56:29 -07004228 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004229 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004230 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004231 */
Robin Lee25e26452015-06-02 09:56:29 -07004232 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004233 if (mService != null) {
4234 try {
Robin Lee25e26452015-06-02 09:56:29 -07004235 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004236 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004237 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004238 }
4239 }
4240 }
4241
4242 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004243 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4244 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004245 * <p>
4246 * The calling device admin must be a profile owner. If it is not, a security exception will be
4247 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004248 *
Robin Lee25e26452015-06-02 09:56:29 -07004249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004250 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004251 */
Robin Lee25e26452015-06-02 09:56:29 -07004252 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004253 if (mService != null) {
4254 try {
Robin Lee25e26452015-06-02 09:56:29 -07004255 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004257 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004258 }
4259 }
4260 return false;
4261 }
4262
4263 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004264 * Determine whether or not caller-Id information has been disabled.
4265 *
4266 * @param userHandle The user for whom to check the caller-id permission
4267 * @hide
4268 */
4269 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4270 if (mService != null) {
4271 try {
4272 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4273 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004274 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004275 }
4276 }
4277 return false;
4278 }
4279
4280 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004281 * Called by a profile owner of a managed profile to set whether contacts search from the
4282 * managed profile will be shown in the parent profile, for incoming calls.
4283 * <p>
4284 * The calling device admin must be a profile owner. If it is not, a security exception will be
4285 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004286 *
4287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4288 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004289 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004290 */
4291 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4292 boolean disabled) {
4293 if (mService != null) {
4294 try {
4295 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4296 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004297 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004298 }
4299 }
4300 }
4301
4302 /**
4303 * Called by a profile owner of a managed profile to determine whether or not contacts search
4304 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004305 * <p>
4306 * The calling device admin must be a profile owner. If it is not, a security exception will be
4307 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004308 *
4309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004310 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004311 */
4312 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4313 if (mService != null) {
4314 try {
4315 return mService.getCrossProfileContactsSearchDisabled(admin);
4316 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004317 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004318 }
4319 }
4320 return false;
4321 }
4322
4323
4324 /**
4325 * Determine whether or not contacts search has been disabled.
4326 *
4327 * @param userHandle The user for whom to check the contacts search permission
4328 * @hide
4329 */
4330 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4331 if (mService != null) {
4332 try {
4333 return mService
4334 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4335 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004336 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004337 }
4338 }
4339 return false;
4340 }
4341
4342 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004343 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004344 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004345 * @hide
4346 */
4347 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004348 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004349 if (mService != null) {
4350 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004351 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4352 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004353 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004354 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004355 }
4356 }
4357 }
4358
4359 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004360 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004361 * @hide
4362 */
4363 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4364 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004365 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004366 originalIntent);
4367 }
4368
4369 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004370 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4371 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004372 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004373 * The calling device admin must be a profile owner. If it is not, a security exception will be
4374 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004375 * <p>
4376 * This API works on managed profile only.
4377 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004378 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4379 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4380 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004381 */
Robin Lee25e26452015-06-02 09:56:29 -07004382 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004383 if (mService != null) {
4384 try {
Robin Lee25e26452015-06-02 09:56:29 -07004385 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004386 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004387 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004388 }
4389 }
4390 }
4391
4392 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004393 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4394 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004395 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004396 * The calling device admin must be a profile owner. If it is not, a security exception will be
4397 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004398 * <p>
4399 * This API works on managed profile only.
4400 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4402 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004403 */
Robin Lee25e26452015-06-02 09:56:29 -07004404 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004405 if (mService != null) {
4406 try {
Robin Lee25e26452015-06-02 09:56:29 -07004407 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004408 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004409 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004410 }
4411 }
4412 return true;
4413 }
4414
4415 /**
4416 * Determine whether or not Bluetooth devices cannot access contacts.
4417 * <p>
4418 * This API works on managed profile UserHandle only.
4419 *
4420 * @param userHandle The user for whom to check the caller-id permission
4421 * @hide
4422 */
4423 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4424 if (mService != null) {
4425 try {
4426 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4427 .getIdentifier());
4428 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004429 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004430 }
4431 }
4432 return true;
4433 }
4434
4435 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004436 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004437 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4438 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004439 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004440 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004441 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004442 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004443 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004444 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4445 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004446 */
Robin Lee25e26452015-06-02 09:56:29 -07004447 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004448 if (mService != null) {
4449 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004450 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004451 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004452 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004453 }
4454 }
4455 }
4456
4457 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004458 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4459 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004460 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004461 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004462 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004463 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004464 */
Robin Lee25e26452015-06-02 09:56:29 -07004465 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004466 if (mService != null) {
4467 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004468 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004469 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004470 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004471 }
4472 }
4473 }
4474
4475 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004476 * Called by a profile or device owner to set the permitted accessibility services. When set by
4477 * a device owner or profile owner the restriction applies to all profiles of the user the
4478 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4479 * service. When zero or more packages have been added, accessiblity services that are not in
4480 * the list and not part of the system can not be enabled by the user.
4481 * <p>
4482 * Calling with a null value for the list disables the restriction so that all services can be
4483 * used, calling with an empty list only allows the builtin system's services.
4484 * <p>
4485 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004486 *
4487 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4488 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004489 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4490 * accessibility services enabled, that are not in the list.
4491 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004492 */
Robin Lee25e26452015-06-02 09:56:29 -07004493 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004494 List<String> packageNames) {
4495 if (mService != null) {
4496 try {
4497 return mService.setPermittedAccessibilityServices(admin, packageNames);
4498 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004499 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004500 }
4501 }
4502 return false;
4503 }
4504
4505 /**
4506 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004507 * <p>
4508 * An empty list means no accessibility services except system services are allowed. Null means
4509 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004510 *
4511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4512 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004513 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004514 */
Robin Lee25e26452015-06-02 09:56:29 -07004515 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004516 if (mService != null) {
4517 try {
4518 return mService.getPermittedAccessibilityServices(admin);
4519 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004520 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004521 }
4522 }
4523 return null;
4524 }
4525
4526 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004527 * Called by the system to check if a specific accessibility service is disabled by admin.
4528 *
4529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4530 * @param packageName Accessibility service package name that needs to be checked.
4531 * @param userHandle user id the admin is running as.
4532 * @return true if the accessibility service is permitted, otherwise false.
4533 *
4534 * @hide
4535 */
4536 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4537 @NonNull String packageName, int userHandle) {
4538 if (mService != null) {
4539 try {
4540 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4541 userHandle);
4542 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004543 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004544 }
4545 }
4546 return false;
4547 }
4548
4549 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004550 * Returns the list of accessibility services permitted by the device or profiles
4551 * owners of this user.
4552 *
4553 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4554 * it will contain the intersection of the permitted lists for any device or profile
4555 * owners that apply to this user. It will also include any system accessibility services.
4556 *
4557 * @param userId which user to check for.
4558 * @return List of accessiblity service package names.
4559 * @hide
4560 */
4561 @SystemApi
4562 public List<String> getPermittedAccessibilityServices(int userId) {
4563 if (mService != null) {
4564 try {
4565 return mService.getPermittedAccessibilityServicesForUser(userId);
4566 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004567 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004568 }
4569 }
4570 return null;
4571 }
4572
4573 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004574 * Called by a profile or device owner to set the permitted input methods services. When set by
4575 * a device owner or profile owner the restriction applies to all profiles of the user the
4576 * device owner or profile owner is an admin for. By default the user can use any input method.
4577 * When zero or more packages have been added, input method that are not in the list and not
4578 * part of the system can not be enabled by the user. This method will fail if it is called for
4579 * a admin that is not for the foreground user or a profile of the foreground user.
4580 * <p>
4581 * Calling with a null value for the list disables the restriction so that all input methods can
4582 * be used, calling with an empty list disables all but the system's own input methods.
4583 * <p>
4584 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004585 *
4586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4587 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004588 * @return true if setting the restriction succeeded. It will fail if there are one or more
4589 * non-system input methods currently enabled that are not in the packageNames list.
4590 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004591 */
Robin Lee25e26452015-06-02 09:56:29 -07004592 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004593 if (mService != null) {
4594 try {
4595 return mService.setPermittedInputMethods(admin, packageNames);
4596 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004597 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004598 }
4599 }
4600 return false;
4601 }
4602
4603
4604 /**
4605 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004606 * <p>
4607 * An empty list means no input methods except system input methods are allowed. Null means all
4608 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004609 *
4610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4611 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004612 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004613 */
Robin Lee25e26452015-06-02 09:56:29 -07004614 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004615 if (mService != null) {
4616 try {
4617 return mService.getPermittedInputMethods(admin);
4618 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004619 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004620 }
4621 }
4622 return null;
4623 }
4624
4625 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004626 * Called by the system to check if a specific input method is disabled by admin.
4627 *
4628 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4629 * @param packageName Input method package name that needs to be checked.
4630 * @param userHandle user id the admin is running as.
4631 * @return true if the input method is permitted, otherwise false.
4632 *
4633 * @hide
4634 */
4635 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4636 @NonNull String packageName, int userHandle) {
4637 if (mService != null) {
4638 try {
4639 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4640 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004641 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004642 }
4643 }
4644 return false;
4645 }
4646
4647 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004648 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004649 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004650 *
4651 * <p>Null means all input methods are allowed, if a non-null list is returned
4652 * it will contain the intersection of the permitted lists for any device or profile
4653 * owners that apply to this user. It will also include any system input methods.
4654 *
4655 * @return List of input method package names.
4656 * @hide
4657 */
4658 @SystemApi
4659 public List<String> getPermittedInputMethodsForCurrentUser() {
4660 if (mService != null) {
4661 try {
4662 return mService.getPermittedInputMethodsForCurrentUser();
4663 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004664 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004665 }
4666 }
4667 return null;
4668 }
4669
4670 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004671 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4672 * currently installed it.
4673 *
4674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4675 *
4676 * @return List of package names to keep cached.
4677 * @hide
4678 */
4679 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4680 if (mService != null) {
4681 try {
4682 return mService.getKeepUninstalledPackages(admin);
4683 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004684 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004685 }
4686 }
4687 return null;
4688 }
4689
4690 /**
4691 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4692 * currently installed it.
4693 *
4694 * <p>Please note that setting this policy does not imply that specified apps will be
4695 * automatically pre-cached.</p>
4696 *
4697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4698 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004699 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004700 * @hide
4701 */
4702 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4703 @NonNull List<String> packageNames) {
4704 if (mService != null) {
4705 try {
4706 mService.setKeepUninstalledPackages(admin, packageNames);
4707 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004708 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004709 }
4710 }
4711 }
4712
4713 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004714 * Called by a device owner to create a user with the specified name. The UserHandle returned
4715 * by this method should not be persisted as user handles are recycled as users are removed and
4716 * created. If you need to persist an identifier for this user, use
4717 * {@link UserManager#getSerialNumberForUser}.
4718 *
4719 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4720 * @param name the user's name
4721 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004722 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4723 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004724 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004725 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004726 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004727 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004728 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004729 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004730 return null;
4731 }
4732
4733 /**
Jason Monk03978a42014-06-10 15:05:30 -04004734 * Called by a device owner to create a user with the specified name. The UserHandle returned
4735 * by this method should not be persisted as user handles are recycled as users are removed and
4736 * created. If you need to persist an identifier for this user, use
4737 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4738 * immediately.
4739 *
4740 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4741 * as registered as an active admin on the new user. The profile owner package will be
4742 * installed on the new user if it already is installed on the device.
4743 *
4744 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4745 * profileOwnerComponent when onEnable is called.
4746 *
4747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4748 * @param name the user's name
4749 * @param ownerName the human readable name of the organisation associated with this DPM.
4750 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4751 * the user.
4752 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4753 * on the new user.
4754 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004755 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4756 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004757 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004758 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004759 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004760 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004761 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004762 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4763 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004764 return null;
4765 }
4766
4767 /**
phweissa92e1212016-01-25 17:14:10 +01004768 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004769 */
4770 public static final int SKIP_SETUP_WIZARD = 0x0001;
4771
4772 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004773 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4774 * ephemeral.
4775 * @hide
4776 */
4777 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4778
4779 /**
phweissa92e1212016-01-25 17:14:10 +01004780 * Called by a device owner to create a user with the specified name and a given component of
4781 * the calling package as profile owner. The UserHandle returned by this method should not be
4782 * persisted as user handles are recycled as users are removed and created. If you need to
4783 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4784 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004785 * <p>
4786 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
4787 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
4788 * be registered as an active admin on the new user. The profile owner package will be installed
4789 * on the new user.
4790 * <p>
4791 * If the adminExtras are not null, they will be stored on the device until the user is started
4792 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01004793 *
4794 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4795 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004796 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004797 * same package as admin, otherwise no user is created and an
4798 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01004799 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004800 * user.
phweissa92e1212016-01-25 17:14:10 +01004801 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004802 * @see UserHandle
4803 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4804 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004805 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01004806 */
4807 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004808 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4809 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004810 try {
phweissa92e1212016-01-25 17:14:10 +01004811 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004812 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004813 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01004814 }
phweiss343fb332016-01-25 14:48:59 +01004815 }
4816
4817 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004818 * Called by a device owner to remove a user and all associated data. The primary user can not
4819 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04004820 *
4821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4822 * @param userHandle the user to remove.
4823 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004824 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04004825 */
Robin Lee25e26452015-06-02 09:56:29 -07004826 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004827 try {
4828 return mService.removeUser(admin, userHandle);
4829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004830 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04004831 }
4832 }
4833
4834 /**
Jason Monk582d9112014-07-09 19:57:08 -04004835 * Called by a device owner to switch the specified user to the foreground.
4836 *
4837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4838 * @param userHandle the user to switch to; null will switch to primary.
4839 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004840 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04004841 * @see Intent#ACTION_USER_FOREGROUND
4842 */
Robin Lee25e26452015-06-02 09:56:29 -07004843 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004844 try {
4845 return mService.switchUser(admin, userHandle);
4846 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004847 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04004848 }
4849 }
4850
4851 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004852 * Retrieves the application restrictions for a given target application running in the calling
4853 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004854 * <p>
4855 * The caller must be a profile or device owner on that user, or the package allowed to manage
4856 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4857 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004858 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004859 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004860 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004861 * @param packageName The name of the package to fetch restricted settings of.
4862 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004863 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
4864 * {@link Bundle} if no restrictions have been set.
4865 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004866 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004867 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004868 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004869 if (mService != null) {
4870 try {
4871 return mService.getApplicationRestrictions(admin, packageName);
4872 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004873 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004874 }
4875 }
4876 return null;
4877 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004878
4879 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004880 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004881 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004882 * The calling device admin must be a profile or device owner; if it is not, a security
4883 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004884 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4886 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
4887 * for the list of keys.
4888 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07004889 */
Robin Lee25e26452015-06-02 09:56:29 -07004890 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004891 if (mService != null) {
4892 try {
4893 mService.setUserRestriction(admin, key, true);
4894 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004895 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004896 }
4897 }
4898 }
4899
4900 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004901 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004902 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004903 * The calling device admin must be a profile or device owner; if it is not, a security
4904 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004905 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4907 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
4908 * for the list of keys.
4909 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07004910 */
Robin Lee25e26452015-06-02 09:56:29 -07004911 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004912 if (mService != null) {
4913 try {
4914 mService.setUserRestriction(admin, key, false);
4915 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004916 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004917 }
4918 }
4919 }
Adam Connors010cfd42014-04-16 12:48:13 +01004920
4921 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004922 * Called by a profile or device owner to get user restrictions set with
4923 * {@link #addUserRestriction(ComponentName, String)}.
4924 * <p>
4925 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004926 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004927 * {@link UserManager#getUserRestrictions()}.
4928 *
4929 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004930 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004931 */
4932 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
4933 Bundle ret = null;
4934 if (mService != null) {
4935 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07004936 ret = mService.getUserRestrictions(admin);
4937 } catch (RemoteException e) {
4938 throw e.rethrowFromSystemServer();
4939 }
4940 }
4941 return ret == null ? new Bundle() : ret;
4942 }
4943
4944 /**
4945 * Called by the system to get the user restrictions for a user.
4946 *
4947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4948 * @param userHandle user id the admin is running as.
4949 *
4950 * @hide
4951 */
4952 public Bundle getUserRestrictionsForUser(@NonNull ComponentName admin, int userHandle) {
4953 Bundle ret = null;
4954 if (mService != null) {
4955 try {
4956 ret = mService.getUserRestrictionsForUser(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004957 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004958 throw e.rethrowFromSystemServer();
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004959 }
4960 }
4961 return ret == null ? new Bundle() : ret;
4962 }
4963
4964 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004965 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
4966 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04004967 *
4968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004969 * @param packageName The name of the package to hide or unhide.
4970 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004971 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004972 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004973 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04004974 */
Robin Lee25e26452015-06-02 09:56:29 -07004975 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004976 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004977 if (mService != null) {
4978 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004979 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004980 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004981 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004982 }
4983 }
4984 return false;
4985 }
4986
4987 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004988 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004989 *
4990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004991 * @param packageName The name of the package to retrieve the hidden status of.
4992 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004993 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04004994 */
Robin Lee25e26452015-06-02 09:56:29 -07004995 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004996 if (mService != null) {
4997 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004998 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004999 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005000 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005001 }
5002 }
5003 return false;
5004 }
5005
5006 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005007 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005008 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005009 *
5010 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005011 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005012 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005013 */
Robin Lee25e26452015-06-02 09:56:29 -07005014 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00005015 if (mService != null) {
5016 try {
5017 mService.enableSystemApp(admin, packageName);
5018 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005019 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005020 }
5021 }
5022 }
5023
5024 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005025 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5026 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005027 *
5028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5029 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005030 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005031 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005032 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005033 */
Robin Lee25e26452015-06-02 09:56:29 -07005034 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00005035 if (mService != null) {
5036 try {
5037 return mService.enableSystemAppWithIntent(admin, intent);
5038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005039 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005040 }
5041 }
5042 return 0;
5043 }
5044
5045 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005046 * Called by a device owner or profile owner to disable account management for a specific type
5047 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005048 * <p>
5049 * The calling device admin must be a device owner or profile owner. If it is not, a security
5050 * exception will be thrown.
5051 * <p>
5052 * When account management is disabled for an account type, adding or removing an account of
5053 * that type will not be possible.
5054 * <p>
5055 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005056 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5057 * management for a specific type is disabled.
5058 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005059 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5060 * @param accountType For which account management is disabled or enabled.
5061 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005062 * enabled (false).
5063 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005064 */
Robin Lee25e26452015-06-02 09:56:29 -07005065 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005066 boolean disabled) {
5067 if (mService != null) {
5068 try {
5069 mService.setAccountManagementDisabled(admin, accountType, disabled);
5070 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005071 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005072 }
5073 }
5074 }
5075
5076 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005077 * Gets the array of accounts for which account management is disabled by the profile owner.
5078 *
5079 * <p> Account management can be disabled/enabled by calling
5080 * {@link #setAccountManagementDisabled}.
5081 *
5082 * @return a list of account types for which account management has been disabled.
5083 *
5084 * @see #setAccountManagementDisabled
5085 */
5086 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005087 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005088 }
5089
5090 /**
5091 * @see #getAccountTypesWithManagementDisabled()
5092 * @hide
5093 */
5094 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005095 if (mService != null) {
5096 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005097 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005098 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005099 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005100 }
5101 }
5102
5103 return null;
5104 }
justinzhang511e0d82014-03-24 16:09:24 -04005105
5106 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005107 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005108 * <p>
5109 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5110 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5111 * package list results in locked tasks belonging to those packages to be finished. This
5112 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005113 *
Jason Monkd7b86212014-06-16 13:15:38 -04005114 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005115 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005116 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005117 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005118 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5119 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005120 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005121 */
Robin Lee25e26452015-06-02 09:56:29 -07005122 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005123 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04005124 if (mService != null) {
5125 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005126 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005128 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005129 }
5130 }
5131 }
5132
5133 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005134 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005135 *
5136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005137 * @hide
5138 */
Robin Lee25e26452015-06-02 09:56:29 -07005139 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04005140 if (mService != null) {
5141 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005142 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005144 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005145 }
5146 }
5147 return null;
5148 }
5149
5150 /**
5151 * This function lets the caller know whether the given component is allowed to start the
5152 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005153 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005154 */
Jason Monkd7b86212014-06-16 13:15:38 -04005155 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04005156 if (mService != null) {
5157 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005158 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005160 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005161 }
5162 }
5163 return false;
5164 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005165
5166 /**
5167 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5168 * 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 -07005169 * <p>
5170 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005171 * <ul>
5172 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5173 * <li>{@link Settings.Global#AUTO_TIME}</li>
5174 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005175 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005176 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005177 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005178 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5179 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5180 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5181 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5182 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005183 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005184 * <p>
5185 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005186 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005187 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5188 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5189 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005190 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005191 * <li>{@link Settings.Global#MODE_RINGER}. Use
5192 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005193 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005194 * <li>{@link Settings.Global#WIFI_ON}. Use
5195 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005196 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005197 *
5198 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5199 * @param setting The name of the setting to update.
5200 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005201 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005202 */
Robin Lee25e26452015-06-02 09:56:29 -07005203 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005204 if (mService != null) {
5205 try {
5206 mService.setGlobalSetting(admin, setting, value);
5207 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005208 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005209 }
5210 }
5211 }
5212
5213 /**
5214 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5215 * that the value of the setting is in the correct form for the setting type should be performed
5216 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005217 * <p>
5218 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005219 * <ul>
5220 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005221 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005222 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5223 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005224 * <p>
5225 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005226 * <ul>
5227 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5228 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005229 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5231 * @param setting The name of the setting to update.
5232 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005233 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005234 */
Robin Lee25e26452015-06-02 09:56:29 -07005235 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005236 if (mService != null) {
5237 try {
5238 mService.setSecureSetting(admin, setting, value);
5239 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005240 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005241 }
5242 }
5243 }
5244
Amith Yamasanif20d6402014-05-24 15:34:37 -07005245 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005246 * Designates a specific service component as the provider for making permission requests of a
5247 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005248 * <p/>
5249 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005250 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005252 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005253 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5254 * provider previously assigned.
5255 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005256 */
Robin Lee25e26452015-06-02 09:56:29 -07005257 public void setRestrictionsProvider(@NonNull ComponentName admin,
5258 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005259 if (mService != null) {
5260 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005261 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005262 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005263 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005264 }
5265 }
5266 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005267
5268 /**
5269 * Called by profile or device owners to set the master volume mute on or off.
5270 *
5271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5272 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005273 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005274 */
Robin Lee25e26452015-06-02 09:56:29 -07005275 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005276 if (mService != null) {
5277 try {
5278 mService.setMasterVolumeMuted(admin, on);
5279 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005280 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005281 }
5282 }
5283 }
5284
5285 /**
5286 * Called by profile or device owners to check whether the master volume mute is on or off.
5287 *
5288 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5289 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005290 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005291 */
Robin Lee25e26452015-06-02 09:56:29 -07005292 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005293 if (mService != null) {
5294 try {
5295 return mService.isMasterVolumeMuted(admin);
5296 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005297 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005298 }
5299 }
5300 return false;
5301 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005302
5303 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005304 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005305 *
5306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5307 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005308 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005309 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005310 */
Robin Lee25e26452015-06-02 09:56:29 -07005311 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005312 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005313 if (mService != null) {
5314 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005315 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005316 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005317 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005318 }
5319 }
5320 }
5321
5322 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005323 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005324 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005325 * <p>
5326 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005327 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5328 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5329 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005330 *
Robin Lee25e26452015-06-02 09:56:29 -07005331 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005332 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005333 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005334 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005335 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005336 */
Robin Lee25e26452015-06-02 09:56:29 -07005337 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005338 if (mService != null) {
5339 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005340 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005341 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005342 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005343 }
5344 }
5345 return false;
5346 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005347
5348 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005349 * Called by the profile owner of a managed profile to enable widget providers from a given
5350 * package to be available in the parent profile. As a result the user will be able to add
5351 * widgets from the white-listed package running under the profile to a widget host which runs
5352 * under the parent profile, for example the home screen. Note that a package may have zero or
5353 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005354 * <p>
5355 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005356 *
5357 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5358 * @param packageName The package from which widget providers are white-listed.
5359 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005360 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005361 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5362 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5363 */
Robin Lee25e26452015-06-02 09:56:29 -07005364 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005365 if (mService != null) {
5366 try {
5367 return mService.addCrossProfileWidgetProvider(admin, packageName);
5368 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005369 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005370 }
5371 }
5372 return false;
5373 }
5374
5375 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005376 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005377 * package to be available in the parent profile. For this method to take effect the package
5378 * should have been added via
5379 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005380 * <p>
5381 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005382 *
5383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005384 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005385 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005386 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005387 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5388 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5389 */
Esteban Talavera62399912016-01-11 15:37:55 +00005390 public boolean removeCrossProfileWidgetProvider(
5391 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005392 if (mService != null) {
5393 try {
5394 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5395 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005396 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005397 }
5398 }
5399 return false;
5400 }
5401
5402 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005403 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005404 * available in the parent profile.
5405 *
5406 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5407 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005408 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5409 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005410 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005411 */
Robin Lee25e26452015-06-02 09:56:29 -07005412 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005413 if (mService != null) {
5414 try {
5415 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5416 if (providers != null) {
5417 return providers;
5418 }
5419 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005420 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005421 }
5422 }
5423 return Collections.emptyList();
5424 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005425
5426 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005427 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005428 *
5429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5430 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005431 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005432 */
Robin Lee25e26452015-06-02 09:56:29 -07005433 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005434 try {
5435 mService.setUserIcon(admin, icon);
5436 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005437 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005438 }
5439 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005440
5441 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005442 * Called by device owners to set a local system update policy. When a new policy is set,
5443 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005444 *
Robin Lee25e26452015-06-02 09:56:29 -07005445 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005446 * components in the device owner package can set system update policies and the most
5447 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005448 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005449 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005450 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005451 */
Robin Lee25e26452015-06-02 09:56:29 -07005452 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005453 if (mService != null) {
5454 try {
Robin Lee25e26452015-06-02 09:56:29 -07005455 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005456 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005457 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005458 }
5459 }
5460 }
5461
5462 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005463 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005464 *
Robin Lee25e26452015-06-02 09:56:29 -07005465 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005466 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005467 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005468 if (mService != null) {
5469 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005470 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005471 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005472 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005473 }
5474 }
5475 return null;
5476 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005477
5478 /**
5479 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005480 * <p>
5481 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5482 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5483 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5484 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005485 *
5486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005487 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005488 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005489 * place. {@code true} otherwise.
5490 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005491 */
Robin Lee25e26452015-06-02 09:56:29 -07005492 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005493 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005494 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005495 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005496 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005497 }
5498 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005499
5500 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005501 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005502 * notifications, quick settings and other screen overlays that allow escaping from a single use
5503 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005504 *
5505 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005506 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005507 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5508 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005509 */
Robin Lee25e26452015-06-02 09:56:29 -07005510 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005511 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005512 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005513 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005514 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005515 }
5516 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005517
5518 /**
5519 * Callable by the system update service to notify device owners about pending updates.
5520 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5521 * permission.
5522 *
5523 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5524 * when the current pending update was first available. -1 if no update is available.
5525 * @hide
5526 */
5527 @SystemApi
5528 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5529 if (mService != null) {
5530 try {
5531 mService.notifyPendingSystemUpdate(updateReceivedTime);
5532 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005533 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005534 }
5535 }
5536 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005537
5538 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005539 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005540 * requests by applications. The policy can allow for normal operation which prompts the user to
5541 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5542 * by an application. This also applies to new permissions declared by app updates. When a
5543 * permission is denied or granted this way, the effect is equivalent to setting the permission
5544 * grant state via {@link #setPermissionGrantState}.
5545 * <p/>
5546 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005547 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005548 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005549 * @param admin Which profile or device owner this request is associated with.
5550 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005551 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5552 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005553 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005554 */
Robin Lee25e26452015-06-02 09:56:29 -07005555 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005556 try {
5557 mService.setPermissionPolicy(admin, policy);
5558 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005559 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005560 }
5561 }
5562
5563 /**
5564 * Returns the current runtime permission policy set by the device or profile owner. The
5565 * default is {@link #PERMISSION_POLICY_PROMPT}.
5566 * @param admin Which profile or device owner this request is associated with.
5567 * @return the current policy for future permission requests.
5568 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005569 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005570 try {
5571 return mService.getPermissionPolicy(admin);
5572 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005573 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005574 }
5575 }
5576
5577 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005578 * Sets the grant state of a runtime permission for a specific application. The state can be
5579 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5580 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5581 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5582 * the permission is granted and the user cannot manage it through the UI. This might affect all
5583 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005584 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005585 * <p/>
5586 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5587 * the permission. It retains the previous grant, if any.
5588 * <p/>
5589 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005590 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005591 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005592 * @param admin Which profile or device owner this request is associated with.
5593 * @param packageName The application to grant or revoke a permission to.
5594 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005595 * @param grantState The permission grant state which is one of
5596 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5597 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005598 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005599 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005600 * @see #PERMISSION_GRANT_STATE_DENIED
5601 * @see #PERMISSION_GRANT_STATE_DEFAULT
5602 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005603 */
Robin Lee25e26452015-06-02 09:56:29 -07005604 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005605 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005606 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005607 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005608 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005609 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005610 }
5611 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005612
5613 /**
5614 * Returns the current grant state of a runtime permission for a specific application.
5615 *
5616 * @param admin Which profile or device owner this request is associated with.
5617 * @param packageName The application to check the grant state for.
5618 * @param permission The permission to check for.
5619 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005620 * has not set a grant state, the return value is
5621 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5622 * permission is currently granted for the package.
5623 * <p/>
5624 * If a grant state was set by the profile or device owner, then the return value will
5625 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5626 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5627 * currently denied or granted.
5628 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005629 * @see #setPermissionGrantState(ComponentName, String, String, int)
5630 * @see PackageManager#checkPermission(String, String)
5631 */
Robin Lee25e26452015-06-02 09:56:29 -07005632 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005633 String permission) {
5634 try {
5635 return mService.getPermissionGrantState(admin, packageName, permission);
5636 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005637 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005638 }
5639 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005640
5641 /**
5642 * Returns if provisioning a managed profile or device is possible or not.
5643 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5644 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005645 * @return if provisioning a managed profile or device is possible or not.
5646 * @throws IllegalArgumentException if the supplied action is not valid.
5647 */
5648 public boolean isProvisioningAllowed(String action) {
5649 try {
5650 return mService.isProvisioningAllowed(action);
5651 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005652 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005653 }
5654 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005655
5656 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005657 * Return if this user is a managed profile of another user. An admin can become the profile
5658 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01005659 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005660 * @param admin Which profile owner this request is associated with.
5661 * @return if this user is a managed profile of another user.
5662 */
5663 public boolean isManagedProfile(@NonNull ComponentName admin) {
5664 try {
5665 return mService.isManagedProfile(admin);
5666 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005667 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005668 }
5669 }
5670
5671 /**
5672 * @hide
5673 * Return if this user is a system-only user. An admin can manage a device from a system only
5674 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5675 * @param admin Which device owner this request is associated with.
5676 * @return if this user is a system-only user.
5677 */
5678 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5679 try {
5680 return mService.isSystemOnlyUser(admin);
5681 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005682 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005683 }
5684 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005685
5686 /**
5687 * Called by device owner to get the MAC address of the Wi-Fi device.
5688 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005689 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005690 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5691 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5692 * <p>
5693 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5694 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005695 */
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005696 public String getWifiMacAddress(@NonNull ComponentName admin) {
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005697 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005698 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005699 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005700 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005701 }
5702 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005703
5704 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005705 * Called by device owner to reboot the device. If there is an ongoing call on the device,
5706 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005707 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005708 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005709 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005710 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005711 */
5712 public void reboot(@NonNull ComponentName admin) {
5713 try {
5714 mService.reboot(admin);
5715 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005716 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005717 }
5718 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005719
5720 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005721 * Called by a device admin to set the short support message. This will be displayed to the user
5722 * in settings screens where funtionality has been disabled by the admin. The message should be
5723 * limited to a short statement such as "This setting is disabled by your administrator. Contact
5724 * someone@example.com for support." If the message is longer than 200 characters it may be
5725 * truncated.
5726 * <p>
5727 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005728 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5729 * and set a new version of this string accordingly.
5730 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005731 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005732 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005733 * @param message Short message to be displayed to the user in settings or null to clear the
5734 * existing message.
5735 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005736 */
5737 public void setShortSupportMessage(@NonNull ComponentName admin,
5738 @Nullable String message) {
5739 if (mService != null) {
5740 try {
5741 mService.setShortSupportMessage(admin, message);
5742 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005743 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005744 }
5745 }
5746 }
5747
5748 /**
5749 * Called by a device admin to get the short support message.
5750 *
5751 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005752 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} or null if
5753 * no message has been set.
5754 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005755 */
5756 public String getShortSupportMessage(@NonNull ComponentName admin) {
5757 if (mService != null) {
5758 try {
5759 return mService.getShortSupportMessage(admin);
5760 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005761 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005762 }
5763 }
5764 return null;
5765 }
5766
5767 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005768 * Called by a device admin to set the long support message. This will be displayed to the user
5769 * in the device administators settings screen.
5770 * <p>
5771 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005772 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5773 * and set a new version of this string accordingly.
5774 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005775 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005777 * @param message Long message to be displayed to the user in settings or null to clear the
5778 * existing message.
5779 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005780 */
5781 public void setLongSupportMessage(@NonNull ComponentName admin,
5782 @Nullable String message) {
5783 if (mService != null) {
5784 try {
5785 mService.setLongSupportMessage(admin, message);
5786 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005787 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005788 }
5789 }
5790 }
5791
5792 /**
5793 * Called by a device admin to get the long support message.
5794 *
5795 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005796 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} or null if
5797 * no message has been set.
5798 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005799 */
5800 public String getLongSupportMessage(@NonNull ComponentName admin) {
5801 if (mService != null) {
5802 try {
5803 return mService.getLongSupportMessage(admin);
5804 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005805 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005806 }
5807 }
5808 return null;
5809 }
5810
5811 /**
5812 * Called by the system to get the short support message.
5813 *
5814 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5815 * @param userHandle user id the admin is running as.
5816 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5817 *
5818 * @hide
5819 */
5820 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5821 if (mService != null) {
5822 try {
5823 return mService.getShortSupportMessageForUser(admin, userHandle);
5824 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005825 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005826 }
5827 }
5828 return null;
5829 }
5830
5831
5832 /**
5833 * Called by the system to get the long support message.
5834 *
5835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5836 * @param userHandle user id the admin is running as.
5837 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5838 *
5839 * @hide
5840 */
5841 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5842 if (mService != null) {
5843 try {
5844 return mService.getLongSupportMessageForUser(admin, userHandle);
5845 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005846 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005847 }
5848 }
5849 return null;
5850 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005851
5852 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005853 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5854 * whose calls act on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005855 * <p>
5856 * Note only some methods will work on the parent Manager.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005857 *
5858 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005859 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005860 */
5861 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5862 try {
5863 if (!mService.isManagedProfile(admin)) {
5864 throw new SecurityException("The current user does not have a parent profile.");
5865 }
5866 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005867 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005868 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005869 }
5870 }
5871
5872 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005873 * Called by device owner to control the security logging feature. Logging can only be
5874 * enabled on single user devices where the sole user is managed by the device owner.
5875 *
5876 * <p> Security logs contain various information intended for security auditing purposes.
5877 * See {@link SecurityEvent} for details.
5878 *
5879 * <p>There must be only one user on the device, managed by the device owner.
5880 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005881 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005882 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00005883 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005884 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00005885 * @see #retrieveSecurityLogs
5886 */
5887 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5888 try {
5889 mService.setSecurityLoggingEnabled(admin, enabled);
5890 } catch (RemoteException re) {
5891 throw re.rethrowFromSystemServer();
5892 }
5893 }
5894
5895 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005896 * Return whether security logging is enabled or not by the device owner.
5897 *
5898 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
5899 * thrown.
5900 *
5901 * @param admin Which device owner this request is associated with.
5902 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
5903 * @throws SecurityException if {@code admin} is not a device owner.
5904 */
5905 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005906 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005907 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005908 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005909 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005910 }
5911 }
5912
5913 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005914 * Called by device owner to retrieve all new security logging entries since the last call to
5915 * this API after device boots.
5916 *
5917 * <p> Access to the logs is rate limited and it will only return new logs after the device
5918 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5919 *
5920 * <p>There must be only one user on the device, managed by the device owner.
5921 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005922 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005923 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00005924 * @return the new batch of security logs which is a list of {@link SecurityEvent},
5925 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005926 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005927 */
Michal Karpinski6235a942016-03-15 12:07:23 +00005928 public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005929 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005930 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005931 if (list != null) {
5932 return list.getList();
5933 } else {
5934 // Rate limit exceeded.
5935 return null;
5936 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005937 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005938 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005939 }
5940 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005941
5942 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005943 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5944 * profile.
5945 *
5946 * @hide
5947 */
5948 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5949 mContext.checkSelfPermission(
5950 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5951 if (!uInfo.isManagedProfile()) {
5952 throw new SecurityException("The user " + uInfo.id
5953 + " does not have a parent profile.");
5954 }
5955 return new DevicePolicyManager(mContext, true);
5956 }
5957
5958 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005959 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005960 * <p>
5961 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005962 * corruption-free during power cycles, due to hardware variations and limitations. As a result,
Michal Karpinskie0e100982016-03-30 15:02:26 +01005963 * this API is provided as best-effort and the returned logs may be empty or contain corrupted
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005964 * data. </strong>
5965 * <p>
5966 * There must be only one user on the device, managed by the device owner. Otherwise a
5967 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005968 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005969 * @param admin Which device owner this request is associated with.
5970 * @return Device logs from before the latest reboot of the system.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005971 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005972 */
Michal Karpinski6235a942016-03-15 12:07:23 +00005973 public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005974 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005975 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005976 return list.getList();
5977 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005978 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005979 }
5980 }
5981
5982 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005983 * Called by a profile owner of a managed profile to set the color used for customization. This
5984 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01005985 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005986 * <p>
5987 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00005988 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5989 *
5990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5991 * @param color The 32bit representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005992 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00005993 */
5994 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5995 try {
5996 mService.setOrganizationColor(admin, color);
5997 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005998 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005999 }
6000 }
6001
6002 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006003 * @hide
6004 *
6005 * Sets the color used for customization.
6006 *
6007 * @param color The 32bit representation of the color to be used.
6008 * @param userId which user to set the color to.
6009 * @RequiresPermission(allOf = {
6010 * Manifest.permission.MANAGE_USERS,
6011 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6012 */
6013 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6014 try {
6015 mService.setOrganizationColorForUser(color, userId);
6016 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006017 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006018 }
6019 }
6020
6021 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006022 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6023 * This color is used as background color of the confirm credentials screen for that user.
6024 *
6025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6026 * @return The 32bit representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006027 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006028 */
6029 public int getOrganizationColor(@NonNull ComponentName admin) {
6030 try {
6031 return mService.getOrganizationColor(admin);
6032 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006033 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006034 }
6035 }
6036
6037 /**
6038 * @hide
6039 * Retrieve the customization color for a given user.
6040 *
6041 * @param userHandle The user id of the user we're interested in.
6042 * @return The 32bit representation of the color to be used.
6043 */
6044 public int getOrganizationColorForUser(int userHandle) {
6045 try {
6046 return mService.getOrganizationColorForUser(userHandle);
6047 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006048 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006049 }
6050 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006051
6052 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006053 * Called by a profile owner of a managed profile to set the name of the organization under
6054 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006055 * <p>
6056 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006057 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6058 * and set a new version of this string accordingly.
6059 *
6060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6061 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006062 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006063 */
6064 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
6065 try {
6066 mService.setOrganizationName(admin, title);
6067 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006068 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006069 }
6070 }
6071
6072 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006073 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6074 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006075 *
6076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6077 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006078 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006079 */
6080 public String getOrganizationName(@NonNull ComponentName admin) {
6081 try {
6082 return mService.getOrganizationName(admin);
6083 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006084 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006085 }
6086 }
6087
6088 /**
6089 * Retrieve the default title message used in the confirm credentials screen for a given user.
6090 *
6091 * @param userHandle The user id of the user we're interested in.
6092 * @return The organization name or {@code null} if none is set.
6093 *
6094 * @hide
6095 */
6096 public String getOrganizationNameForUser(int userHandle) {
6097 try {
6098 return mService.getOrganizationNameForUser(userHandle);
6099 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006100 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006101 }
6102 }
6103
6104 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006105 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6106 * return {@link #STATE_USER_UNMANAGED}
6107 * @hide
6108 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006109 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006110 @UserProvisioningState
6111 public int getUserProvisioningState() {
6112 if (mService != null) {
6113 try {
6114 return mService.getUserProvisioningState();
6115 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006116 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006117 }
6118 }
6119 return STATE_USER_UNMANAGED;
6120 }
6121
6122 /**
6123 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6124 *
6125 * @param state to store
6126 * @param userHandle for user
6127 * @hide
6128 */
6129 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6130 if (mService != null) {
6131 try {
6132 mService.setUserProvisioningState(state, userHandle);
6133 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006134 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006135 }
6136 }
6137 }
6138
6139 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006140 * @hide
6141 * Indicates the entity that controls the device or profile owner. A user/profile is considered
6142 * affiliated if it is managed by the same entity as the device.
6143 *
6144 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
6145 * user/profile is considered affiliated if the following conditions are both met:
6146 * <ul>
6147 * <li>The device owner and the user's/profile's profile owner have called this method,
6148 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
6149 * and a profile owner intersect, they must have come from the same source, which means that
6150 * the device owner and profile owner are controlled by the same entity.</li>
6151 * <li>The device owner's and profile owner's package names are the same.</li>
6152 * </ul>
6153 *
6154 * @param admin Which profile or device owner this request is associated with.
6155 * @param ids A set of opaque affiliation ids.
6156 */
6157 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
6158 try {
6159 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
6160 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006161 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006162 }
6163 }
6164
6165 /**
6166 * @hide
6167 * Returns whether this user/profile is affiliated with the device. See
6168 * {@link #setAffiliationIds} for the definition of affiliation.
6169 *
6170 * @return whether this user/profile is affiliated with the device.
6171 */
6172 public boolean isAffiliatedUser() {
6173 try {
6174 return mService != null && mService.isAffiliatedUser();
6175 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006176 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006177 }
6178 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006179
6180 /**
6181 * @hide
6182 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6183 * to be started
6184 * @param packageName the package to check for
6185 * @return whether the uninstall intent for {@code packageName} is pending
6186 */
6187 public boolean isUninstallInQueue(String packageName) {
6188 try {
6189 return mService.isUninstallInQueue(packageName);
6190 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006191 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006192 }
6193 }
6194
6195 /**
6196 * @hide
6197 * @param packageName the package containing active DAs to be uninstalled
6198 */
6199 public void uninstallPackageWithActiveAdmins(String packageName) {
6200 try {
6201 mService.uninstallPackageWithActiveAdmins(packageName);
6202 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006203 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006204 }
6205 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006206}