blob: cbb6732d7b8be01aed37aea04db82a56fac3e736 [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;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000028import android.auditing.SecurityLog;
29import android.auditing.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.content.ComponentName;
31import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010032import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000033import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000036import android.content.pm.ParceledListSlice;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.content.pm.ResolveInfo;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000038import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050039import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040040import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000041import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010042import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070043import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000044import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080045import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.os.RemoteException;
47import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070048import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040049import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000050import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000051import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010052import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070053import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import android.util.Log;
55
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070056import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040057import com.android.org.conscrypt.TrustedCertificateStore;
58
Jessica Hummel91da58d2014-04-10 17:39:43 +010059import org.xmlpull.v1.XmlPullParserException;
60
Maggie Benthallda51e682013-08-08 22:35:44 -040061import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080062import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000063import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070065import java.net.InetSocketAddress;
66import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010067import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000068import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010069import java.security.PrivateKey;
70import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040071import java.security.cert.CertificateException;
72import java.security.cert.CertificateFactory;
73import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010074import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000075import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070076import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070077import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080078import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010079import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080080
81/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000082 * Public interface for managing policies enforced on a device. Most clients of this class must be
83 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000084 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000085 * a device administrator may be registered as either a profile or device owner. A given method is
86 * accessible to all device administrators unless the documentation for that method specifies that
87 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080088 *
89 * <div class="special reference">
90 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000091 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080092 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070093 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080094 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080095 */
96public class DevicePolicyManager {
97 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080098
99 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000101 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700102
Makoto Onukic8a5a552015-11-19 14:29:12 -0800103 private static final String REMOTE_EXCEPTION_MESSAGE =
104 "Failed to talk with device policy manager service";
105
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000106 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000107 this(context,
108 IDevicePolicyManager.Stub.asInterface(
109 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
110 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800111 }
112
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800113 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000115 protected DevicePolicyManager(
116 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 mContext = context;
118 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000119 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 }
121
122 /** @hide */
123 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000124 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800125 return me.mService != null ? me : null;
126 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700127
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700128 /** @hide test will override it. */
129 @VisibleForTesting
130 protected int myUserId() {
131 return UserHandle.myUserId();
132 }
133
Dianne Hackbornd6847842010-01-12 18:14:19 -0800134 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000135 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000136 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100137 * <p>A managed profile allows data separation for example for the usage of a
138 * device as a personal and corporate device. The user which provisioning is started from and
139 * the managed profile share a launcher.
140 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800141 * <p>This intent will typically be sent by a mobile device management application (MDM).
142 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
143 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100144 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000145 * <p>It is possible to check if provisioning is allowed or not by querying the method
146 * {@link #isProvisioningAllowed(String)}.
147 *
148 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000149 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700150 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000151 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
152 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000153 *
154 * <p> The intent may also contain the following extras:
155 * <ul>
156 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
157 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
158 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000159 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000160 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
161 * in the provisioning intent. The
162 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
163 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
164 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100165 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100166 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
167 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100168 *
169 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
170 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
171 * the provisioning flow was successful, although this doesn't guarantee the full flow will
172 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
173 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000174 */
175 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
176 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100177 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000178
179 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000180 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000181 * Activity action: Starts the provisioning flow which sets up a managed user.
182 *
183 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800184 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000185 * owner who has full control over the user. Provisioning can only happen before user setup has
186 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
187 * allowed.
188 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000189 * <p>This intent should contain the extra
190 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000191 *
192 * <p> If provisioning fails, the device returns to its previous state.
193 *
194 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
195 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
196 * the provisioning flow was successful, although this doesn't guarantee the full flow will
197 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
198 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000199 */
200 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
201 public static final String ACTION_PROVISION_MANAGED_USER
202 = "android.app.action.PROVISION_MANAGED_USER";
203
204 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 * Activity action: Starts the provisioning flow which sets up a managed device.
206 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
207 *
208 * <p> During device owner provisioning a device admin app is set as the owner of the device.
209 * A device owner has full control over the device. The device owner can not be modified by the
210 * user.
211 *
212 * <p> A typical use case would be a device that is owned by a company, but used by either an
213 * employee or client.
214 *
215 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000216 * It is possible to check if provisioning is allowed or not by querying the method
217 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100218 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000219 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100220 * <ul>
221 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
222 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
223 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100224 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000225 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000226 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100227 * </ul>
228 *
229 * <p> When device owner provisioning has completed, an intent of the type
230 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
231 * device owner.
232 *
233 * <p> If provisioning fails, the device is factory reset.
234 *
Alan Treadway4582f812015-07-28 11:49:35 +0100235 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
236 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
237 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
238 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 */
240 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
241 public static final String ACTION_PROVISION_MANAGED_DEVICE
242 = "android.app.action.PROVISION_MANAGED_DEVICE";
243
244 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000245 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000246 *
247 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
248 * the device. A device owner has full control over the device. The device owner can not be
249 * modified by the user and the only way of resetting the device is via factory reset.
250 *
251 * <p>A typical use case would be a device that is owned by a company, but used by either an
252 * employee or client.
253 *
254 * <p>The provisioning message should be sent to an unprovisioned device.
255 *
256 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
257 * by a privileged app with the permission
258 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
259 *
260 * <p>The provisioning intent contains the following properties:
261 * <ul>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
263 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
278 *
279 * @hide
280 */
281 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
282 @SystemApi
283 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
284 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
285
286 /**
287 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000288 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
289 *
290 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
291 * management state that is distinct from that reached by
292 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
293 * user, and only has control over device-wide policies, not individual users and their data.
294 * The primary benefit is that multiple non-system users are supported when provisioning using
295 * this form of device management.
296 *
297 * <p> During device owner provisioning a device admin app is set as the owner of the device.
298 * A device owner has full control over the device. The device owner can not be modified by the
299 * user.
300 *
301 * <p> A typical use case would be a device that is owned by a company, but used by either an
302 * employee or client.
303 *
304 * <p> An intent with this action can be sent only on an unprovisioned device.
305 * It is possible to check if provisioning is allowed or not by querying the method
306 * {@link #isProvisioningAllowed(String)}.
307 *
308 * <p>The intent contains the following extras:
309 * <ul>
310 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
311 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
314 * </ul>
315 *
316 * <p> When device owner provisioning has completed, an intent of the type
317 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
318 * device owner.
319 *
320 * <p> If provisioning fails, the device is factory reset.
321 *
322 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
323 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
324 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
325 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
326 *
327 * @hide
328 */
329 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
330 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
331 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
332
333 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000334 * Activity action: Finalizes management provisioning, should be used after user-setup
335 * has been completed and {@link #getUserProvisioningState()} returns one of:
336 * <ul>
337 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
338 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
339 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
340 * </ul>
341 *
342 * @hide
343 */
344 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
345 public static final String ACTION_PROVISION_FINALIZATION
346 = "android.app.action.PROVISION_FINALIZATION";
347
348 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100349 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100350 * allows a mobile device management application or NFC programmer application which starts
351 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100352 * <p>
353 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
354 * sends the intent to pass data to itself on the newly created profile.
355 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
356 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100357 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
358 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
359 * message should contain a stringified {@link java.util.Properties} instance, whose string
360 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
361 * management application after provisioning.
362 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100363 * <p>
364 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700365 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
366 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100367 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100368 */
369 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100370 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100371
372 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 * A String extra holding the package name of the mobile device management application that
374 * will be set as the profile owner or device owner.
375 *
376 * <p>If an application starts provisioning directly via an intent with action
377 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
378 * application that started provisioning. The package will be set as profile owner in that case.
379 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000380 * <p>This package is set as device owner when device owner provisioning is started by an NFC
381 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000382 *
383 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700384 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000385
386 * @see DeviceAdminReceiver
387 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100388 * supported, but only if there is only one device admin receiver in the package that requires
389 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000390 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000391 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000392 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100393 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000394
395 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000396 * A ComponentName extra indicating the device admin receiver of the mobile device management
397 * application that will be set as the profile owner or device owner and active admin.
398 *
399 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100400 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
401 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
402 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000403 *
404 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100405 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
406 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400407 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000408 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000409 *
410 * @see DeviceAdminReceiver
411 */
412 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
413 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
414
415 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000416 * An {@link android.accounts.Account} extra holding the account to migrate during managed
417 * profile provisioning. If the account supplied is present in the primary user, it will be
418 * copied, along with its credentials to the managed profile and removed from the primary user.
419 *
420 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
421 */
422
423 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
424 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
425
426 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100427 * A String extra that, holds the email address of the account which a managed profile is
428 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
429 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100430 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100431 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
432 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100433 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
434 * contains this extra, it is forwarded in the
435 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
436 * device management application that was set as the profile owner during provisioning.
437 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100438 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100439 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
440 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100441
442 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000443 * A integer extra indicating the predominant color to show during the provisioning.
444 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000445 *
446 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
447 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
448 */
449 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
450 "android.app.extra.PROVISIONING_MAIN_COLOR";
451
452 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000453 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700454 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000455 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100456 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
457 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000458 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000459 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
460 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000461
462 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100463 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
464 * will be set to.
465 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000466 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
467 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100468 */
469 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100470 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100471
472 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100473 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
474 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100475 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000476 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
477 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100478 */
479 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100480 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100481
482 /**
483 * A String extra holding the {@link java.util.Locale} that the device will be set to.
484 * Format: xx_yy, where xx is the language code, and yy the country code.
485 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000486 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
487 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100488 */
489 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100490 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100491
492 /**
493 * A String extra holding the ssid of the wifi network that should be used during nfc device
494 * owner provisioning for downloading the mobile device management application.
495 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000496 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
497 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100498 */
499 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100500 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100501
502 /**
503 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
504 * is hidden or not.
505 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000506 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
507 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100508 */
509 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100510 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511
512 /**
513 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100514 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
515 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100516 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000517 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
518 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100519 */
520 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100521 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100522
523 /**
524 * A String extra holding the password of the wifi network in
525 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
526 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
528 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100529 */
530 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100531 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100532
533 /**
534 * A String extra holding the proxy host for the wifi network in
535 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100541 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542
543 /**
544 * An int extra holding the proxy port for the wifi network in
545 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
546 *
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_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100551 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552
553 /**
554 * A String extra holding the proxy bypass for the wifi network in
555 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100561 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562
563 /**
564 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
565 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100571 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572
573 /**
574 * A String extra holding a url that specifies the download location of the device admin
575 * package. When not provided it is assumed that the device admin package is already installed.
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_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400584 * An int extra holding a minimum required version code for the device admin package. If the
585 * device admin is already installed on the device, it will only be re-downloaded from
586 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
587 * installed package is less than this version code.
588 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400589 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400590 * provisioning via an NFC bump.
591 */
592 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
593 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
594
595 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100596 * A String extra holding a http cookie header which should be used in the http request to the
597 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
598 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000599 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
600 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100601 */
602 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100603 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100604
605 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100606 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
607 * the file at download location specified in
608 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100609 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100610 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100611 * present. The provided checksum should match the checksum of the file at the download
612 * location. If the checksum doesn't match an error will be shown to the user and the user will
613 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100614 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000615 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
616 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100617 *
618 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
619 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700620 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100621 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 */
623 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100624 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625
626 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100627 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100628 * android package archive at the download location specified in {@link
629 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
630 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100631 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100632 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
633 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
634 *
635 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100636 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100637 * the download location. If the checksum does not match an error will be shown to the user and
638 * the user will be asked to factory reset the device.
639 *
640 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
641 * provisioning via an NFC bump.
642 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100643 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
644 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100645
646 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000647 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
648 * has completed successfully.
649 *
650 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700651 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000652 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800653 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000654 * corresponds to the account requested to be migrated at provisioning time, if any.
655 */
656 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
657 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
658 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
659
660 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400661 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500662 * provisioning.
663 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400664 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100665 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500666 */
667 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
668 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
669
670 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000671 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
672 * provisioning. If this extra is not passed, a default image will be shown.
673 * <h5>The following URI schemes are accepted:</h5>
674 * <ul>
675 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
676 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
677 * </ul>
678 *
679 * <p> It is the responsability of the caller to provide an image with a reasonable
680 * pixed density for the device.
681 *
682 * <p> If a content: URI is passed, the intent should have the flag
683 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
684 * {@link android.content.ClipData} of the intent too.
685 *
686 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
687 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
688 */
689 public static final String EXTRA_PROVISIONING_LOGO_URI =
690 "android.app.extra.PROVISIONING_LOGO_URI";
691
692 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000693 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
694 * during setup-wizard.
695 *
696 * <p>If unspecified, defaults to {@code true} to match the behavior in
697 * {@link android.os.Build.VERSION_CODES#M} and earlier.
698 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000699 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
700 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000701 *
702 * @hide
703 */
704 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
705 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
706
707 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400708 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100709 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400710 * <p>During device owner provisioning a device admin app is set as the owner of the device.
711 * A device owner has full control over the device. The device owner can not be modified by the
712 * user and the only way of resetting the device is if the device owner app calls a factory
713 * reset.
714 *
715 * <p> A typical use case would be a device that is owned by a company, but used by either an
716 * employee or client.
717 *
718 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100719 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000720 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100721 * contains the following properties:
722 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400723 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
724 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100725 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400726 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100727 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
728 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
729 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
730 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
731 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
732 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
733 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
734 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
735 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
736 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100737 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
738 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
739 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100740 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000741 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700742 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400743 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
744 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
745 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400746 */
747 public static final String MIME_TYPE_PROVISIONING_NFC
748 = "application/com.android.managedprovisioning";
749
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100750 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800751 * Activity action: ask the user to add a new device administrator to the system.
752 * The desired policy is the ComponentName of the policy in the
753 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
754 * bring the user through adding the device administrator to the system (or
755 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700756 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800757 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
758 * field to provide the user with additional explanation (in addition
759 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800760 *
761 * <p>If your administrator is already active, this will ordinarily return immediately (without
762 * user intervention). However, if your administrator has been updated and is requesting
763 * additional uses-policy flags, the user will be presented with the new list. New policies
764 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800765 */
766 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
767 public static final String ACTION_ADD_DEVICE_ADMIN
768 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769
Dianne Hackbornd6847842010-01-12 18:14:19 -0800770 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700771 * @hide
772 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700773 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700774 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700775 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
776 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700777 * to remotely control restrictions on the user.
778 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800779 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700780 * result of whether or not the user approved the action. If approved, the result will
781 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
782 * as a profile owner.
783 *
784 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
785 * field to provide the user with additional explanation (in addition
786 * to your component's description) about what is being added.
787 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700788 * <p>If there is already a profile owner active or the caller is not a system app, the
789 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700790 */
791 @SystemApi
792 public static final String ACTION_SET_PROFILE_OWNER
793 = "android.app.action.SET_PROFILE_OWNER";
794
795 /**
796 * @hide
797 * Name of the profile owner admin that controls the user.
798 */
799 @SystemApi
800 public static final String EXTRA_PROFILE_OWNER_NAME
801 = "android.app.extra.PROFILE_OWNER_NAME";
802
803 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100804 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700805 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700806 *
Jim Miller284b62e2010-06-08 14:27:42 -0700807 * @hide
808 */
809 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
810 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
811
812 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100813 * Broadcast action: sent when the device owner is set or changed.
814 *
815 * This broadcast is sent only to the primary user.
816 * @see #ACTION_PROVISION_MANAGED_DEVICE
817 */
818 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
819 public static final String ACTION_DEVICE_OWNER_CHANGED
820 = "android.app.action.DEVICE_OWNER_CHANGED";
821
822 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 * The ComponentName of the administrator component.
824 *
825 * @see #ACTION_ADD_DEVICE_ADMIN
826 */
827 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700828
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800830 * An optional CharSequence providing additional explanation for why the
831 * admin is being added.
832 *
833 * @see #ACTION_ADD_DEVICE_ADMIN
834 */
835 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700836
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800837 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700838 * Activity action: have the user enter a new password. This activity should
839 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
840 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
841 * enter a new password that meets the current requirements. You can use
842 * {@link #isActivePasswordSufficient()} to determine whether you need to
843 * have the user select a new password in order to meet the current
844 * constraints. Upon being resumed from this activity, you can check the new
845 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000846 *
847 * If the intent is launched from within a managed profile with a profile
848 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
849 * this will trigger entering a new password for the parent of the profile.
850 * For all other cases it will trigger entering a new password for the user
851 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000852 *
853 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800854 */
855 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
856 public static final String ACTION_SET_NEW_PASSWORD
857 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700858
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000859 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000860 * Activity action: have the user enter a new password for the parent profile.
861 * If the intent is launched from within a managed profile, this will trigger
862 * entering a new password for the parent of the profile. In all other cases
863 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
864 */
865 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
866 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
867 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
868
869 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000870 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
871 * the parent profile to access intents sent from the managed profile.
872 * That is, when an app in the managed profile calls
873 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
874 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000875 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100876 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000877
878 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000879 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
880 * the managed profile to access intents sent from the parent profile.
881 * That is, when an app in the parent profile calls
882 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
883 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000884 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100885 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700886
Dianne Hackbornd6847842010-01-12 18:14:19 -0800887 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100888 * Broadcast action: notify that a new local system update policy has been set by the device
889 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000890 */
891 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100892 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
893 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000894
Amith Yamasanid49489b2015-04-28 14:00:26 -0700895 /**
896 * Permission policy to prompt user for new permission requests for runtime permissions.
897 * Already granted or denied permissions are not affected by this.
898 */
899 public static final int PERMISSION_POLICY_PROMPT = 0;
900
901 /**
902 * Permission policy to always grant new permission requests for runtime permissions.
903 * Already granted or denied permissions are not affected by this.
904 */
905 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
906
907 /**
908 * Permission policy to always deny new permission requests for runtime permissions.
909 * Already granted or denied permissions are not affected by this.
910 */
911 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
912
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700913 /**
914 * Runtime permission state: The user can manage the permission
915 * through the UI.
916 */
917 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
918
919 /**
920 * Runtime permission state: The permission is granted to the app
921 * and the user cannot manage the permission through the UI.
922 */
923 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
924
925 /**
926 * Runtime permission state: The permission is denied to the app
927 * and the user cannot manage the permission through the UI.
928 */
929 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000930
931 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000932 * No management for current user in-effect. This is the default.
933 * @hide
934 */
935 public static final int STATE_USER_UNMANAGED = 0;
936
937 /**
938 * Management partially setup, user setup needs to be completed.
939 * @hide
940 */
941 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
942
943 /**
944 * Management partially setup, user setup completed.
945 * @hide
946 */
947 public static final int STATE_USER_SETUP_COMPLETE = 2;
948
949 /**
950 * Management setup and active on current user.
951 * @hide
952 */
953 public static final int STATE_USER_SETUP_FINALIZED = 3;
954
955 /**
956 * Management partially setup on a managed profile.
957 * @hide
958 */
959 public static final int STATE_USER_PROFILE_COMPLETE = 4;
960
961 /**
962 * @hide
963 */
964 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
965 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
966 @Retention(RetentionPolicy.SOURCE)
967 public @interface UserProvisioningState {}
968
969 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800970 * Return true if the given administrator component is currently
971 * active (enabled) in the system.
972 */
Robin Lee25e26452015-06-02 09:56:29 -0700973 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700974 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100975 }
976
977 /**
978 * @see #isAdminActive(ComponentName)
979 * @hide
980 */
Robin Lee25e26452015-06-02 09:56:29 -0700981 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800982 if (mService != null) {
983 try {
Robin Lee25e26452015-06-02 09:56:29 -0700984 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800986 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800987 }
988 }
989 return false;
990 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800991 /**
992 * Return true if the given administrator component is currently being removed
993 * for the user.
994 * @hide
995 */
Robin Lee25e26452015-06-02 09:56:29 -0700996 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800997 if (mService != null) {
998 try {
Robin Lee25e26452015-06-02 09:56:29 -0700999 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001000 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001001 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001002 }
1003 }
1004 return false;
1005 }
1006
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001007
Dianne Hackbornd6847842010-01-12 18:14:19 -08001008 /**
Robin Lee25e26452015-06-02 09:56:29 -07001009 * Return a list of all currently active device administrators' component
1010 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001011 * returned.
1012 */
1013 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001014 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001015 }
1016
1017 /**
1018 * @see #getActiveAdmins()
1019 * @hide
1020 */
1021 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001022 if (mService != null) {
1023 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001024 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001025 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001026 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001027 }
1028 }
1029 return null;
1030 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001031
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001032 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001033 * Used by package administration code to determine if a package can be stopped
1034 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001035 * @hide
1036 */
1037 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001038 return packageHasActiveAdmins(packageName, myUserId());
1039 }
1040
1041 /**
1042 * Used by package administration code to determine if a package can be stopped
1043 * or uninstalled.
1044 * @hide
1045 */
1046 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001047 if (mService != null) {
1048 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001049 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001050 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001052 }
1053 }
1054 return false;
1055 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001056
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001057 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 * Remove a current administration component. This can only be called
1059 * by the application that owns the administration component; if you
1060 * try to remove someone else's component, a security exception will be
1061 * thrown.
1062 */
Robin Lee25e26452015-06-02 09:56:29 -07001063 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001064 if (mService != null) {
1065 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001066 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001067 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001068 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 }
1070 }
1071 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001072
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001074 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001075 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001076 * but requires additional policies after an upgrade.
1077 *
1078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1079 * an active administrator, or an exception will be thrown.
1080 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1081 */
Robin Lee25e26452015-06-02 09:56:29 -07001082 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001083 if (mService != null) {
1084 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001085 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001086 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001088 }
1089 }
1090 return false;
1091 }
1092
1093 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001094 * Returns true if the Profile Challenge is available to use for the given profile user.
1095 *
1096 * @hide
1097 */
1098 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1099 if (mService != null) {
1100 try {
1101 return mService.isSeparateProfileChallengeAllowed(userHandle);
1102 } catch (RemoteException e) {
1103 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1104 }
1105 }
1106 return false;
1107 }
1108
1109 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001110 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1111 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001112 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001113 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001114 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001115
Dianne Hackbornd6847842010-01-12 18:14:19 -08001116 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001117 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1118 * recognition technology. This implies technologies that can recognize the identity of
1119 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1120 * Note that quality constants are ordered so that higher values are more restrictive.
1121 */
1122 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1123
1124 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001125 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001126 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001127 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001128 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001129 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001130
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001131 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001132 * Constant for {@link #setPasswordQuality}: the user must have entered a
1133 * password containing at least numeric characters. Note that quality
1134 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001135 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001136 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001137
Dianne Hackbornd6847842010-01-12 18:14:19 -08001138 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001139 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001140 * password containing at least numeric characters with no repeating (4444)
1141 * or ordered (1234, 4321, 2468) sequences. Note that quality
1142 * constants are ordered so that higher values are more restrictive.
1143 */
1144 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1145
1146 /**
1147 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001148 * password containing at least alphabetic (or other symbol) characters.
1149 * Note that quality constants are ordered so that higher values are more
1150 * restrictive.
1151 */
1152 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001153
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001154 /**
1155 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001156 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001157 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001158 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001159 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001160 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001161
Dianne Hackbornd6847842010-01-12 18:14:19 -08001162 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001163 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001164 * password containing at least a letter, a numerical digit and a special
1165 * symbol, by default. With this password quality, passwords can be
1166 * restricted to contain various sets of characters, like at least an
1167 * uppercase letter, etc. These are specified using various methods,
1168 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1169 * that quality constants are ordered so that higher values are more
1170 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001171 */
1172 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1173
1174 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001175 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1176 * modify password. In case this password quality is set, the password is
1177 * managed by a profile owner. The profile owner can set any password,
1178 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1179 * that quality constants are ordered so that higher values are more
1180 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1181 * the highest.
1182 * @hide
1183 */
1184 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1185
1186 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001187 * Called by an application that is administering the device to set the
1188 * password restrictions it is imposing. After setting this, the user
1189 * will not be able to enter a new password that is not at least as
1190 * restrictive as what has been set. Note that the current password
1191 * will remain until the user has set a new one, so the change does not
1192 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001193 * {@link #ACTION_SET_NEW_PASSWORD} or
1194 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001195 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001196 * <p>Quality constants are ordered so that higher values are more restrictive;
1197 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001198 * the user's preference, and any other considerations) is the one that
1199 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001200 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001201 * <p>The calling device admin must have requested
1202 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1203 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001204 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001205 * <p>This method can be called on the {@link DevicePolicyManager} instance
1206 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1207 * restrictions on the parent profile.
1208 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001209 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001210 * @param quality The new desired quality. One of
1211 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001212 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1213 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1214 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 */
Robin Lee25e26452015-06-02 09:56:29 -07001216 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001217 if (mService != null) {
1218 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001219 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001220 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001221 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001222 }
1223 }
1224 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001225
Dianne Hackbornd6847842010-01-12 18:14:19 -08001226 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001227 * Retrieve the current minimum password quality for a particular admin or all admins that set
1228 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1229 * a separate challenge are not taken into account.
1230 *
1231 * <p>This method can be called on the {@link DevicePolicyManager} instance
1232 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1233 * restrictions on the parent profile.
1234 *
Robin Lee25e26452015-06-02 09:56:29 -07001235 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001236 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001237 */
Robin Lee25e26452015-06-02 09:56:29 -07001238 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001239 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001240 }
1241
1242 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001243 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001244 if (mService != null) {
1245 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001246 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001247 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001248 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001249 }
1250 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001251 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001252 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001253
Dianne Hackbornd6847842010-01-12 18:14:19 -08001254 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 * Called by an application that is administering the device to set the
1256 * minimum allowed password length. After setting this, the user
1257 * will not be able to enter a new password that is not at least as
1258 * restrictive as what has been set. Note that the current password
1259 * will remain until the user has set a new one, so the change does not
1260 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001261 * {@link #ACTION_SET_NEW_PASSWORD} or
1262 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Dianne Hackbornd6847842010-01-12 18:14:19 -08001263 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001264 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1265 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1266 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001267 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001268 * <p>The calling device admin must have requested
1269 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1270 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001271 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001272 * <p>This method can be called on the {@link DevicePolicyManager} instance
1273 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1274 * restrictions on the parent profile.
1275 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001277 * @param length The new desired minimum password length. A value of 0
1278 * means there is no restriction.
1279 */
Robin Lee25e26452015-06-02 09:56:29 -07001280 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001281 if (mService != null) {
1282 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001283 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001284 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001285 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001286 }
1287 }
1288 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001289
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001291 * Retrieve the current minimum password length for a particular admin or all admins that set
1292 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1293 * a separate challenge are not taken into account.
1294 *
1295 * <p>This method can be called on the {@link DevicePolicyManager} instance
1296 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1297 * restrictions on the parent profile.
1298 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001299 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001300 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001301 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001302 */
Robin Lee25e26452015-06-02 09:56:29 -07001303 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001304 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001305 }
1306
1307 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001308 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001309 if (mService != null) {
1310 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001311 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001312 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001313 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001314 }
1315 }
1316 return 0;
1317 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001318
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001319 /**
1320 * Called by an application that is administering the device to set the
1321 * minimum number of upper case letters required in the password. After
1322 * setting this, the user will not be able to enter a new password that is
1323 * not at least as restrictive as what has been set. Note that the current
1324 * password will remain until the user has set a new one, so the change does
1325 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001326 * {@link #ACTION_SET_NEW_PASSWORD} or
1327 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001328 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001329 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1330 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001331 * <p>
1332 * The calling device admin must have requested
1333 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1334 * this method; if it has not, a security exception will be thrown.
1335 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001336 * <p>This method can be called on the {@link DevicePolicyManager} instance
1337 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1338 * restrictions on the parent profile.
1339 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001340 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1341 * with.
1342 * @param length The new desired minimum number of upper case letters
1343 * required in the password. A value of 0 means there is no
1344 * restriction.
1345 */
Robin Lee25e26452015-06-02 09:56:29 -07001346 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001347 if (mService != null) {
1348 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001349 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001350 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001351 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001352 }
1353 }
1354 }
1355
1356 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001357 * Retrieve the current number of upper case letters required in the password
1358 * for a particular admin or all admins that set retrictions on this user and
1359 * its participating profiles. Restrictions on profiles that have a separate challenge
1360 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001361 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001362 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001363 * and only applies when the password quality is
1364 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001365 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001366 * <p>This method can be called on the {@link DevicePolicyManager} instance
1367 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1368 * restrictions on the parent profile.
1369 *
Robin Lee25e26452015-06-02 09:56:29 -07001370 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001371 * aggregate all admins.
1372 * @return The minimum number of upper case letters required in the
1373 * password.
1374 */
Robin Lee25e26452015-06-02 09:56:29 -07001375 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001376 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001377 }
1378
1379 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001380 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001381 if (mService != null) {
1382 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001383 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001384 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001385 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001386 }
1387 }
1388 return 0;
1389 }
1390
1391 /**
1392 * Called by an application that is administering the device to set the
1393 * minimum number of lower case letters required in the password. After
1394 * setting this, the user will not be able to enter a new password that is
1395 * not at least as restrictive as what has been set. Note that the current
1396 * password will remain until the user has set a new one, so the change does
1397 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001398 * {@link #ACTION_SET_NEW_PASSWORD} or
1399 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001401 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1402 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001403 * <p>
1404 * The calling device admin must have requested
1405 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1406 * this method; if it has not, a security exception will be thrown.
1407 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001408 * <p>This method can be called on the {@link DevicePolicyManager} instance
1409 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1410 * restrictions on the parent profile.
1411 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001412 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1413 * with.
1414 * @param length The new desired minimum number of lower case letters
1415 * required in the password. A value of 0 means there is no
1416 * restriction.
1417 */
Robin Lee25e26452015-06-02 09:56:29 -07001418 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001419 if (mService != null) {
1420 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001421 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001422 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001423 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001424 }
1425 }
1426 }
1427
1428 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001429 * Retrieve the current number of lower case letters required in the password
1430 * for a particular admin or all admins that set retrictions on this user
1431 * and its participating profiles. Restrictions on profiles that have
1432 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001433 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001434 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001435 * and only applies when the password quality is
1436 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001437 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001438 * <p>This method can be called on the {@link DevicePolicyManager} instance
1439 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1440 * restrictions on the parent profile.
1441 *
Robin Lee25e26452015-06-02 09:56:29 -07001442 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 * aggregate all admins.
1444 * @return The minimum number of lower case letters required in the
1445 * password.
1446 */
Robin Lee25e26452015-06-02 09:56:29 -07001447 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001448 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001449 }
1450
1451 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001452 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001453 if (mService != null) {
1454 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001455 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001456 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001457 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001458 }
1459 }
1460 return 0;
1461 }
1462
1463 /**
1464 * Called by an application that is administering the device to set the
1465 * minimum number of letters required in the password. After setting this,
1466 * the user will not be able to enter a new password that is not at least as
1467 * restrictive as what has been set. Note that the current password will
1468 * remain until the user has set a new one, so the change does not take
1469 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001470 * {@link #ACTION_SET_NEW_PASSWORD} or
1471 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001472 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001473 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1474 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001475 * <p>
1476 * The calling device admin must have requested
1477 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1478 * this method; if it has not, a security exception will be thrown.
1479 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001480 * <p>This method can be called on the {@link DevicePolicyManager} instance
1481 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1482 * restrictions on the parent profile.
1483 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001484 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1485 * with.
1486 * @param length The new desired minimum number of letters required in the
1487 * password. A value of 0 means there is no restriction.
1488 */
Robin Lee25e26452015-06-02 09:56:29 -07001489 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 if (mService != null) {
1491 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001492 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001493 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001494 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001495 }
1496 }
1497 }
1498
1499 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001500 * Retrieve the current number of letters required in the password
1501 * for a particular admin or all admins that set retrictions on this user
1502 * and its participating profiles. Restrictions on profiles that have
1503 * a separate challenge are not taken into account.
1504 * This is the same value as set by
1505 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001506 * and only applies when the password quality is
1507 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001508 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001509 * <p>This method can be called on the {@link DevicePolicyManager} instance
1510 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1511 * restrictions on the parent profile.
1512 *
Robin Lee25e26452015-06-02 09:56:29 -07001513 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001514 * aggregate all admins.
1515 * @return The minimum number of letters required in the password.
1516 */
Robin Lee25e26452015-06-02 09:56:29 -07001517 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001518 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001519 }
1520
1521 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001522 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001523 if (mService != null) {
1524 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001525 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001526 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001527 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001528 }
1529 }
1530 return 0;
1531 }
1532
1533 /**
1534 * Called by an application that is administering the device to set the
1535 * minimum number of numerical digits required in the password. After
1536 * setting this, the user will not be able to enter a new password that is
1537 * not at least as restrictive as what has been set. Note that the current
1538 * password will remain until the user has set a new one, so the change does
1539 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001540 * {@link #ACTION_SET_NEW_PASSWORD} or
1541 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001542 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001543 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1544 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001545 * <p>
1546 * The calling device admin must have requested
1547 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1548 * this method; if it has not, a security exception will be thrown.
1549 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001550 * <p>This method can be called on the {@link DevicePolicyManager} instance
1551 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1552 * restrictions on the parent profile.
1553 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001554 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1555 * with.
1556 * @param length The new desired minimum number of numerical digits required
1557 * in the password. A value of 0 means there is no restriction.
1558 */
Robin Lee25e26452015-06-02 09:56:29 -07001559 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001560 if (mService != null) {
1561 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001562 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001563 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001564 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001565 }
1566 }
1567 }
1568
1569 /**
1570 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001571 * for a particular admin or all admins that set retrictions on this user
1572 * and its participating profiles. Restrictions on profiles that have
1573 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001574 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001575 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001576 * and only applies when the password quality is
1577 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001578 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001579 * <p>This method can be called on the {@link DevicePolicyManager} instance
1580 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1581 * restrictions on the parent profile.
1582 *
Robin Lee25e26452015-06-02 09:56:29 -07001583 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001584 * aggregate all admins.
1585 * @return The minimum number of numerical digits required in the password.
1586 */
Robin Lee25e26452015-06-02 09:56:29 -07001587 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001588 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001589 }
1590
1591 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001592 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001593 if (mService != null) {
1594 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001595 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001596 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001597 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001598 }
1599 }
1600 return 0;
1601 }
1602
1603 /**
1604 * Called by an application that is administering the device to set the
1605 * minimum number of symbols required in the password. After setting this,
1606 * the user will not be able to enter a new password that is not at least as
1607 * restrictive as what has been set. Note that the current password will
1608 * remain until the user has set a new one, so the change does not take
1609 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001610 * {@link #ACTION_SET_NEW_PASSWORD} or
1611 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001612 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001613 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1614 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001615 * <p>
1616 * The calling device admin must have requested
1617 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1618 * this method; if it has not, a security exception will be thrown.
1619 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001620 * <p>This method can be called on the {@link DevicePolicyManager} instance
1621 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1622 * restrictions on the parent profile.
1623 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001624 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1625 * with.
1626 * @param length The new desired minimum number of symbols required in the
1627 * password. A value of 0 means there is no restriction.
1628 */
Robin Lee25e26452015-06-02 09:56:29 -07001629 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001630 if (mService != null) {
1631 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001632 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001633 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001634 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001635 }
1636 }
1637 }
1638
1639 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001640 * Retrieve the current number of symbols required in the password
1641 * for a particular admin or all admins that set retrictions on this user
1642 * and its participating profiles. Restrictions on profiles that have
1643 * a separate challenge are not taken into account. This is the same value as
1644 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001645 * and only applies when the password quality is
1646 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001647 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001648 * <p>This method can be called on the {@link DevicePolicyManager} instance
1649 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1650 * restrictions on the parent profile.
1651 *
Robin Lee25e26452015-06-02 09:56:29 -07001652 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001653 * aggregate all admins.
1654 * @return The minimum number of symbols required in the password.
1655 */
Robin Lee25e26452015-06-02 09:56:29 -07001656 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001657 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001658 }
1659
1660 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001661 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001662 if (mService != null) {
1663 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001664 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001665 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001666 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001667 }
1668 }
1669 return 0;
1670 }
1671
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001672 /**
1673 * Called by an application that is administering the device to set the
1674 * minimum number of non-letter characters (numerical digits or symbols)
1675 * required in the password. After setting this, the user will not be able
1676 * to enter a new password that is not at least as restrictive as what has
1677 * been set. Note that the current password will remain until the user has
1678 * set a new one, so the change does not take place immediately. To prompt
Esteban Talaverac1c83592016-02-17 17:56:15 +00001679 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1680 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001681 * setting this value. This constraint is only imposed if the administrator
1682 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1683 * {@link #setPasswordQuality}. The default value is 0.
1684 * <p>
1685 * The calling device admin must have requested
1686 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1687 * this method; if it has not, a security exception will be thrown.
1688 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001689 * <p>This method can be called on the {@link DevicePolicyManager} instance
1690 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1691 * restrictions on the parent profile.
1692 *
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001693 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1694 * with.
1695 * @param length The new desired minimum number of letters required in the
1696 * password. A value of 0 means there is no restriction.
1697 */
Robin Lee25e26452015-06-02 09:56:29 -07001698 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001699 if (mService != null) {
1700 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001701 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001702 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001703 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001704 }
1705 }
1706 }
1707
1708 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001709 * Retrieve the current number of non-letter characters required in the password
1710 * for a particular admin or all admins that set retrictions on this user
1711 * and its participating profiles. Restrictions on profiles that have
1712 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001713 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001714 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001715 * and only applies when the password quality is
1716 * {@link #PASSWORD_QUALITY_COMPLEX}.
1717 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001718 * <p>This method can be called on the {@link DevicePolicyManager} instance
1719 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1720 * restrictions on the parent profile.
1721 *
Robin Lee25e26452015-06-02 09:56:29 -07001722 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001723 * aggregate all admins.
1724 * @return The minimum number of letters required in the password.
1725 */
Robin Lee25e26452015-06-02 09:56:29 -07001726 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001727 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001728 }
1729
1730 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001731 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001732 if (mService != null) {
1733 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001734 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001735 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001737 }
1738 }
1739 return 0;
1740 }
1741
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001742 /**
1743 * Called by an application that is administering the device to set the length
1744 * of the password history. After setting this, the user will not be able to
1745 * enter a new password that is the same as any password in the history. Note
1746 * that the current password will remain until the user has set a new one, so
1747 * the change does not take place immediately. To prompt the user for a new
Esteban Talaverac1c83592016-02-17 17:56:15 +00001748 * password, use {@link #ACTION_SET_NEW_PASSWORD} or
1749 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001750 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001751 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1752 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1753 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001754 *
1755 * <p>
1756 * The calling device admin must have requested
1757 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1758 * method; if it has not, a security exception will be thrown.
1759 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001760 * <p>This method can be called on the {@link DevicePolicyManager} instance
1761 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1762 * restrictions on the parent profile.
1763 *
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001764 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1765 * with.
1766 * @param length The new desired length of password history. A value of 0
1767 * means there is no restriction.
1768 */
Robin Lee25e26452015-06-02 09:56:29 -07001769 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001770 if (mService != null) {
1771 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001772 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001773 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001774 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001775 }
1776 }
1777 }
1778
1779 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001780 * Called by a device admin to set the password expiration timeout. Calling this method
1781 * will restart the countdown for password expiration for the given admin, as will changing
1782 * the device password (for all admins).
1783 *
1784 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1785 * For example, to have the password expire 5 days from now, timeout would be
1786 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1787 *
1788 * <p>To disable password expiration, a value of 0 may be used for timeout.
1789 *
Jim Millera4e28d12010-11-08 16:15:47 -08001790 * <p>The calling device admin must have requested
1791 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1792 * method; if it has not, a security exception will be thrown.
1793 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001794 * <p> Note that setting the password will automatically reset the expiration time for all
1795 * active admins. Active admins do not need to explicitly call this method in that case.
1796 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001797 * <p>This method can be called on the {@link DevicePolicyManager} instance
1798 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1799 * restrictions on the parent profile.
1800 *
Jim Millera4e28d12010-11-08 16:15:47 -08001801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1802 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1803 * means there is no restriction (unlimited).
1804 */
Robin Lee25e26452015-06-02 09:56:29 -07001805 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001806 if (mService != null) {
1807 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001808 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001809 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001810 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001811 }
1812 }
1813 }
1814
1815 /**
Jim Miller6b857682011-02-16 16:27:41 -08001816 * Get the password expiration timeout for the given admin. The expiration timeout is the
1817 * recurring expiration timeout provided in the call to
1818 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001819 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1820 * have set restrictions on profiles that have a separate challenge are not taken into account.
1821 *
1822 * <p>This method can be called on the {@link DevicePolicyManager} instance
1823 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1824 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001825 *
Robin Lee25e26452015-06-02 09:56:29 -07001826 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001827 * @return The timeout for the given admin or the minimum of all timeouts
1828 */
Robin Lee25e26452015-06-02 09:56:29 -07001829 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001830 if (mService != null) {
1831 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001832 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001833 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001834 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001835 }
1836 }
1837 return 0;
1838 }
1839
1840 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001841 * Get the current password expiration time for a particular admin or all admins that set
1842 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1843 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1844 * of all expiration times is returned - which will be the minimum of all of them.
1845 *
1846 * <p>This method can be called on the {@link DevicePolicyManager} instance
1847 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1848 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001849 *
Robin Lee25e26452015-06-02 09:56:29 -07001850 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001851 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001852 */
Robin Lee25e26452015-06-02 09:56:29 -07001853 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001854 if (mService != null) {
1855 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001856 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001857 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001858 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001859 }
1860 }
1861 return 0;
1862 }
1863
1864 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001865 * Retrieve the current password history length for a particular admin or all admins that
1866 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1867 * have a separate challenge are not taken into account.
1868 *
1869 * <p>This method can be called on the {@link DevicePolicyManager} instance
1870 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1871 * restrictions on the parent profile.
1872 *
Robin Lee25e26452015-06-02 09:56:29 -07001873 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001874 * all admins.
1875 * @return The length of the password history
1876 */
Robin Lee25e26452015-06-02 09:56:29 -07001877 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001878 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001879 }
1880
1881 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001882 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001883 if (mService != null) {
1884 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001885 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001886 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001887 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001888 }
1889 }
1890 return 0;
1891 }
1892
Dianne Hackbornd6847842010-01-12 18:14:19 -08001893 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001894 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001895 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001896 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001897 * @return Returns the maximum length that the user can enter.
1898 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001899 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001900 // Kind-of arbitrary.
1901 return 16;
1902 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001903
Dianne Hackborn254cb442010-01-27 19:23:59 -08001904 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001905 * Determine whether the current password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001906 * to meet the policy requirements (e.g. quality, minimum length) that have been
1907 * requested by the admins of this user and its participating profiles.
1908 * Restrictions on profiles that have a separate challenge are not taken into account.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001909 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001910 * <p>The calling device admin must have requested
1911 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1912 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001913 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001914 * <p>This method can be called on the {@link DevicePolicyManager} instance
1915 * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine
1916 * if the password set on the parent profile is sufficient.
1917 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001918 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001919 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001920 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001921 if (mService != null) {
1922 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001923 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001924 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001925 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001926 }
1927 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001928 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001929 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001930
Dianne Hackbornd6847842010-01-12 18:14:19 -08001931 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001932 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001933 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001934 * requested by the admins of the parent user and its profiles.
1935 *
1936 * @param userHandle the userId of the profile to check the password for.
1937 * @return Returns true if the password would meet the current requirements, else false.
1938 * @hide
1939 */
1940 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1941 if (mService != null) {
1942 try {
1943 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1944 } catch (RemoteException e) {
1945 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1946 }
1947 }
1948 return false;
1949 }
1950
1951 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001952 * Retrieve the number of times the user has failed at entering a
1953 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001954 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001955 * <p>This method can be called on the {@link DevicePolicyManager} instance
1956 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1957 * the number of failed password attemts for the parent user.
1958 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001959 * <p>The calling device admin must have requested
1960 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1961 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001962 */
1963 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001964 return getCurrentFailedPasswordAttempts(myUserId());
1965 }
1966
1967 /**
1968 * Retrieve the number of times the given user has failed at entering a
1969 * password since that last successful password entry.
1970 *
1971 * <p>The calling device admin must have requested
1972 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
1973 * not and it is not the system uid, a security exception will be thrown.
1974 *
1975 * @hide
1976 */
1977 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001978 if (mService != null) {
1979 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001980 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001981 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001982 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001983 }
1984 }
1985 return -1;
1986 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001987
1988 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001989 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001990 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001991 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001992 * @hide
1993 */
1994 public boolean getDoNotAskCredentialsOnBoot() {
1995 if (mService != null) {
1996 try {
1997 return mService.getDoNotAskCredentialsOnBoot();
1998 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001999 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002000 }
2001 }
2002 return false;
2003 }
2004
2005 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08002006 * Setting this to a value greater than zero enables a built-in policy
Esteban Talaverac1c83592016-02-17 17:56:15 +00002007 * that will perform a device or profile wipe after too many incorrect
Andrew Stadler88209d12010-02-08 22:59:36 -08002008 * device-unlock passwords have been entered. This built-in policy combines
2009 * watching for failed passwords and wiping the device, and requires
2010 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002011 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002012 *
Andrew Stadler88209d12010-02-08 22:59:36 -08002013 * <p>To implement any other policy (e.g. wiping data for a particular
2014 * application only, erasing or revoking credentials, or reporting the
2015 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002016 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08002017 * instead. Do not use this API, because if the maximum count is reached,
Esteban Talaverac1c83592016-02-17 17:56:15 +00002018 * the device or profile will be wiped immediately, and your callback will not be invoked.
2019 *
2020 * <p>This method can be called on the {@link DevicePolicyManager} instance
2021 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2022 * a value on the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002023 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002025 * @param num The number of failed password attempts at which point the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002026 * device or profile will be wiped.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002027 */
Robin Lee25e26452015-06-02 09:56:29 -07002028 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002029 if (mService != null) {
2030 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002031 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002032 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002033 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002034 }
2035 }
2036 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002037
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002038 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002039 * Retrieve the current maximum number of login attempts that are allowed before the device
2040 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2041 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2042 * not taken into account.
2043 *
2044 * <p>This method can be called on the {@link DevicePolicyManager} instance
2045 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2046 * the value for the parent profile.
2047 *
Robin Lee25e26452015-06-02 09:56:29 -07002048 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002049 * all admins.
2050 */
Robin Lee25e26452015-06-02 09:56:29 -07002051 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002052 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002053 }
2054
2055 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002056 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002057 if (mService != null) {
2058 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002059 return mService.getMaximumFailedPasswordsForWipe(
2060 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002061 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002062 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002063 }
2064 }
2065 return 0;
2066 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002067
Dianne Hackborn254cb442010-01-27 19:23:59 -08002068 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002069 * Returns the profile with the smallest maximum failed passwords for wipe,
2070 * for the given user. So for primary user, it might return the primary or
2071 * a managed profile. For a secondary user, it would be the same as the
2072 * user passed in.
2073 * @hide Used only by Keyguard
2074 */
2075 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2076 if (mService != null) {
2077 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002078 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2079 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002080 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002081 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002082 }
2083 }
2084 return UserHandle.USER_NULL;
2085 }
2086
2087 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002088 * Flag for {@link #resetPassword}: don't allow other admins to change
2089 * the password again until the user has entered it.
2090 */
2091 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002092
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002093 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002094 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2095 * If the flag is set, the device can be booted without asking for user password.
2096 * The absence of this flag does not change the current boot requirements. This flag
2097 * can be set by the device owner only. If the app is not the device owner, the flag
2098 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2099 * device to factory defaults.
2100 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002101 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002102
2103 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002104 * Force a new device unlock password (the password needed to access the
2105 * entire device, not for individual accounts) on the user. This takes
2106 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08002107 *
2108 * <p>Calling this from a managed profile that shares the password with the owner profile
2109 * will throw a security exception.
2110 *
2111 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
2112 * device admins that are not device owner and not profile owner.
2113 * The password can now only be changed if there is currently no password set. Device owner
2114 * and profile owner can still do this.</em>
2115 *
2116 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002117 * current password quality and length constraints as returned by
2118 * {@link #getPasswordQuality(ComponentName)} and
2119 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
2120 * these constraints, then it will be rejected and false returned. Note
2121 * that the password may be a stronger quality (containing alphanumeric
2122 * characters when the requested quality is only numeric), in which case
2123 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002124 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002125 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08002126 * pattern or password if the current password constraints allow it. <em>Note: This will not
2127 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2128 * device owner and not profile owner. Once set, the password cannot be changed to null or
2129 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002130 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002131 * <p>The calling device admin must have requested
2132 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
2133 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002134 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002135 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002136 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002137 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002138 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08002139 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002140 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002141 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002142 if (mParentInstance) {
2143 throw new SecurityException("Reset password does not work across profiles.");
2144 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002145 if (mService != null) {
2146 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002147 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002148 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002149 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002150 }
2151 }
2152 return false;
2153 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002154
Dianne Hackbornd6847842010-01-12 18:14:19 -08002155 /**
2156 * Called by an application that is administering the device to set the
2157 * maximum time for user activity until the device will lock. This limits
2158 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002159 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002160 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002161 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002162 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002163 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002164 * <p>This method can be called on the {@link DevicePolicyManager} instance
2165 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2166 * restrictions on the parent profile.
2167 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002168 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002169 * @param timeMs The new desired maximum time to lock in milliseconds.
2170 * A value of 0 means there is no restriction.
2171 */
Robin Lee25e26452015-06-02 09:56:29 -07002172 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002173 if (mService != null) {
2174 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002175 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002176 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002177 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002178 }
2179 }
2180 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002181
Dianne Hackbornd6847842010-01-12 18:14:19 -08002182 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002183 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2184 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2185 * a separate challenge are not taken into account.
2186 *
2187 * <p>This method can be called on the {@link DevicePolicyManager} instance
2188 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2189 * restrictions on the parent profile.
2190 *
Robin Lee25e26452015-06-02 09:56:29 -07002191 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002192 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002193 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002194 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002195 */
Robin Lee25e26452015-06-02 09:56:29 -07002196 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002197 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002198 }
2199
2200 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002201 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002202 if (mService != null) {
2203 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002204 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002205 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002206 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002207 }
2208 }
2209 return 0;
2210 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002211
Dianne Hackbornd6847842010-01-12 18:14:19 -08002212 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002213 * Make the device lock immediately, as if the lock screen timeout has
2214 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002215 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002216 * <p>The calling device admin must have requested
2217 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2218 * this method; if it has not, a security exception will be thrown.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002219 *
2220 * <p>This method can be called on the {@link DevicePolicyManager} instance
2221 * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock
2222 * the parent profile.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002223 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002224 public void lockNow() {
2225 if (mService != null) {
2226 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002227 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002228 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002229 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002230 }
2231 }
2232 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002233
Dianne Hackbornd6847842010-01-12 18:14:19 -08002234 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002235 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002236 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002237 */
2238 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2239
2240 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002241 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2242 * data.
2243 *
Paul Crowley2934b262014-12-02 11:21:13 +00002244 * <p>This flag may only be set by device owner admins; if it is set by
2245 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002246 */
2247 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2248
2249 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002250 * Ask the user data be wiped. Wiping the primary user will cause the
2251 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002252 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002253 * <p>The calling device admin must have requested
2254 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2255 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002256 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002257 * @param flags Bit mask of additional options: currently supported flags
2258 * are {@link #WIPE_EXTERNAL_STORAGE} and
2259 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002260 */
2261 public void wipeData(int flags) {
2262 if (mService != null) {
2263 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002264 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002265 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002266 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002267 }
2268 }
2269 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002270
Dianne Hackbornd6847842010-01-12 18:14:19 -08002271 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002272 * Called by an application that is administering the device to set the
2273 * global proxy and exclusion list.
2274 * <p>
2275 * The calling device admin must have requested
2276 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2277 * this method; if it has not, a security exception will be thrown.
2278 * Only the first device admin can set the proxy. If a second admin attempts
2279 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002280 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002281 * be returned.
2282 * The method can be called repeatedly by the device admin alrady setting the
2283 * proxy to update the proxy and exclusion list.
2284 *
Robin Lee25e26452015-06-02 09:56:29 -07002285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002286 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2287 * Pass Proxy.NO_PROXY to reset the proxy.
2288 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002289 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2290 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002291 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002292 */
Robin Lee25e26452015-06-02 09:56:29 -07002293 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002294 List<String> exclusionList ) {
2295 if (proxySpec == null) {
2296 throw new NullPointerException();
2297 }
2298 if (mService != null) {
2299 try {
2300 String hostSpec;
2301 String exclSpec;
2302 if (proxySpec.equals(Proxy.NO_PROXY)) {
2303 hostSpec = null;
2304 exclSpec = null;
2305 } else {
2306 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2307 throw new IllegalArgumentException();
2308 }
2309 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2310 String hostName = sa.getHostName();
2311 int port = sa.getPort();
2312 StringBuilder hostBuilder = new StringBuilder();
2313 hostSpec = hostBuilder.append(hostName)
2314 .append(":").append(Integer.toString(port)).toString();
2315 if (exclusionList == null) {
2316 exclSpec = "";
2317 } else {
2318 StringBuilder listBuilder = new StringBuilder();
2319 boolean firstDomain = true;
2320 for (String exclDomain : exclusionList) {
2321 if (!firstDomain) {
2322 listBuilder = listBuilder.append(",");
2323 } else {
2324 firstDomain = false;
2325 }
2326 listBuilder = listBuilder.append(exclDomain.trim());
2327 }
2328 exclSpec = listBuilder.toString();
2329 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002330 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2331 != android.net.Proxy.PROXY_VALID)
2332 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002333 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002334 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002335 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002336 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002337 }
2338 }
2339 return null;
2340 }
2341
2342 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002343 * Set a network-independent global HTTP proxy. This is not normally what you want
2344 * for typical HTTP proxies - they are generally network dependent. However if you're
2345 * doing something unusual like general internal filtering this may be useful. On
2346 * a private network where the proxy is not accessible, you may break HTTP using this.
2347 *
2348 * <p>This method requires the caller to be the device owner.
2349 *
2350 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2351 * @see ProxyInfo
2352 *
2353 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2354 * with.
2355 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2356 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2357 */
Robin Lee25e26452015-06-02 09:56:29 -07002358 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2359 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002360 if (mService != null) {
2361 try {
2362 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2363 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002364 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002365 }
2366 }
2367 }
2368
2369 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002370 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002371 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2372 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002373 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002374 */
2375 public ComponentName getGlobalProxyAdmin() {
2376 if (mService != null) {
2377 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002378 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002379 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002380 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002381 }
2382 }
2383 return null;
2384 }
2385
2386 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002387 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002388 * indicating that encryption is not supported.
2389 */
2390 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2391
2392 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002393 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002394 * indicating that encryption is supported, but is not currently active.
2395 */
2396 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2397
2398 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002399 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002400 * indicating that encryption is not currently active, but is currently
2401 * being activated. This is only reported by devices that support
2402 * encryption of data and only when the storage is currently
2403 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2404 * to become encrypted will never return this value.
2405 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002406 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002407
2408 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002409 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002410 * indicating that encryption is active.
2411 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002412 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002413
2414 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002415 * Result code for {@link #getStorageEncryptionStatus}:
2416 * indicating that encryption is active, but an encryption key has not
2417 * been set by the user.
2418 */
2419 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2420
2421 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002422 * Activity action: begin the process of encrypting data on the device. This activity should
2423 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2424 * After resuming from this activity, use {@link #getStorageEncryption}
2425 * to check encryption status. However, on some devices this activity may never return, as
2426 * it may trigger a reboot and in some cases a complete data wipe of the device.
2427 */
2428 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2429 public static final String ACTION_START_ENCRYPTION
2430 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002431 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002432 * Widgets are enabled in keyguard
2433 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002434 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002435
2436 /**
Jim Miller50e62182014-04-23 17:25:00 -07002437 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002438 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002439 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2440
2441 /**
2442 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2443 */
2444 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2445
2446 /**
Jim Miller50e62182014-04-23 17:25:00 -07002447 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2448 */
2449 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2450
2451 /**
2452 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2453 */
2454 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2455
2456 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002457 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002458 * (e.g. PIN/Pattern/Password).
2459 */
2460 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2461
2462 /**
Jim Miller06e34502014-07-17 14:46:05 -07002463 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2464 */
2465 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2466
2467 /**
Jim Miller35207742012-11-02 15:33:20 -07002468 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002469 */
2470 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002471
2472 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002473 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002474 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002475 *
2476 * <p>When multiple device administrators attempt to control device
2477 * encryption, the most secure, supported setting will always be
2478 * used. If any device administrator requests device encryption,
2479 * it will be enabled; Conversely, if a device administrator
2480 * attempts to disable device encryption while another
2481 * device administrator has enabled it, the call to disable will
2482 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2483 *
2484 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002485 * written to other storage areas may or may not be encrypted, and this policy does not require
2486 * or control the encryption of any other storage areas.
2487 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2488 * {@code true}, then the directory returned by
2489 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2490 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002491 *
2492 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2493 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2494 * the encryption key may not be fully secured. For maximum security, the administrator should
2495 * also require (and check for) a pattern, PIN, or password.
2496 *
2497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2498 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002499 * @return the new request status (for all active admins) - will be one of
2500 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2501 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2502 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002503 */
Robin Lee25e26452015-06-02 09:56:29 -07002504 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002505 if (mService != null) {
2506 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002507 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002508 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002509 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002510 }
2511 }
2512 return ENCRYPTION_STATUS_UNSUPPORTED;
2513 }
2514
2515 /**
2516 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002517 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002518 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2520 * this will return the requested encryption setting as an aggregate of all active
2521 * administrators.
2522 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002523 */
Robin Lee25e26452015-06-02 09:56:29 -07002524 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002525 if (mService != null) {
2526 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002527 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002528 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002529 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002530 }
2531 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002532 return false;
2533 }
2534
2535 /**
2536 * Called by an application that is administering the device to
2537 * determine the current encryption status of the device.
2538 *
2539 * Depending on the returned status code, the caller may proceed in different
2540 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2541 * storage system does not support encryption. If the
2542 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2543 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002544 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2545 * storage system has enabled encryption but no password is set so further action
2546 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002547 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2548 *
Robin Lee7e678712014-07-24 16:41:31 +01002549 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002550 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002551 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2552 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002553 */
2554 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002555 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002556 }
2557
2558 /** @hide per-user version */
2559 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002560 if (mService != null) {
2561 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002562 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002563 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002564 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002565 }
2566 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002567 return ENCRYPTION_STATUS_UNSUPPORTED;
2568 }
2569
2570 /**
Robin Lee7e678712014-07-24 16:41:31 +01002571 * Installs the given certificate as a user CA.
2572 *
Robin Lee25e26452015-06-02 09:56:29 -07002573 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2574 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002575 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002576 *
2577 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002578 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002579 */
Robin Lee25e26452015-06-02 09:56:29 -07002580 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002581 if (mService != null) {
2582 try {
Robin Lee7e678712014-07-24 16:41:31 +01002583 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002584 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002585 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002586 }
2587 }
2588 return false;
2589 }
2590
2591 /**
Robin Lee7e678712014-07-24 16:41:31 +01002592 * Uninstalls the given certificate from trusted user CAs, if present.
2593 *
Robin Lee25e26452015-06-02 09:56:29 -07002594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2595 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002596 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002597 */
Robin Lee25e26452015-06-02 09:56:29 -07002598 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002599 if (mService != null) {
2600 try {
Robin Lee306fe082014-06-19 14:04:24 +00002601 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002602 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002603 } catch (CertificateException e) {
2604 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002605 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002606 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002607 }
2608 }
2609 }
2610
2611 /**
Robin Lee7e678712014-07-24 16:41:31 +01002612 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2613 * If a user has installed any certificates by other means than device policy these will be
2614 * included too.
2615 *
Robin Lee25e26452015-06-02 09:56:29 -07002616 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2617 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002618 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002619 */
Robin Lee25e26452015-06-02 09:56:29 -07002620 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002621 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002622 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002623 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002624 mService.enforceCanManageCaCerts(admin);
2625 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2626 for (String alias : certStore.userAliases()) {
2627 try {
2628 certs.add(certStore.getCertificate(alias).getEncoded());
2629 } catch (CertificateException ce) {
2630 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2631 }
2632 }
2633 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002634 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002635 }
2636 }
2637 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002638 }
2639
2640 /**
Robin Lee7e678712014-07-24 16:41:31 +01002641 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2642 * means other than device policy will also be removed, except for system CA certificates.
2643 *
Robin Lee25e26452015-06-02 09:56:29 -07002644 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2645 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002646 */
Robin Lee25e26452015-06-02 09:56:29 -07002647 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002648 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002649 try {
2650 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2651 .toArray(new String[0]));
2652 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002653 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002654 }
2655 }
2656 }
2657
2658 /**
2659 * Returns whether this certificate is installed as a trusted CA.
2660 *
Robin Lee25e26452015-06-02 09:56:29 -07002661 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2662 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002663 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002664 */
Robin Lee25e26452015-06-02 09:56:29 -07002665 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002666 if (mService != null) {
2667 try {
2668 mService.enforceCanManageCaCerts(admin);
2669 return getCaCertAlias(certBuffer) != null;
2670 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002671 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002672 } catch (CertificateException ce) {
2673 Log.w(TAG, "Could not parse certificate", ce);
2674 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002675 }
2676 return false;
2677 }
2678
2679 /**
Robin Leece3399f2016-02-24 12:08:32 +00002680 * Called by a device or profile owner, or delegated certificate installer, to install a
2681 * certificate and corresponding private key. All apps within the profile will be able to access
2682 * the certificate and use the private key, given direct user approval.
2683 *
2684 * <p>Access to the installed credentials will not be granted to the caller of this API without
2685 * direct user approval. This is for security - should a certificate installer become
2686 * compromised, certificates it had already installed will be protected.
2687 *
2688 * <p>If the installer must have access to the credentials, call
2689 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002690 *
Robin Lee25e26452015-06-02 09:56:29 -07002691 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2692 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002693 * @param privKey The private key to install.
2694 * @param cert The certificate to install.
2695 * @param alias The private key alias under which to install the certificate. If a certificate
2696 * with that alias already exists, it will be overwritten.
2697 * @return {@code true} if the keys were installed, {@code false} otherwise.
2698 */
Robin Leefbc65642015-08-03 16:21:22 +01002699 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2700 @NonNull Certificate cert, @NonNull String alias) {
Robin Leece3399f2016-02-24 12:08:32 +00002701 return installKeyPair(admin, privKey, cert, alias, false);
2702 }
2703
2704 /**
2705 * Called by a device or profile owner, or delegated certificate installer, to install a
2706 * certificate and corresponding private key. All apps within the profile will be able to access
2707 * the certificate and use the private key, given direct user approval.
2708 *
2709 * <p>The caller of this API may grant itself access to the credential immediately, without user
2710 * approval. It is a best practice not to request this unless strictly necessary since it opens
2711 * up additional security vulnerabilities.
2712 *
2713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2714 * {@code null} if calling from a delegated certificate installer.
2715 * @param privKey The private key to install.
2716 * @param cert The certificate to install.
2717 * @param alias The private key alias under which to install the certificate. If a certificate
2718 * with that alias already exists, it will be overwritten.
2719 * @param requestAccess {@code true} to request that the calling app be granted access to the
2720 * credentials immediately. Otherwise, access to the credentials will be gated by user approval.
2721 * @return {@code true} if the keys were installed, {@code false} otherwise.
2722 */
2723 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2724 @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002725 try {
2726 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002727 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2728 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Leece3399f2016-02-24 12:08:32 +00002729 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002730 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002731 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002732 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2733 Log.w(TAG, "Failed to obtain private key material", e);
2734 } catch (CertificateException | IOException e) {
2735 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002736 }
2737 return false;
2738 }
2739
2740 /**
Robin Leece3399f2016-02-24 12:08:32 +00002741 * Called by a device or profile owner, or delegated certificate installer, to remove all user
2742 * credentials installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002743 *
2744 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2745 * {@code null} if calling from a delegated certificate installer.
2746 * @param alias The private key alias under which the certificate is installed.
2747 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2748 */
2749 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2750 try {
2751 return mService.removeKeyPair(admin, alias);
2752 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00002753 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Leefbc65642015-08-03 16:21:22 +01002754 }
2755 return false;
2756 }
2757
2758 /**
Robin Lee25e26452015-06-02 09:56:29 -07002759 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002760 * doesn't exist.
2761 */
2762 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2763 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2764 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2765 new ByteArrayInputStream(certBuffer));
2766 return new TrustedCertificateStore().getCertificateAlias(cert);
2767 }
2768
2769 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002770 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002771 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002772 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002773 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002774 * <p>
2775 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2776 * it is later cleared by calling this method with a null value or uninstallling the certificate
2777 * installer.
Rubin Xuf03d0a62016-02-10 14:54:15 +00002778 *<p>
2779 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2780 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
2781 * supplied certificate installer package must be installed when calling this API,
2782 * otherwise an {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002783 *
Robin Lee25e26452015-06-02 09:56:29 -07002784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002785 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002786 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002787 */
Robin Lee25e26452015-06-02 09:56:29 -07002788 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2789 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002790 if (mService != null) {
2791 try {
Robin Lee25e26452015-06-02 09:56:29 -07002792 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002793 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002794 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002795 }
2796 }
2797 }
2798
2799 /**
2800 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002801 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002802 *
Robin Lee25e26452015-06-02 09:56:29 -07002803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2804 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002805 * if none is set.
2806 */
Robin Lee25e26452015-06-02 09:56:29 -07002807 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002808 if (mService != null) {
2809 try {
Robin Lee25e26452015-06-02 09:56:29 -07002810 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002811 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002812 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002813 }
2814 }
2815 return null;
2816 }
2817
2818 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002819 * Called by a device or profile owner to configure an always-on VPN connection through a
2820 * specific application for the current user.
2821 * This connection is automatically granted and persisted after a reboot.
2822 *
2823 * <p>The designated package should declare a {@link android.net.VpnService} in its
2824 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2825 * otherwise the call will fail.
2826 *
2827 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2828 * to remove an existing always-on VPN configuration.
2829 *
2830 * @return {@code true} if the package is set as always-on VPN controller;
2831 * {@code false} otherwise.
2832 */
2833 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2834 @Nullable String vpnPackage) {
2835 if (mService != null) {
2836 try {
2837 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2838 } catch (RemoteException e) {
2839 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2840 }
2841 }
2842 return false;
2843 }
2844
2845 /**
2846 * Called by a device or profile owner to read the name of the package administering an
2847 * always-on VPN connection for the current user.
2848 * If there is no such package, or the always-on VPN is provided by the system instead
2849 * of by an application, {@code null} will be returned.
2850 *
2851 * @return Package name of VPN controller responsible for always-on VPN,
2852 * or {@code null} if none is set.
2853 */
2854 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2855 if (mService != null) {
2856 try {
2857 return mService.getAlwaysOnVpnPackage(admin);
2858 } catch (RemoteException e) {
2859 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2860 }
2861 }
2862 return null;
2863 }
2864
2865 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002866 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002867 * on the device, for this user. After setting this, no applications running as this user
2868 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002869 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002870 * <p>If the caller is device owner, then the restriction will be applied to all users.
2871 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002872 * <p>The calling device admin must have requested
2873 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2874 * this method; if it has not, a security exception will be thrown.
2875 *
2876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2877 * @param disabled Whether or not the camera should be disabled.
2878 */
Robin Lee25e26452015-06-02 09:56:29 -07002879 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002880 if (mService != null) {
2881 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002882 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002883 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002884 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002885 }
2886 }
2887 }
2888
2889 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002890 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002891 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002892 * @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 -07002893 * have disabled the camera
2894 */
Robin Lee25e26452015-06-02 09:56:29 -07002895 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002896 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002897 }
2898
2899 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002900 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002901 if (mService != null) {
2902 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002903 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002904 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002905 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002906 }
2907 }
2908 return false;
2909 }
2910
2911 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002912 * Called by a device owner to request a bugreport.
2913 *
2914 * <p>There must be only one user on the device, managed by the device owner.
2915 * Otherwise a security exception will be thrown.
2916 *
2917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2918 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2919 * if it wasn't triggered because a previous bugreport operation is still active
2920 * (either the bugreport is still running or waiting for the user to share or decline)
2921 */
2922 public boolean requestBugreport(@NonNull ComponentName admin) {
2923 if (mService != null) {
2924 try {
2925 return mService.requestBugreport(admin);
2926 } catch (RemoteException e) {
2927 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2928 }
2929 }
2930 return false;
2931 }
2932
2933 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002934 * Determine whether or not creating a guest user has been disabled for the device
2935 *
2936 * @hide
2937 */
2938 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2939 // Currently guest users can always be created if multi-user is enabled
2940 // TODO introduce a policy for guest user creation
2941 return false;
2942 }
2943
2944 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002945 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2946 * screen capture also prevents the content from being shown on display devices that do not have
2947 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2948 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002949 *
2950 * <p>The calling device admin must be a device or profile owner. If it is not, a
2951 * security exception will be thrown.
2952 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002953 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002954 * blocks assist requests for all activities of the relevant user.
2955 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002956 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002957 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002958 */
Robin Lee25e26452015-06-02 09:56:29 -07002959 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002960 if (mService != null) {
2961 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002962 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002963 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002964 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002965 }
2966 }
2967 }
2968
2969 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002970 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002971 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002972 * @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 +01002973 * have disabled screen capture.
2974 */
Robin Lee25e26452015-06-02 09:56:29 -07002975 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002976 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002977 }
2978
2979 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002980 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002981 if (mService != null) {
2982 try {
2983 return mService.getScreenCaptureDisabled(admin, userHandle);
2984 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002985 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002986 }
2987 }
2988 return false;
2989 }
2990
2991 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002992 * Called by a device owner to set whether auto time is required. If auto time is
2993 * required the user cannot set the date and time, but has to use network date and time.
2994 *
2995 * <p>Note: if auto time is required the user can still manually set the time zone.
2996 *
2997 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2998 * be thrown.
2999 *
3000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3001 * @param required Whether auto time is set required or not.
3002 */
Robin Lee25e26452015-06-02 09:56:29 -07003003 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003004 if (mService != null) {
3005 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003006 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003007 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003008 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003009 }
3010 }
3011 }
3012
3013 /**
3014 * @return true if auto time is required.
3015 */
3016 public boolean getAutoTimeRequired() {
3017 if (mService != null) {
3018 try {
3019 return mService.getAutoTimeRequired();
3020 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003021 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003022 }
3023 }
3024 return false;
3025 }
3026
3027 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003028 * Called by a device owner to set whether all users created on the device should be ephemeral.
3029 *
3030 * <p>The system user is exempt from this policy - it is never ephemeral.
3031 *
3032 * <p>The calling device admin must be the device owner. If it is not, a security exception will
3033 * be thrown.
3034 *
3035 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3036 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
3037 * subsequently created users will be ephemeral.
3038 * @hide
3039 */
3040 public void setForceEphemeralUsers(
3041 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3042 if (mService != null) {
3043 try {
3044 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3045 } catch (RemoteException e) {
3046 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3047 }
3048 }
3049 }
3050
3051 /**
3052 * @return true if all users are created ephemeral.
3053 * @hide
3054 */
3055 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3056 if (mService != null) {
3057 try {
3058 return mService.getForceEphemeralUsers(admin);
3059 } catch (RemoteException e) {
3060 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3061 }
3062 }
3063 return false;
3064 }
3065
3066 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003067 * Called by an application that is administering the device to disable keyguard customizations,
3068 * such as widgets. After setting this, keyguard features will be disabled according to the
3069 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003070 *
3071 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07003072 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07003073 * this method; if it has not, a security exception will be thrown.
3074 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003075 * <p>Calling this from a managed profile before version
Esteban Talaverac1c83592016-02-17 17:56:15 +00003076 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version
3077 * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003078 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003079 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
3080 * is no separate challenge set on the managed profile.
3081 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
3082 * there is one, or the parent user otherwise.
3083 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications
3084 * generated by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003085 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003086 *
3087 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3088 * set on the {@link DevicePolicyManager} instance returned by
3089 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the
3090 * parent profile.
3091 *
3092 * <p>Requests to disable other features on a managed profile will be ignored.
3093 *
3094 * <p>The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003095 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003096 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003098 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
3099 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07003100 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003101 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
3102 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07003103 */
Robin Lee25e26452015-06-02 09:56:29 -07003104 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003105 if (mService != null) {
3106 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003107 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003108 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003109 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07003110 }
3111 }
3112 }
3113
3114 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003115 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003116 * admin, if specified, or all admins that set retrictions on this user and its participating
3117 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3118 *
3119 * <p>This method can be called on the {@link DevicePolicyManager} instance
3120 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3121 * restrictions on the parent profile.
3122 *
Esteban Talavera62399912016-01-11 15:37:55 +00003123 * @param admin The name of the admin component to check, or {@code null} to check whether any
3124 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003125 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3126 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003127 */
Robin Lee25e26452015-06-02 09:56:29 -07003128 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003129 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003130 }
3131
3132 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003133 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003134 if (mService != null) {
3135 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003136 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003137 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003138 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07003139 }
3140 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003141 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003142 }
3143
3144 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003145 * @hide
3146 */
Robin Lee25e26452015-06-02 09:56:29 -07003147 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3148 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003149 if (mService != null) {
3150 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003151 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003152 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003153 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003154 }
3155 }
3156 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003157
Dianne Hackbornd6847842010-01-12 18:14:19 -08003158 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003159 * @hide
3160 */
Robin Lee25e26452015-06-02 09:56:29 -07003161 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003162 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003163 }
3164
3165 /**
Robin Lee25e26452015-06-02 09:56:29 -07003166 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08003167 * @hide
3168 */
Robin Lee25e26452015-06-02 09:56:29 -07003169 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003170 ActivityInfo ai;
3171 try {
3172 ai = mContext.getPackageManager().getReceiverInfo(cn,
3173 PackageManager.GET_META_DATA);
3174 } catch (PackageManager.NameNotFoundException e) {
3175 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
3176 return null;
3177 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003178
Dianne Hackbornd6847842010-01-12 18:14:19 -08003179 ResolveInfo ri = new ResolveInfo();
3180 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003181
Dianne Hackbornd6847842010-01-12 18:14:19 -08003182 try {
3183 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08003184 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003185 Log.w(TAG, "Unable to parse device policy " + cn, e);
3186 return null;
3187 }
3188 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003189
Dianne Hackbornd6847842010-01-12 18:14:19 -08003190 /**
3191 * @hide
3192 */
Robin Lee25e26452015-06-02 09:56:29 -07003193 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003194 if (mService != null) {
3195 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003196 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003197 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003198 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003199 }
3200 }
3201 }
3202
3203 /**
3204 * @hide
3205 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003206 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003207 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003208 if (mService != null) {
3209 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003210 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003211 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003212 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003213 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003214 }
3215 }
3216 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003217
Dianne Hackbornd6847842010-01-12 18:14:19 -08003218 /**
3219 * @hide
3220 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003221 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003222 if (mService != null) {
3223 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003224 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003225 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003226 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003227 }
3228 }
3229 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003230
Dianne Hackbornd6847842010-01-12 18:14:19 -08003231 /**
3232 * @hide
3233 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003234 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003235 if (mService != null) {
3236 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003237 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003238 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003239 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003240 }
3241 }
3242 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003243
3244 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003245 * @hide
3246 */
3247 public void reportFailedFingerprintAttempt(int userHandle) {
3248 if (mService != null) {
3249 try {
3250 mService.reportFailedFingerprintAttempt(userHandle);
3251 } catch (RemoteException e) {
3252 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3253 }
3254 }
3255 }
3256
3257 /**
3258 * @hide
3259 */
3260 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3261 if (mService != null) {
3262 try {
3263 mService.reportSuccessfulFingerprintAttempt(userHandle);
3264 } catch (RemoteException e) {
3265 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3266 }
3267 }
3268 }
3269
3270 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003271 * Should be called when keyguard has been dismissed.
3272 * @hide
3273 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003274 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003275 if (mService != null) {
3276 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003277 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003278 } catch (RemoteException e) {
3279 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3280 }
3281 }
3282 }
3283
3284 /**
3285 * Should be called when keyguard view has been shown to the user.
3286 * @hide
3287 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003288 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003289 if (mService != null) {
3290 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003291 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003292 } catch (RemoteException e) {
3293 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3294 }
3295 }
3296 }
3297
3298 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003299 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003300 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003301 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3302 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003303 * @return whether the package was successfully registered as the device owner.
3304 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003305 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003306 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003307 public boolean setDeviceOwner(ComponentName who) {
3308 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003309 }
3310
3311 /**
3312 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003313 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003314 public boolean setDeviceOwner(ComponentName who, int userId) {
3315 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003316 }
3317
3318 /**
3319 * @hide
3320 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003321 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3322 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003323 }
3324
3325 /**
3326 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003327 * Sets the given package as the device owner. The package must already be installed. There
3328 * must not already be a device owner.
3329 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3330 * this method.
3331 * Calling this after the setup phase of the primary user has completed is allowed only if
3332 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003333 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003334 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003335 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003336 * @return whether the package was successfully registered as the device owner.
3337 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003338 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003339 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003340 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003341 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003342 if (mService != null) {
3343 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003344 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003345 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003346 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003347 }
3348 }
3349 return false;
3350 }
3351
3352 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003353 * Used to determine if a particular package has been registered as a Device Owner app.
3354 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003355 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003356 * package is currently registered as the device owner app, pass in the package name from
3357 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003358 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003359 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3360 * the setup process.
3361 * @param packageName the package name of the app, to compare with the registered device owner
3362 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003363 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003364 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003365 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003366 return isDeviceOwnerAppOnCallingUser(packageName);
3367 }
3368
3369 /**
3370 * @return true if a package is registered as device owner, only when it's running on the
3371 * calling user.
3372 *
3373 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3374 * @hide
3375 */
3376 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3377 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3378 }
3379
3380 /**
3381 * @return true if a package is registered as device owner, even if it's running on a different
3382 * user.
3383 *
3384 * <p>Requires the MANAGE_USERS permission.
3385 *
3386 * @hide
3387 */
3388 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3389 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3390 }
3391
3392 /**
3393 * @return device owner component name, only when it's running on the calling user.
3394 *
3395 * @hide
3396 */
3397 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3398 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3399 }
3400
3401 /**
3402 * @return device owner component name, even if it's running on a different user.
3403 *
3404 * <p>Requires the MANAGE_USERS permission.
3405 *
3406 * @hide
3407 */
3408 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3409 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3410 }
3411
3412 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003413 if (packageName == null) {
3414 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003415 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003416 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003417 if (deviceOwner == null) {
3418 return false;
3419 }
3420 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003421 }
3422
Makoto Onukic8a5a552015-11-19 14:29:12 -08003423 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3424 if (mService != null) {
3425 try {
3426 return mService.getDeviceOwnerComponent(callingUserOnly);
3427 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003428 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003429 }
3430 }
3431 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003432 }
3433
Jason Monkb0dced82014-06-06 14:36:20 -04003434 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003435 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3436 * no device owner.
3437 *
3438 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003439 *
3440 * @hide
3441 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003442 public int getDeviceOwnerUserId() {
3443 if (mService != null) {
3444 try {
3445 return mService.getDeviceOwnerUserId();
3446 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003447 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003448 }
3449 }
3450 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003451 }
3452
3453 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003454 * Clears the current device owner. The caller must be the device owner.
3455 *
3456 * This function should be used cautiously as once it is called it cannot
3457 * be undone. The device owner can only be set as a part of device setup
3458 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003459 *
3460 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003461 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003462 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003463 if (mService != null) {
3464 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003465 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003466 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003467 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003468 }
3469 }
3470 }
3471
Makoto Onukia52562c2015-10-01 16:12:31 -07003472 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003473 * Returns the device owner package name, only if it's running on the calling user.
3474 *
3475 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003476 *
3477 * @hide
3478 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003479 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003480 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003481 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3482 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003483 }
3484
3485 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003486 * @return true if the device is managed by any device owner.
3487 *
3488 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003489 *
3490 * @hide
3491 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003492 public boolean isDeviceManaged() {
3493 return getDeviceOwnerComponentOnAnyUser() != null;
3494 }
3495
3496 /**
3497 * Returns the device owner name. Note this method *will* return the device owner
3498 * name when it's running on a different user.
3499 *
3500 * <p>Requires the MANAGE_USERS permission.
3501 *
3502 * @hide
3503 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003504 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003505 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003506 if (mService != null) {
3507 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003508 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003509 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003510 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003511 }
3512 }
3513 return null;
3514 }
Adam Connors776c5552014-01-09 10:42:56 +00003515
3516 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003517 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003518 * @deprecated Do not use
3519 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003520 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003521 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003522 @SystemApi
3523 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003524 return null;
3525 }
3526
3527 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003528 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003529 * @deprecated Do not use
3530 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003531 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003532 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003533 @SystemApi
3534 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003535 return null;
3536 }
3537
Julia Reynolds20118f12015-02-11 12:34:08 -05003538 /**
Adam Connors776c5552014-01-09 10:42:56 +00003539 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003540 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303541 * Sets the given component as an active admin and registers the package as the profile
3542 * owner for this user. The package must already be installed and there shouldn't be
3543 * an existing profile owner registered for this user. Also, this method must be called
3544 * before the user setup has been completed.
3545 * <p>
3546 * This method can only be called by system apps that hold MANAGE_USERS permission and
3547 * MANAGE_DEVICE_ADMINS permission.
3548 * @param admin The component to register as an active admin and profile owner.
3549 * @param ownerName The user-visible name of the entity that is managing this user.
3550 * @return whether the admin was successfully registered as the profile owner.
3551 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3552 * the user has already been set up.
3553 */
Justin Morey80440cc2014-07-24 09:16:35 -05003554 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003555 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303556 throws IllegalArgumentException {
3557 if (mService != null) {
3558 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003559 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303560 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003561 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303562 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303563 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3564 }
3565 }
3566 return false;
3567 }
3568
3569 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003570 * Clears the active profile owner and removes all user restrictions. The caller must
3571 * be from the same package as the active profile owner for this user, otherwise a
3572 * SecurityException will be thrown.
3573 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003574 * <p>This doesn't work for managed profile owners.
3575 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003576 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003577 */
Robin Lee25e26452015-06-02 09:56:29 -07003578 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003579 if (mService != null) {
3580 try {
3581 mService.clearProfileOwner(admin);
3582 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003583 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003584 }
3585 }
3586 }
3587
3588 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003589 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003590 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003591 */
3592 public boolean hasUserSetupCompleted() {
3593 if (mService != null) {
3594 try {
3595 return mService.hasUserSetupCompleted();
3596 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003597 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003598 }
3599 }
3600 return true;
3601 }
3602
3603 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003604 * @hide
3605 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003606 * already be installed. There must not already be a profile owner for this user.
3607 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3608 * this method.
3609 * Calling this after the setup phase of the specified user has completed is allowed only if:
3610 * - the caller is SYSTEM_UID.
3611 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003612 * @param admin the component name to be registered as profile owner.
3613 * @param ownerName the human readable name of the organisation associated with this DPM.
3614 * @param userHandle the userId to set the profile owner for.
3615 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003616 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3617 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003618 */
Robin Lee25e26452015-06-02 09:56:29 -07003619 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003620 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003621 if (mService != null) {
3622 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003623 if (ownerName == null) {
3624 ownerName = "";
3625 }
3626 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003627 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003628 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003629 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3630 }
3631 }
3632 return false;
3633 }
3634
3635 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003636 * Sets the device owner information to be shown on the lock screen.
3637 *
3638 * <p>If the device owner information is {@code null} or empty then the device owner info is
3639 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003640 * <p>If the device owner information contains only whitespaces then the message on the lock
3641 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003642 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003643 * <p>If the device owner information needs to be localized, it is the responsibility of the
3644 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3645 * and set a new version of this string accordingly.
3646 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003647 * @param admin The name of the admin component to check.
3648 * @param info Device owner information which will be displayed instead of the user
3649 * owner info.
3650 * @return Whether the device owner information has been set.
3651 */
3652 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3653 if (mService != null) {
3654 try {
3655 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3656 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003657 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003658 }
3659 }
3660 return false;
3661 }
3662
3663 /**
3664 * @return The device owner information. If it is not set returns {@code null}.
3665 */
3666 public String getDeviceOwnerLockScreenInfo() {
3667 if (mService != null) {
3668 try {
3669 return mService.getDeviceOwnerLockScreenInfo();
3670 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003671 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003672 }
3673 }
3674 return null;
3675 }
3676
3677 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003678 * Called by device or profile owners to suspend packages for this user.
3679 *
3680 * <p>A suspended package will not be able to start activities. Its notifications will
3681 * be hidden, it will not show up in recents, will not be able to show toasts or dialogs
3682 * or ring the device.
3683 *
3684 * <p>The package must already be installed.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003685 *
3686 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003687 * @param packageNames The package names to suspend or unsuspend.
3688 * @param suspended If set to {@code true} than the packages will be suspended, if set to
3689 * {@code false} the packages will be unsuspended.
3690 * @return an array of package names for which the suspended status is not set as requested in
3691 * this method.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003692 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003693 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003694 boolean suspended) {
3695 if (mService != null) {
3696 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003697 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003698 } catch (RemoteException re) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00003699 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003700 }
3701 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003702 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003703 }
3704
3705 /**
3706 * Called by device or profile owners to determine if a package is suspended.
3707 *
3708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3709 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003710 * @return {@code true} if the package is suspended or {@code false} if the package is not
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003711 * suspended, could not be found or an error occurred.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003712 */
3713 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3714 if (mService != null) {
3715 try {
3716 return mService.getPackageSuspended(admin, packageName);
3717 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00003718 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003719 }
3720 }
3721 return false;
3722 }
3723
3724 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003725 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3726 * be used. Only the profile owner can call this.
3727 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003728 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003729 *
3730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3731 */
Robin Lee25e26452015-06-02 09:56:29 -07003732 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003733 if (mService != null) {
3734 try {
3735 mService.setProfileEnabled(admin);
3736 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003737 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003738 }
3739 }
3740 }
3741
3742 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003743 * Sets the name of the profile. In the device owner case it sets the name of the user
3744 * which it is called from. Only a profile owner or device owner can call this. If this is
Jessica Hummel1333ea12014-06-23 11:20:10 +01003745 * never called by the profile or device owner, the name will be set to default values.
3746 *
3747 * @see #isProfileOwnerApp
3748 * @see #isDeviceOwnerApp
3749 *
Robin Lee25e26452015-06-02 09:56:29 -07003750 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003751 * @param profileName The name of the profile.
3752 */
Robin Lee25e26452015-06-02 09:56:29 -07003753 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003754 if (mService != null) {
3755 try {
Robin Lee25e26452015-06-02 09:56:29 -07003756 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003757 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003758 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003759 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003760 }
3761 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003762
3763 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003764 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003765 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003766 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003767 *
3768 * @param packageName The package name of the app to compare with the registered profile owner.
3769 * @return Whether or not the package is registered as the profile owner.
3770 */
3771 public boolean isProfileOwnerApp(String packageName) {
3772 if (mService != null) {
3773 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003774 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003775 return profileOwner != null
3776 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003777 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003778 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003779 }
3780 }
3781 return false;
3782 }
3783
3784 /**
3785 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003786 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003787 * owner has been set for that user.
3788 * @throws IllegalArgumentException if the userId is invalid.
3789 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003790 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003791 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003792 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3793 }
3794
3795 /**
3796 * @see #getProfileOwner()
3797 * @hide
3798 */
3799 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003800 if (mService != null) {
3801 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003802 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003803 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003804 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003805 throw new IllegalArgumentException(
3806 "Requested profile owner for invalid userId", re);
3807 }
3808 }
3809 return null;
3810 }
3811
3812 /**
3813 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003814 * @return the human readable name of the organisation associated with this DPM or {@code null}
3815 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003816 * @throws IllegalArgumentException if the userId is invalid.
3817 */
3818 public String getProfileOwnerName() throws IllegalArgumentException {
3819 if (mService != null) {
3820 try {
3821 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3822 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003823 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003824 throw new IllegalArgumentException(
3825 "Requested profile owner for invalid userId", re);
3826 }
3827 }
3828 return null;
3829 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003830
3831 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003832 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003833 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003834 * @return the human readable name of the organisation associated with this profile owner or
3835 * null if one is not set.
3836 * @throws IllegalArgumentException if the userId is invalid.
3837 */
3838 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003839 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003840 if (mService != null) {
3841 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003842 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003843 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003844 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003845 throw new IllegalArgumentException(
3846 "Requested profile owner for invalid userId", re);
3847 }
3848 }
3849 return null;
3850 }
3851
3852 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003853 * Called by a profile owner or device owner to add a default intent handler activity for
3854 * intents that match a certain intent filter. This activity will remain the default intent
3855 * handler even if the set of potential event handlers for the intent filter changes and if
3856 * the intent preferences are reset.
3857 *
3858 * <p>The default disambiguation mechanism takes over if the activity is not installed
3859 * (anymore). When the activity is (re)installed, it is automatically reset as default
3860 * intent handler for the filter.
3861 *
3862 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3863 * security exception will be thrown.
3864 *
3865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3866 * @param filter The IntentFilter for which a default handler is added.
3867 * @param activity The Activity that is added as default intent handler.
3868 */
Robin Lee25e26452015-06-02 09:56:29 -07003869 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3870 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003871 if (mService != null) {
3872 try {
3873 mService.addPersistentPreferredActivity(admin, filter, activity);
3874 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003875 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003876 }
3877 }
3878 }
3879
3880 /**
3881 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003882 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003883 *
3884 * <p>The calling device admin must be a profile owner. If it is not, a security
3885 * exception will be thrown.
3886 *
3887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3888 * @param packageName The name of the package for which preferences are removed.
3889 */
Robin Lee25e26452015-06-02 09:56:29 -07003890 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003891 String packageName) {
3892 if (mService != null) {
3893 try {
3894 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3895 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003896 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003897 }
3898 }
3899 }
Robin Lee66e5d962014-04-09 16:44:21 +01003900
3901 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003902 * Called by a profile owner or device owner to grant permission to a package to manage
3903 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3904 * {@link #getApplicationRestrictions}.
3905 * <p>
3906 * This permission is persistent until it is later cleared by calling this method with a
3907 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00003908 * <p>
3909 * The supplied application restriction managing package must be installed when calling this
3910 * API, otherwise an {@link IllegalArgumentException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00003911 *
3912 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3913 * @param packageName The package name which will be given access to application restrictions
3914 * APIs. If {@code null} is given the current package will be cleared.
3915 */
3916 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3917 @Nullable String packageName) {
3918 if (mService != null) {
3919 try {
3920 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3921 } catch (RemoteException e) {
3922 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3923 }
3924 }
3925 }
3926
3927 /**
3928 * Called by a profile owner or device owner to retrieve the application restrictions managing
3929 * package for the current user, or {@code null} if none is set.
3930 *
3931 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3932 * @return The package name allowed to manage application restrictions on the current user, or
3933 * {@code null} if none is set.
3934 */
3935 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3936 if (mService != null) {
3937 try {
3938 return mService.getApplicationRestrictionsManagingPackage(admin);
3939 } catch (RemoteException e) {
3940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3941 }
3942 }
3943 return null;
3944 }
3945
3946 /**
3947 * Returns {@code true} if the calling package has been granted permission via
3948 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3949 * restrictions for the calling user.
3950 */
3951 public boolean isCallerApplicationRestrictionsManagingPackage() {
3952 if (mService != null) {
3953 try {
3954 return mService.isCallerApplicationRestrictionsManagingPackage();
3955 } catch (RemoteException e) {
3956 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3957 }
3958 }
3959 return false;
3960 }
3961
3962 /**
3963 * Sets the application restrictions for a given target application running in the calling user.
3964 *
3965 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3966 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3967 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003968 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003969 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3970 * <ul>
3971 * <li>{@code boolean}
3972 * <li>{@code int}
3973 * <li>{@code String} or {@code String[]}
3974 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3975 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003976 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003977 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003978 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003979 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3980 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003981 * <p>The application restrictions are only made visible to the target application via
3982 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3983 * device owner, and the application restrictions managing package via
3984 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003985 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3987 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003988 * @param packageName The name of the package to update restricted settings for.
3989 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3990 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003991 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003992 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003993 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003994 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003995 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003996 Bundle settings) {
3997 if (mService != null) {
3998 try {
3999 mService.setApplicationRestrictions(admin, packageName, settings);
4000 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004001 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004002 }
4003 }
4004 }
4005
4006 /**
Jim Millere303bf42014-08-26 17:12:29 -07004007 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
4008 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
4009 * trust agents but those enabled by this function call. If flag
4010 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07004011 *
4012 * <p>The calling device admin must have requested
4013 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07004014 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07004015 *
4016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004017 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08004018 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07004019 * will be strictly disabled according to the state of the
4020 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4021 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
4022 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
4023 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07004024 */
Robin Lee25e26452015-06-02 09:56:29 -07004025 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4026 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004027 if (mService != null) {
4028 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004029 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004030 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004031 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07004032 }
4033 }
4034 }
4035
4036 /**
Jim Millere303bf42014-08-26 17:12:29 -07004037 * Gets configuration for the given trust agent based on aggregating all calls to
4038 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4039 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004040 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004041 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4042 * this function returns a list of configurations for all admins that declare
4043 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4044 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4045 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4046 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004047 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004048 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004049 */
Robin Lee25e26452015-06-02 09:56:29 -07004050 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4051 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004052 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004053 }
4054
4055 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004056 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4057 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004058 if (mService != null) {
4059 try {
Jim Millere303bf42014-08-26 17:12:29 -07004060 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004061 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004062 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07004063 }
4064 }
Jim Millere303bf42014-08-26 17:12:29 -07004065 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004066 }
4067
4068 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004069 * Called by a profile owner of a managed profile to set whether caller-Id information from
4070 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01004071 *
4072 * <p>The calling device admin must be a profile owner. If it is not, a
4073 * security exception will be thrown.
4074 *
Robin Lee25e26452015-06-02 09:56:29 -07004075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004076 * @param disabled If true caller-Id information in the managed profile is not displayed.
4077 */
Robin Lee25e26452015-06-02 09:56:29 -07004078 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004079 if (mService != null) {
4080 try {
Robin Lee25e26452015-06-02 09:56:29 -07004081 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004082 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004083 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01004084 }
4085 }
4086 }
4087
4088 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004089 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4090 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01004091 *
4092 * <p>The calling device admin must be a profile owner. If it is not, a
4093 * security exception will be thrown.
4094 *
Robin Lee25e26452015-06-02 09:56:29 -07004095 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004096 */
Robin Lee25e26452015-06-02 09:56:29 -07004097 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004098 if (mService != null) {
4099 try {
Robin Lee25e26452015-06-02 09:56:29 -07004100 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004101 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004102 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01004103 }
4104 }
4105 return false;
4106 }
4107
4108 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004109 * Determine whether or not caller-Id information has been disabled.
4110 *
4111 * @param userHandle The user for whom to check the caller-id permission
4112 * @hide
4113 */
4114 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4115 if (mService != null) {
4116 try {
4117 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4118 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004119 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07004120 }
4121 }
4122 return false;
4123 }
4124
4125 /**
Victor Chang1060c6182016-01-04 20:16:23 +00004126 * Called by a profile owner of a managed profile to set whether contacts search from
4127 * the managed profile will be shown in the parent profile, for incoming calls.
4128 *
4129 * <p>The calling device admin must be a profile owner. If it is not, a
4130 * security exception will be thrown.
4131 *
4132 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4133 * @param disabled If true contacts search in the managed profile is not displayed.
4134 */
4135 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4136 boolean disabled) {
4137 if (mService != null) {
4138 try {
4139 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4140 } catch (RemoteException e) {
4141 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4142 }
4143 }
4144 }
4145
4146 /**
4147 * Called by a profile owner of a managed profile to determine whether or not contacts search
4148 * has been disabled.
4149 *
4150 * <p>The calling device admin must be a profile owner. If it is not, a
4151 * security exception will be thrown.
4152 *
4153 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4154 */
4155 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4156 if (mService != null) {
4157 try {
4158 return mService.getCrossProfileContactsSearchDisabled(admin);
4159 } catch (RemoteException e) {
4160 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4161 }
4162 }
4163 return false;
4164 }
4165
4166
4167 /**
4168 * Determine whether or not contacts search has been disabled.
4169 *
4170 * @param userHandle The user for whom to check the contacts search permission
4171 * @hide
4172 */
4173 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4174 if (mService != null) {
4175 try {
4176 return mService
4177 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4178 } catch (RemoteException e) {
4179 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4180 }
4181 }
4182 return false;
4183 }
4184
4185 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004186 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004187 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004188 * @hide
4189 */
4190 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004191 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004192 if (mService != null) {
4193 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004194 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4195 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004196 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004197 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07004198 }
4199 }
4200 }
4201
4202 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004203 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004204 * @hide
4205 */
4206 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4207 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004208 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004209 originalIntent);
4210 }
4211
4212 /**
Ricky Wai778ba132015-03-31 14:21:22 +01004213 * Called by a profile owner of a managed profile to set whether bluetooth
4214 * devices can access enterprise contacts.
4215 * <p>
4216 * The calling device admin must be a profile owner. If it is not, a
4217 * security exception will be thrown.
4218 * <p>
4219 * This API works on managed profile only.
4220 *
Robin Lee25e26452015-06-02 09:56:29 -07004221 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004222 * with.
4223 * @param disabled If true, bluetooth devices cannot access enterprise
4224 * contacts.
4225 */
Robin Lee25e26452015-06-02 09:56:29 -07004226 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004227 if (mService != null) {
4228 try {
Robin Lee25e26452015-06-02 09:56:29 -07004229 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004230 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004231 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004232 }
4233 }
4234 }
4235
4236 /**
4237 * Called by a profile owner of a managed profile to determine whether or
4238 * not Bluetooth devices cannot access enterprise contacts.
4239 * <p>
4240 * The calling device admin must be a profile owner. If it is not, a
4241 * security exception will be thrown.
4242 * <p>
4243 * This API works on managed profile only.
4244 *
Robin Lee25e26452015-06-02 09:56:29 -07004245 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004246 * with.
4247 */
Robin Lee25e26452015-06-02 09:56:29 -07004248 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004249 if (mService != null) {
4250 try {
Robin Lee25e26452015-06-02 09:56:29 -07004251 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004252 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004253 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004254 }
4255 }
4256 return true;
4257 }
4258
4259 /**
4260 * Determine whether or not Bluetooth devices cannot access contacts.
4261 * <p>
4262 * This API works on managed profile UserHandle only.
4263 *
4264 * @param userHandle The user for whom to check the caller-id permission
4265 * @hide
4266 */
4267 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4268 if (mService != null) {
4269 try {
4270 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4271 .getIdentifier());
4272 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004273 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004274 }
4275 }
4276 return true;
4277 }
4278
4279 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004280 * Called by the profile owner of a managed profile so that some intents sent in the managed
4281 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004282 * Only activity intents are supported.
4283 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004284 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004285 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4286 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004287 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4288 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004289 */
Robin Lee25e26452015-06-02 09:56:29 -07004290 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004291 if (mService != null) {
4292 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004293 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004294 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004295 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004296 }
4297 }
4298 }
4299
4300 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004301 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4302 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004303 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4305 */
Robin Lee25e26452015-06-02 09:56:29 -07004306 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004307 if (mService != null) {
4308 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004309 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004310 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004312 }
4313 }
4314 }
4315
4316 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004317 * Called by a profile or device owner to set the permitted accessibility services. When
4318 * set by a device owner or profile owner the restriction applies to all profiles of the
4319 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004320 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004321 * By default the user can use any accessiblity service. When zero or more packages have
4322 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004323 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004324 *
4325 * <p> Calling with a null value for the list disables the restriction so that all services
4326 * can be used, calling with an empty list only allows the builtin system's services.
4327 *
4328 * <p> System accesibility services are always available to the user the list can't modify
4329 * this.
4330 *
4331 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4332 * @param packageNames List of accessibility service package names.
4333 *
4334 * @return true if setting the restriction succeeded. It fail if there is
4335 * one or more non-system accessibility services enabled, that are not in the list.
4336 */
Robin Lee25e26452015-06-02 09:56:29 -07004337 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004338 List<String> packageNames) {
4339 if (mService != null) {
4340 try {
4341 return mService.setPermittedAccessibilityServices(admin, packageNames);
4342 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004343 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004344 }
4345 }
4346 return false;
4347 }
4348
4349 /**
4350 * Returns the list of permitted accessibility services set by this device or profile owner.
4351 *
4352 * <p>An empty list means no accessibility services except system services are allowed.
4353 * Null means all accessibility services are allowed.
4354 *
4355 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4356 * @return List of accessiblity service package names.
4357 */
Robin Lee25e26452015-06-02 09:56:29 -07004358 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004359 if (mService != null) {
4360 try {
4361 return mService.getPermittedAccessibilityServices(admin);
4362 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004363 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004364 }
4365 }
4366 return null;
4367 }
4368
4369 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004370 * Called by the system to check if a specific accessibility service is disabled by admin.
4371 *
4372 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4373 * @param packageName Accessibility service package name that needs to be checked.
4374 * @param userHandle user id the admin is running as.
4375 * @return true if the accessibility service is permitted, otherwise false.
4376 *
4377 * @hide
4378 */
4379 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4380 @NonNull String packageName, int userHandle) {
4381 if (mService != null) {
4382 try {
4383 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4384 userHandle);
4385 } catch (RemoteException e) {
4386 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4387 }
4388 }
4389 return false;
4390 }
4391
4392 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004393 * Returns the list of accessibility services permitted by the device or profiles
4394 * owners of this user.
4395 *
4396 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4397 * it will contain the intersection of the permitted lists for any device or profile
4398 * owners that apply to this user. It will also include any system accessibility services.
4399 *
4400 * @param userId which user to check for.
4401 * @return List of accessiblity service package names.
4402 * @hide
4403 */
4404 @SystemApi
4405 public List<String> getPermittedAccessibilityServices(int userId) {
4406 if (mService != null) {
4407 try {
4408 return mService.getPermittedAccessibilityServicesForUser(userId);
4409 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004410 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004411 }
4412 }
4413 return null;
4414 }
4415
4416 /**
4417 * Called by a profile or device owner to set the permitted input methods services. When
4418 * set by a device owner or profile owner the restriction applies to all profiles of the
4419 * user the device owner or profile owner is an admin for.
4420 *
4421 * By default the user can use any input method. When zero or more packages have
4422 * been added, input method that are not in the list and not part of the system
4423 * can not be enabled by the user.
4424 *
4425 * This method will fail if it is called for a admin that is not for the foreground user
4426 * or a profile of the foreground user.
4427 *
4428 * <p> Calling with a null value for the list disables the restriction so that all input methods
4429 * can be used, calling with an empty list disables all but the system's own input methods.
4430 *
4431 * <p> System input methods are always available to the user this method can't modify this.
4432 *
4433 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4434 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004435 * @return true if setting the restriction succeeded. It will fail if there are
4436 * one or more non-system input methods currently enabled that are not in
4437 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004438 */
Robin Lee25e26452015-06-02 09:56:29 -07004439 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004440 if (mService != null) {
4441 try {
4442 return mService.setPermittedInputMethods(admin, packageNames);
4443 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004444 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004445 }
4446 }
4447 return false;
4448 }
4449
4450
4451 /**
4452 * Returns the list of permitted input methods set by this device or profile owner.
4453 *
4454 * <p>An empty list means no input methods except system input methods are allowed.
4455 * Null means all input methods are allowed.
4456 *
4457 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4458 * @return List of input method package names.
4459 */
Robin Lee25e26452015-06-02 09:56:29 -07004460 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004461 if (mService != null) {
4462 try {
4463 return mService.getPermittedInputMethods(admin);
4464 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004465 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004466 }
4467 }
4468 return null;
4469 }
4470
4471 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004472 * Called by the system to check if a specific input method is disabled by admin.
4473 *
4474 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4475 * @param packageName Input method package name that needs to be checked.
4476 * @param userHandle user id the admin is running as.
4477 * @return true if the input method is permitted, otherwise false.
4478 *
4479 * @hide
4480 */
4481 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4482 @NonNull String packageName, int userHandle) {
4483 if (mService != null) {
4484 try {
4485 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4486 } catch (RemoteException e) {
4487 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4488 }
4489 }
4490 return false;
4491 }
4492
4493 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004494 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004495 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004496 *
4497 * <p>Null means all input methods are allowed, if a non-null list is returned
4498 * it will contain the intersection of the permitted lists for any device or profile
4499 * owners that apply to this user. It will also include any system input methods.
4500 *
4501 * @return List of input method package names.
4502 * @hide
4503 */
4504 @SystemApi
4505 public List<String> getPermittedInputMethodsForCurrentUser() {
4506 if (mService != null) {
4507 try {
4508 return mService.getPermittedInputMethodsForCurrentUser();
4509 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004510 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004511 }
4512 }
4513 return null;
4514 }
4515
4516 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004517 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4518 * currently installed it.
4519 *
4520 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4521 *
4522 * @return List of package names to keep cached.
4523 * @hide
4524 */
4525 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4526 if (mService != null) {
4527 try {
4528 return mService.getKeepUninstalledPackages(admin);
4529 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004530 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004531 }
4532 }
4533 return null;
4534 }
4535
4536 /**
4537 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4538 * currently installed it.
4539 *
4540 * <p>Please note that setting this policy does not imply that specified apps will be
4541 * automatically pre-cached.</p>
4542 *
4543 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4544 * @param packageNames List of package names to keep cached.
4545 * @hide
4546 */
4547 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4548 @NonNull List<String> packageNames) {
4549 if (mService != null) {
4550 try {
4551 mService.setKeepUninstalledPackages(admin, packageNames);
4552 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004553 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004554 }
4555 }
4556 }
4557
4558 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004559 * Called by a device owner to create a user with the specified name. The UserHandle returned
4560 * by this method should not be persisted as user handles are recycled as users are removed and
4561 * created. If you need to persist an identifier for this user, use
4562 * {@link UserManager#getSerialNumberForUser}.
4563 *
4564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4565 * @param name the user's name
4566 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004567 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4568 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004569 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004570 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004571 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004572 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004573 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004574 try {
4575 return mService.createUser(admin, name);
4576 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004577 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004578 }
4579 return null;
4580 }
4581
4582 /**
Jason Monk03978a42014-06-10 15:05:30 -04004583 * Called by a device owner to create a user with the specified name. The UserHandle returned
4584 * by this method should not be persisted as user handles are recycled as users are removed and
4585 * created. If you need to persist an identifier for this user, use
4586 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4587 * immediately.
4588 *
4589 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4590 * as registered as an active admin on the new user. The profile owner package will be
4591 * installed on the new user if it already is installed on the device.
4592 *
4593 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4594 * profileOwnerComponent when onEnable is called.
4595 *
4596 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4597 * @param name the user's name
4598 * @param ownerName the human readable name of the organisation associated with this DPM.
4599 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4600 * the user.
4601 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4602 * on the new user.
4603 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004604 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4605 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004606 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004607 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004608 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004609 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004610 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4611 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004612 try {
4613 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4614 adminExtras);
4615 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004616 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004617 }
4618 return null;
4619 }
4620
4621 /**
phweissa92e1212016-01-25 17:14:10 +01004622 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004623 */
4624 public static final int SKIP_SETUP_WIZARD = 0x0001;
4625
4626 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004627 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4628 * ephemeral.
4629 * @hide
4630 */
4631 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4632
4633 /**
phweissa92e1212016-01-25 17:14:10 +01004634 * Called by a device owner to create a user with the specified name and a given component of
4635 * the calling package as profile owner. The UserHandle returned by this method should not be
4636 * persisted as user handles are recycled as users are removed and created. If you need to
4637 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4638 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004639 *
phweissa92e1212016-01-25 17:14:10 +01004640 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4641 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4642 * will be registered as an active admin on the new user. The profile owner package will be
4643 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004644 *
4645 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4646 * started for the first time. Then the extras will be passed to the admin when
4647 * onEnable is called.
4648 *
4649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4650 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004651 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4652 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4653 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004654 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4655 * user.
phweissa92e1212016-01-25 17:14:10 +01004656 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004657 * @see UserHandle
4658 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4659 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004660 */
4661 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004662 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4663 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004664 try {
phweissa92e1212016-01-25 17:14:10 +01004665 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004666 } catch (RemoteException re) {
4667 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4668 }
4669 return null;
4670 }
4671
4672 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004673 * Called by a device owner to remove a user and all associated data. The primary user can
4674 * not be removed.
4675 *
4676 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4677 * @param userHandle the user to remove.
4678 * @return {@code true} if the user was removed, {@code false} otherwise.
4679 */
Robin Lee25e26452015-06-02 09:56:29 -07004680 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004681 try {
4682 return mService.removeUser(admin, userHandle);
4683 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004684 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004685 return false;
4686 }
4687 }
4688
4689 /**
Jason Monk582d9112014-07-09 19:57:08 -04004690 * Called by a device owner to switch the specified user to the foreground.
4691 *
4692 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4693 * @param userHandle the user to switch to; null will switch to primary.
4694 * @return {@code true} if the switch was successful, {@code false} otherwise.
4695 *
4696 * @see Intent#ACTION_USER_FOREGROUND
4697 */
Robin Lee25e26452015-06-02 09:56:29 -07004698 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004699 try {
4700 return mService.switchUser(admin, userHandle);
4701 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004702 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004703 return false;
4704 }
4705 }
4706
4707 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004708 * Retrieves the application restrictions for a given target application running in the calling
4709 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004710 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004711 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4712 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4713 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004714 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004715 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4716 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004717 * @param packageName The name of the package to fetch restricted settings of.
4718 * @return {@link Bundle} of settings corresponding to what was set last time
4719 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4720 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004721 *
4722 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004723 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004724 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004725 if (mService != null) {
4726 try {
4727 return mService.getApplicationRestrictions(admin, packageName);
4728 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004729 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004730 }
4731 }
4732 return null;
4733 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004734
4735 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004736 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004737 * <p>
4738 * The calling device admin must be a profile or device owner; if it is not,
4739 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004740 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004741 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4742 * with.
4743 * @param key The key of the restriction. See the constants in
4744 * {@link android.os.UserManager} for the list of keys.
4745 */
Robin Lee25e26452015-06-02 09:56:29 -07004746 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004747 if (mService != null) {
4748 try {
4749 mService.setUserRestriction(admin, key, true);
4750 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004751 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004752 }
4753 }
4754 }
4755
4756 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004757 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004758 * <p>
4759 * The calling device admin must be a profile or device owner; if it is not,
4760 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004761 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004762 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4763 * with.
4764 * @param key The key of the restriction. See the constants in
4765 * {@link android.os.UserManager} for the list of keys.
4766 */
Robin Lee25e26452015-06-02 09:56:29 -07004767 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004768 if (mService != null) {
4769 try {
4770 mService.setUserRestriction(admin, key, false);
4771 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004772 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004773 }
4774 }
4775 }
Adam Connors010cfd42014-04-16 12:48:13 +01004776
4777 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004778 * Called by a profile or device owner to get user restrictions set with
4779 * {@link #addUserRestriction(ComponentName, String)}.
4780 * <p>
4781 * The target user may have more restrictions set by the system or other device owner / profile
4782 * owner. To get all the user restrictions currently set, use
4783 * {@link UserManager#getUserRestrictions()}.
4784 *
4785 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004786 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004787 */
4788 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004789 return getUserRestrictions(admin, myUserId());
4790 }
4791
4792 /** @hide per-user version */
4793 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004794 Bundle ret = null;
4795 if (mService != null) {
4796 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004797 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004798 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004799 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004800 }
4801 }
4802 return ret == null ? new Bundle() : ret;
4803 }
4804
4805 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004806 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004807 * is unavailable for use, but the data and actual package file remain.
4808 *
4809 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004810 * @param packageName The name of the package to hide or unhide.
4811 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4812 * unhidden.
4813 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004814 */
Robin Lee25e26452015-06-02 09:56:29 -07004815 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004816 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004817 if (mService != null) {
4818 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004819 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004820 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004821 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004822 }
4823 }
4824 return false;
4825 }
4826
4827 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004828 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004829 *
4830 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004831 * @param packageName The name of the package to retrieve the hidden status of.
4832 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004833 */
Robin Lee25e26452015-06-02 09:56:29 -07004834 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004835 if (mService != null) {
4836 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004837 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004838 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004839 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004840 }
4841 }
4842 return false;
4843 }
4844
4845 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004846 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004847 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004848 *
4849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004850 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004851 */
Robin Lee25e26452015-06-02 09:56:29 -07004852 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004853 if (mService != null) {
4854 try {
4855 mService.enableSystemApp(admin, packageName);
4856 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004857 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004858 }
4859 }
4860 }
4861
4862 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004863 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004864 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004865 *
4866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4867 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004868 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004869 * @return int The number of activities that matched the intent and were installed.
4870 */
Robin Lee25e26452015-06-02 09:56:29 -07004871 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004872 if (mService != null) {
4873 try {
4874 return mService.enableSystemAppWithIntent(admin, intent);
4875 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004876 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004877 }
4878 }
4879 return 0;
4880 }
4881
4882 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004883 * Called by a device owner or profile owner to disable account management for a specific type
4884 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004885 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004886 * <p>The calling device admin must be a device owner or profile owner. If it is not, a
Sander Alewijnse650c3342014-05-08 18:00:50 +01004887 * security exception will be thrown.
4888 *
4889 * <p>When account management is disabled for an account type, adding or removing an account
4890 * of that type will not be possible.
4891 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004892 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4893 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4894 * management for a specific type is disabled.
4895 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4897 * @param accountType For which account management is disabled or enabled.
4898 * @param disabled The boolean indicating that account management will be disabled (true) or
4899 * enabled (false).
4900 */
Robin Lee25e26452015-06-02 09:56:29 -07004901 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004902 boolean disabled) {
4903 if (mService != null) {
4904 try {
4905 mService.setAccountManagementDisabled(admin, accountType, disabled);
4906 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004907 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004908 }
4909 }
4910 }
4911
4912 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004913 * Gets the array of accounts for which account management is disabled by the profile owner.
4914 *
4915 * <p> Account management can be disabled/enabled by calling
4916 * {@link #setAccountManagementDisabled}.
4917 *
4918 * @return a list of account types for which account management has been disabled.
4919 *
4920 * @see #setAccountManagementDisabled
4921 */
4922 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004923 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004924 }
4925
4926 /**
4927 * @see #getAccountTypesWithManagementDisabled()
4928 * @hide
4929 */
4930 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004931 if (mService != null) {
4932 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004933 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004934 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004935 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004936 }
4937 }
4938
4939 return null;
4940 }
justinzhang511e0d82014-03-24 16:09:24 -04004941
4942 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004943 * Sets which packages may enter lock task mode.
4944 *
4945 * <p>Any packages that shares uid with an allowed package will also be allowed
4946 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004947 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004948 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004949 * package list results in locked tasks belonging to those packages to be finished.
4950 *
Jason Monkc5185f22014-06-24 11:12:42 -04004951 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004952 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004954 *
4955 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004956 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4957 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004958 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004959 */
Robin Lee25e26452015-06-02 09:56:29 -07004960 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004961 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004962 if (mService != null) {
4963 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004964 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004965 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004966 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004967 }
4968 }
4969 }
4970
4971 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004972 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004973 *
4974 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004975 * @hide
4976 */
Robin Lee25e26452015-06-02 09:56:29 -07004977 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004978 if (mService != null) {
4979 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004980 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004981 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004982 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004983 }
4984 }
4985 return null;
4986 }
4987
4988 /**
4989 * This function lets the caller know whether the given component is allowed to start the
4990 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004991 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004992 */
Jason Monkd7b86212014-06-16 13:15:38 -04004993 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004994 if (mService != null) {
4995 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004996 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004997 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004998 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004999 }
5000 }
5001 return false;
5002 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005003
5004 /**
5005 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5006 * of the setting is in the correct form for the setting type should be performed by the caller.
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005007 * <p>The settings that can be updated with this method are:
5008 * <ul>
5009 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5010 * <li>{@link Settings.Global#AUTO_TIME}</li>
5011 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005012 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005013 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005014 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00005015 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005016 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005017 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01005018 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005019 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01005020 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005021 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005022 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005023 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005024 * <ul>
5025 * <li>{@link Settings.Global#BLUETOOTH_ON}.
5026 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
5027 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
5028 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
5029 * <li>{@link Settings.Global#MODE_RINGER}.
5030 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
5031 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
5032 * <li>{@link Settings.Global#WIFI_ON}.
5033 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
5034 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005035 *
5036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5037 * @param setting The name of the setting to update.
5038 * @param value The value to update the setting to.
5039 */
Robin Lee25e26452015-06-02 09:56:29 -07005040 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005041 if (mService != null) {
5042 try {
5043 mService.setGlobalSetting(admin, setting, value);
5044 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005045 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04005046 }
5047 }
5048 }
5049
5050 /**
5051 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5052 * that the value of the setting is in the correct form for the setting type should be performed
5053 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04005054 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005055 * <ul>
5056 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005057 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005058 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5059 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04005060 * <p>A device owner can additionally update the following settings:
5061 * <ul>
5062 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5063 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5065 * @param setting The name of the setting to update.
5066 * @param value The value to update the setting to.
5067 */
Robin Lee25e26452015-06-02 09:56:29 -07005068 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005069 if (mService != null) {
5070 try {
5071 mService.setSecureSetting(admin, setting, value);
5072 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005073 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04005074 }
5075 }
5076 }
5077
Amith Yamasanif20d6402014-05-24 15:34:37 -07005078 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005079 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07005080 * making permission requests of a local or remote administrator of the user.
5081 * <p/>
5082 * Only a profile owner can designate the restrictions provider.
5083 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005084 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07005085 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07005086 * it removes the restrictions provider previously assigned.
5087 */
Robin Lee25e26452015-06-02 09:56:29 -07005088 public void setRestrictionsProvider(@NonNull ComponentName admin,
5089 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005090 if (mService != null) {
5091 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005092 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005093 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005094 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005095 }
5096 }
5097 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005098
5099 /**
5100 * Called by profile or device owners to set the master volume mute on or off.
5101 *
5102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5103 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
5104 */
Robin Lee25e26452015-06-02 09:56:29 -07005105 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005106 if (mService != null) {
5107 try {
5108 mService.setMasterVolumeMuted(admin, on);
5109 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005110 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04005111 }
5112 }
5113 }
5114
5115 /**
5116 * Called by profile or device owners to check whether the master volume mute is on or off.
5117 *
5118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5119 * @return {@code true} if master volume is muted, {@code false} if it's not.
5120 */
Robin Lee25e26452015-06-02 09:56:29 -07005121 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005122 if (mService != null) {
5123 try {
5124 return mService.isMasterVolumeMuted(admin);
5125 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005126 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04005127 }
5128 }
5129 return false;
5130 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005131
5132 /**
5133 * Called by profile or device owners to change whether a user can uninstall
5134 * a package.
5135 *
5136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5137 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005138 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005139 */
Robin Lee25e26452015-06-02 09:56:29 -07005140 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005141 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005142 if (mService != null) {
5143 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005144 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005145 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005146 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01005147 }
5148 }
5149 }
5150
5151 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005152 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005153 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005154 * <p>
5155 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07005156 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00005157 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07005158 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005159 *
Robin Lee25e26452015-06-02 09:56:29 -07005160 * @param admin The name of the admin component whose blocking policy will be checked, or
5161 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005162 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005163 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01005164 */
Robin Lee25e26452015-06-02 09:56:29 -07005165 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005166 if (mService != null) {
5167 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005168 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005169 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005170 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01005171 }
5172 }
5173 return false;
5174 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005175
5176 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005177 * Called by the profile owner of a managed profile to enable widget providers from a
5178 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07005179 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005180 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07005181 * a package may have zero or more provider components, where each component
5182 * provides a different widget type.
5183 * <p>
5184 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005185 *
5186 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5187 * @param packageName The package from which widget providers are white-listed.
5188 * @return Whether the package was added.
5189 *
5190 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5191 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5192 */
Robin Lee25e26452015-06-02 09:56:29 -07005193 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005194 if (mService != null) {
5195 try {
5196 return mService.addCrossProfileWidgetProvider(admin, packageName);
5197 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005198 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005199 }
5200 }
5201 return false;
5202 }
5203
5204 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005205 * Called by the profile owner of a managed profile to disable widget providers from a given
5206 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07005207 * package should have been added via {@link #addCrossProfileWidgetProvider(
5208 * android.content.ComponentName, String)}.
5209 * <p>
5210 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005211 *
5212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5213 * @param packageName The package from which widget providers are no longer
5214 * white-listed.
5215 * @return Whether the package was removed.
5216 *
5217 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5218 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5219 */
Esteban Talavera62399912016-01-11 15:37:55 +00005220 public boolean removeCrossProfileWidgetProvider(
5221 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005222 if (mService != null) {
5223 try {
5224 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5225 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005226 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005227 }
5228 }
5229 return false;
5230 }
5231
5232 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005233 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005234 * available in the parent profile.
5235 *
5236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5237 * @return The white-listed package list.
5238 *
5239 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5240 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5241 */
Robin Lee25e26452015-06-02 09:56:29 -07005242 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005243 if (mService != null) {
5244 try {
5245 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5246 if (providers != null) {
5247 return providers;
5248 }
5249 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005250 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005251 }
5252 }
5253 return Collections.emptyList();
5254 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005255
5256 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005257 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005258 *
5259 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5260 * @param icon the bitmap to set as the photo.
5261 */
Robin Lee25e26452015-06-02 09:56:29 -07005262 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005263 try {
5264 mService.setUserIcon(admin, icon);
5265 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005266 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005267 }
5268 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005269
5270 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005271 * Called by device owners to set a local system update policy. When a new policy is set,
5272 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005273 *
Robin Lee25e26452015-06-02 09:56:29 -07005274 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5275 * components in the device owner package can set system update policies and the
5276 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005277 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005278 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005279 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005280 */
Robin Lee25e26452015-06-02 09:56:29 -07005281 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005282 if (mService != null) {
5283 try {
Robin Lee25e26452015-06-02 09:56:29 -07005284 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005285 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005286 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005287 }
5288 }
5289 }
5290
5291 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005292 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005293 *
Robin Lee25e26452015-06-02 09:56:29 -07005294 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005295 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005296 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005297 if (mService != null) {
5298 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005299 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005300 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005301 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005302 }
5303 }
5304 return null;
5305 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005306
5307 /**
5308 * Called by a device owner to disable the keyguard altogether.
5309 *
5310 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5311 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5312 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5313 * being disabled.
5314 *
5315 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005316 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005317 *
5318 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005319 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005320 */
Robin Lee25e26452015-06-02 09:56:29 -07005321 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005322 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005323 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005324 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005325 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01005326 return false;
5327 }
5328 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005329
5330 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005331 * Called by device owner to disable the status bar. Disabling the status bar blocks
5332 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005333 * a single use device.
5334 *
5335 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005336 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5337 *
5338 * @return {@code false} if attempting to disable the status bar failed.
5339 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005340 */
Robin Lee25e26452015-06-02 09:56:29 -07005341 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005342 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005343 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005344 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005345 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01005346 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00005347 }
5348 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005349
5350 /**
5351 * Callable by the system update service to notify device owners about pending updates.
5352 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5353 * permission.
5354 *
5355 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5356 * when the current pending update was first available. -1 if no update is available.
5357 * @hide
5358 */
5359 @SystemApi
5360 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5361 if (mService != null) {
5362 try {
5363 mService.notifyPendingSystemUpdate(updateReceivedTime);
5364 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005365 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01005366 }
5367 }
5368 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005369
5370 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005371 * Called by profile or device owners to set the default response for future runtime permission
5372 * requests by applications. The policy can allow for normal operation which prompts the
5373 * user to grant a permission, or can allow automatic granting or denying of runtime
5374 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005375 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5376 * the permission grant state via {@link #setPermissionGrantState}.
5377 *
5378 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005379 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005380 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005381 * @param admin Which profile or device owner this request is associated with.
5382 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5383 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005384 *
5385 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005386 */
Robin Lee25e26452015-06-02 09:56:29 -07005387 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005388 try {
5389 mService.setPermissionPolicy(admin, policy);
5390 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005391 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005392 }
5393 }
5394
5395 /**
5396 * Returns the current runtime permission policy set by the device or profile owner. The
5397 * default is {@link #PERMISSION_POLICY_PROMPT}.
5398 * @param admin Which profile or device owner this request is associated with.
5399 * @return the current policy for future permission requests.
5400 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005401 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005402 try {
5403 return mService.getPermissionPolicy(admin);
5404 } catch (RemoteException re) {
5405 return PERMISSION_POLICY_PROMPT;
5406 }
5407 }
5408
5409 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005410 * Sets the grant state of a runtime permission for a specific application. The state
5411 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5412 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5413 * is denied and the user cannot manage it through the UI, and {@link
5414 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5415 * user cannot manage it through the UI. This might affect all permissions in a
5416 * group that the runtime permission belongs to. This method can only be called
5417 * by a profile or device owner.
5418 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005419 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5420 * revoke the permission. It retains the previous grant, if any.
5421 *
5422 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005423 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005424 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005425 * @param admin Which profile or device owner this request is associated with.
5426 * @param packageName The application to grant or revoke a permission to.
5427 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005428 * @param grantState The permission grant state which is one of {@link
5429 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5430 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5431 * @return whether the permission was successfully granted or revoked.
5432 *
5433 * @see #PERMISSION_GRANT_STATE_DENIED
5434 * @see #PERMISSION_GRANT_STATE_DEFAULT
5435 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005436 */
Robin Lee25e26452015-06-02 09:56:29 -07005437 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005438 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005439 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005440 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005441 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005442 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005443 return false;
5444 }
5445 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005446
5447 /**
5448 * Returns the current grant state of a runtime permission for a specific application.
5449 *
5450 * @param admin Which profile or device owner this request is associated with.
5451 * @param packageName The application to check the grant state for.
5452 * @param permission The permission to check for.
5453 * @return the current grant state specified by device policy. If the profile or device owner
5454 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5455 * This does not indicate whether or not the permission is currently granted for the package.
5456 *
5457 * <p/>If a grant state was set by the profile or device owner, then the return value will
5458 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5459 * which indicates if the permission is currently denied or granted.
5460 *
5461 * @see #setPermissionGrantState(ComponentName, String, String, int)
5462 * @see PackageManager#checkPermission(String, String)
5463 */
Robin Lee25e26452015-06-02 09:56:29 -07005464 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005465 String permission) {
5466 try {
5467 return mService.getPermissionGrantState(admin, packageName, permission);
5468 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005469 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005470 return PERMISSION_GRANT_STATE_DEFAULT;
5471 }
5472 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005473
5474 /**
5475 * Returns if provisioning a managed profile or device is possible or not.
5476 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5477 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5478 * Note that even if this method returns true, there is a slight possibility that the
5479 * provisioning will not be allowed when it is actually initiated because some event has
5480 * happened in between.
5481 * @return if provisioning a managed profile or device is possible or not.
5482 * @throws IllegalArgumentException if the supplied action is not valid.
5483 */
5484 public boolean isProvisioningAllowed(String action) {
5485 try {
5486 return mService.isProvisioningAllowed(action);
5487 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005488 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005489 return false;
5490 }
5491 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005492
5493 /**
5494 * @hide
5495 * Return if this user is a managed profile of another user. An admin can become the profile
5496 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5497 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5498 * @param admin Which profile owner this request is associated with.
5499 * @return if this user is a managed profile of another user.
5500 */
5501 public boolean isManagedProfile(@NonNull ComponentName admin) {
5502 try {
5503 return mService.isManagedProfile(admin);
5504 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005505 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005506 return false;
5507 }
5508 }
5509
5510 /**
5511 * @hide
5512 * Return if this user is a system-only user. An admin can manage a device from a system only
5513 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5514 * @param admin Which device owner this request is associated with.
5515 * @return if this user is a system-only user.
5516 */
5517 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5518 try {
5519 return mService.isSystemOnlyUser(admin);
5520 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005521 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005522 return false;
5523 }
5524 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005525
5526 /**
5527 * Called by device owner to get the MAC address of the Wi-Fi device.
5528 *
5529 * @return the MAC address of the Wi-Fi device, or null when the information is not
5530 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5531 *
5532 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5533 */
5534 public String getWifiMacAddress() {
5535 try {
5536 return mService.getWifiMacAddress();
5537 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005538 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005539 return null;
5540 }
5541 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005542
5543 /**
5544 * Called by device owner to reboot the device.
5545 */
5546 public void reboot(@NonNull ComponentName admin) {
5547 try {
5548 mService.reboot(admin);
5549 } catch (RemoteException re) {
5550 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5551 }
5552 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005553
5554 /**
5555 * Called by a device admin to set the short support message. This will
5556 * be displayed to the user in settings screens where funtionality has
5557 * been disabled by the admin.
5558 *
5559 * The message should be limited to a short statement such as
5560 * "This setting is disabled by your administrator. Contact someone@example.com
5561 * for support."
5562 * If the message is longer than 200 characters it may be truncated.
5563 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005564 * <p>If the short support message needs to be localized, it is the responsibility of the
5565 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5566 * and set a new version of this string accordingly.
5567 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005568 * @see #setLongSupportMessage
5569 *
5570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5571 * @param message Short message to be displayed to the user in settings or null to
5572 * clear the existing message.
5573 */
5574 public void setShortSupportMessage(@NonNull ComponentName admin,
5575 @Nullable String message) {
5576 if (mService != null) {
5577 try {
5578 mService.setShortSupportMessage(admin, message);
5579 } catch (RemoteException e) {
5580 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5581 }
5582 }
5583 }
5584
5585 /**
5586 * Called by a device admin to get the short support message.
5587 *
5588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5589 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5590 * or null if no message has been set.
5591 */
5592 public String getShortSupportMessage(@NonNull ComponentName admin) {
5593 if (mService != null) {
5594 try {
5595 return mService.getShortSupportMessage(admin);
5596 } catch (RemoteException e) {
5597 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5598 }
5599 }
5600 return null;
5601 }
5602
5603 /**
5604 * Called by a device admin to set the long support message. This will
5605 * be displayed to the user in the device administators settings screen.
5606 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005607 * <p>If the long support message needs to be localized, it is the responsibility of the
5608 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5609 * and set a new version of this string accordingly.
5610 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005611 * @see #setShortSupportMessage
5612 *
5613 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5614 * @param message Long message to be displayed to the user in settings or null to
5615 * clear the existing message.
5616 */
5617 public void setLongSupportMessage(@NonNull ComponentName admin,
5618 @Nullable String message) {
5619 if (mService != null) {
5620 try {
5621 mService.setLongSupportMessage(admin, message);
5622 } catch (RemoteException e) {
5623 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5624 }
5625 }
5626 }
5627
5628 /**
5629 * Called by a device admin to get the long support message.
5630 *
5631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5632 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5633 * or null if no message has been set.
5634 */
5635 public String getLongSupportMessage(@NonNull ComponentName admin) {
5636 if (mService != null) {
5637 try {
5638 return mService.getLongSupportMessage(admin);
5639 } catch (RemoteException e) {
5640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5641 }
5642 }
5643 return null;
5644 }
5645
5646 /**
5647 * Called by the system to get the short support message.
5648 *
5649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5650 * @param userHandle user id the admin is running as.
5651 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5652 *
5653 * @hide
5654 */
5655 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5656 if (mService != null) {
5657 try {
5658 return mService.getShortSupportMessageForUser(admin, userHandle);
5659 } catch (RemoteException e) {
5660 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5661 }
5662 }
5663 return null;
5664 }
5665
5666
5667 /**
5668 * Called by the system to get the long support message.
5669 *
5670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5671 * @param userHandle user id the admin is running as.
5672 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5673 *
5674 * @hide
5675 */
5676 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5677 if (mService != null) {
5678 try {
5679 return mService.getLongSupportMessageForUser(admin, userHandle);
5680 } catch (RemoteException e) {
5681 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5682 }
5683 }
5684 return null;
5685 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005686
5687 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005688 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5689 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005690 *
5691 * <p> Note only some methods will work on the parent Manager.
5692 *
5693 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5694 */
5695 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5696 try {
5697 if (!mService.isManagedProfile(admin)) {
5698 throw new SecurityException("The current user does not have a parent profile.");
5699 }
5700 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005701 } catch (RemoteException e) {
5702 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5703 return null;
5704 }
5705 }
5706
5707 /**
5708 * Called by device owner to control the device logging feature. Logging can only be
5709 * enabled on single user devices where the sole user is managed by the device owner.
5710 *
5711 * <p> Device logs contain various information intended for security auditing purposes.
5712 * See {@link SecurityEvent} for details.
5713 *
5714 * @param admin Which device owner this request is associated with.
5715 * @param enabled whether device logging should be enabled or not.
5716 * @see #retrieveDeviceLogs
5717 */
5718 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5719 try {
5720 mService.setDeviceLoggingEnabled(admin, enabled);
5721 } catch (RemoteException re) {
5722 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5723 }
5724 }
5725
5726 /**
5727 * Return whether device logging is enabled or not by the device owner.
5728 *
5729 * @param admin Which device owner this request is associated with.
5730 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5731 */
5732 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5733 try {
5734 return mService.getDeviceLoggingEnabled(admin);
5735 } catch (RemoteException re) {
5736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5737 return false;
5738 }
5739 }
5740
5741 /**
5742 * Called by device owner to retrieve all new device logging entries since the last call to
5743 * this API after device boots.
5744 *
5745 * <p> Access to the logs is rate limited and it will only return new logs after the device
5746 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5747 *
5748 * @param admin Which device owner this request is associated with.
5749 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5750 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5751 */
5752 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5753 try {
5754 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5755 if (list != null) {
5756 return list.getList();
5757 } else {
5758 // Rate limit exceeded.
5759 return null;
5760 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005761 } catch (RemoteException re) {
5762 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5763 return null;
5764 }
5765 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005766
5767 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005768 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5769 * profile.
5770 *
5771 * @hide
5772 */
5773 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5774 mContext.checkSelfPermission(
5775 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5776 if (!uInfo.isManagedProfile()) {
5777 throw new SecurityException("The user " + uInfo.id
5778 + " does not have a parent profile.");
5779 }
5780 return new DevicePolicyManager(mContext, true);
5781 }
5782
5783 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005784 * Called by device owners to retrieve device logs from before the device's last reboot.
5785 *
5786 * <p>
5787 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5788 * corruption-free during power cycles, due to hardware variations and limitations. As a
5789 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5790 * </strong>
5791 *
5792 * @param admin Which device owner this request is associated with.
5793 * @return Device logs from before the latest reboot of the system.
5794 */
5795 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5796 try {
5797 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5798 return list.getList();
5799 } catch (RemoteException re) {
5800 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5801 return Collections.<SecurityEvent>emptyList();
5802 }
5803 }
5804
5805 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005806 * Called by a profile owner of a managed profile to set the color used for customization.
5807 * This color is used as background color of the confirm credentials screen for that user.
5808 * The default color is {@link android.graphics.Color#GRAY}.
5809 *
5810 * <p>The confirm credentials screen can be created using
5811 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5812 *
5813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5814 * @param color The 32bit representation of the color to be used.
5815 */
5816 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5817 try {
5818 mService.setOrganizationColor(admin, color);
5819 } catch (RemoteException re) {
5820 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5821 }
5822 }
5823
5824 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005825 * @hide
5826 *
5827 * Sets the color used for customization.
5828 *
5829 * @param color The 32bit representation of the color to be used.
5830 * @param userId which user to set the color to.
5831 * @RequiresPermission(allOf = {
5832 * Manifest.permission.MANAGE_USERS,
5833 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5834 */
5835 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5836 try {
5837 mService.setOrganizationColorForUser(color, userId);
5838 } catch (RemoteException re) {
5839 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5840 }
5841 }
5842
5843 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005844 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5845 * This color is used as background color of the confirm credentials screen for that user.
5846 *
5847 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5848 * @return The 32bit representation of the color to be used.
5849 */
5850 public int getOrganizationColor(@NonNull ComponentName admin) {
5851 try {
5852 return mService.getOrganizationColor(admin);
5853 } catch (RemoteException re) {
5854 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5855 return 0;
5856 }
5857 }
5858
5859 /**
5860 * @hide
5861 * Retrieve the customization color for a given user.
5862 *
5863 * @param userHandle The user id of the user we're interested in.
5864 * @return The 32bit representation of the color to be used.
5865 */
5866 public int getOrganizationColorForUser(int userHandle) {
5867 try {
5868 return mService.getOrganizationColorForUser(userHandle);
5869 } catch (RemoteException re) {
5870 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5871 return 0;
5872 }
5873 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005874
5875 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005876 * Called by a profile owner of a managed profile to set the name of the organization under
5877 * management.
5878 *
5879 * <p>If the organization name needs to be localized, it is the responsibility of the
5880 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5881 * and set a new version of this string accordingly.
5882 *
5883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5884 * @param title The organization name or {@code null} to clear a previously set name.
5885 */
5886 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5887 try {
5888 mService.setOrganizationName(admin, title);
5889 } catch (RemoteException re) {
5890 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5891 }
5892 }
5893
5894 /**
5895 * Called by a profile owner of a managed profile to retrieve the name of the organization
5896 * under management.
5897 *
5898 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5899 * @return The organization name or {@code null} if none is set.
5900 */
5901 public String getOrganizationName(@NonNull ComponentName admin) {
5902 try {
5903 return mService.getOrganizationName(admin);
5904 } catch (RemoteException re) {
5905 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5906 return null;
5907 }
5908 }
5909
5910 /**
5911 * Retrieve the default title message used in the confirm credentials screen for a given user.
5912 *
5913 * @param userHandle The user id of the user we're interested in.
5914 * @return The organization name or {@code null} if none is set.
5915 *
5916 * @hide
5917 */
5918 public String getOrganizationNameForUser(int userHandle) {
5919 try {
5920 return mService.getOrganizationNameForUser(userHandle);
5921 } catch (RemoteException re) {
5922 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5923 return null;
5924 }
5925 }
5926
5927 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005928 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5929 * return {@link #STATE_USER_UNMANAGED}
5930 * @hide
5931 */
5932 @UserProvisioningState
5933 public int getUserProvisioningState() {
5934 if (mService != null) {
5935 try {
5936 return mService.getUserProvisioningState();
5937 } catch (RemoteException e) {
5938 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5939 }
5940 }
5941 return STATE_USER_UNMANAGED;
5942 }
5943
5944 /**
5945 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5946 *
5947 * @param state to store
5948 * @param userHandle for user
5949 * @hide
5950 */
5951 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5952 if (mService != null) {
5953 try {
5954 mService.setUserProvisioningState(state, userHandle);
5955 } catch (RemoteException e) {
5956 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5957 }
5958 }
5959 }
5960
5961 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005962 * @hide
5963 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5964 * affiliated if it is managed by the same entity as the device.
5965 *
5966 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5967 * user/profile is considered affiliated if the following conditions are both met:
5968 * <ul>
5969 * <li>The device owner and the user's/profile's profile owner have called this method,
5970 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5971 * and a profile owner intersect, they must have come from the same source, which means that
5972 * the device owner and profile owner are controlled by the same entity.</li>
5973 * <li>The device owner's and profile owner's package names are the same.</li>
5974 * </ul>
5975 *
5976 * @param admin Which profile or device owner this request is associated with.
5977 * @param ids A set of opaque affiliation ids.
5978 */
5979 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5980 try {
5981 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5982 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00005983 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005984 }
5985 }
5986
5987 /**
5988 * @hide
5989 * Returns whether this user/profile is affiliated with the device. See
5990 * {@link #setAffiliationIds} for the definition of affiliation.
5991 *
5992 * @return whether this user/profile is affiliated with the device.
5993 */
5994 public boolean isAffiliatedUser() {
5995 try {
5996 return mService != null && mService.isAffiliatedUser();
5997 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00005998 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005999 return false;
6000 }
6001 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006002
6003 /**
6004 * @hide
6005 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6006 * to be started
6007 * @param packageName the package to check for
6008 * @return whether the uninstall intent for {@code packageName} is pending
6009 */
6010 public boolean isUninstallInQueue(String packageName) {
6011 try {
6012 return mService.isUninstallInQueue(packageName);
6013 } catch (RemoteException re) {
6014 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
6015 return false;
6016 }
6017 }
6018
6019 /**
6020 * @hide
6021 * @param packageName the package containing active DAs to be uninstalled
6022 */
6023 public void uninstallPackageWithActiveAdmins(String packageName) {
6024 try {
6025 mService.uninstallPackageWithActiveAdmins(packageName);
6026 } catch (RemoteException re) {
6027 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
6028 }
6029 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006030}