blob: 3657d327010157dad5ddde27d676b7d73f6adebe [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 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000344 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000345 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
346 public static final String ACTION_PROVISION_FINALIZATION
347 = "android.app.action.PROVISION_FINALIZATION";
348
349 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100350 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100351 * allows a mobile device management application or NFC programmer application which starts
352 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100353 * <p>
354 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
355 * sends the intent to pass data to itself on the newly created profile.
356 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
357 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100358 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
359 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
360 * message should contain a stringified {@link java.util.Properties} instance, whose string
361 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
362 * management application after provisioning.
363 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100364 * <p>
365 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700366 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
367 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100368 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100369 */
370 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100371 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100372
373 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100374 * A String extra holding the package name of the mobile device management application that
375 * will be set as the profile owner or device owner.
376 *
377 * <p>If an application starts provisioning directly via an intent with action
378 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
379 * application that started provisioning. The package will be set as profile owner in that case.
380 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000381 * <p>This package is set as device owner when device owner provisioning is started by an NFC
382 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000383 *
384 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700385 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000386
387 * @see DeviceAdminReceiver
388 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100389 * supported, but only if there is only one device admin receiver in the package that requires
390 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000391 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000392 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000393 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100394 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000395
396 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000397 * A ComponentName extra indicating the device admin receiver of the mobile device management
398 * application that will be set as the profile owner or device owner and active admin.
399 *
400 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100401 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
402 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
403 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000404 *
405 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100406 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
407 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400408 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000409 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000410 *
411 * @see DeviceAdminReceiver
412 */
413 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
414 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
415
416 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000417 * An {@link android.accounts.Account} extra holding the account to migrate during managed
418 * profile provisioning. If the account supplied is present in the primary user, it will be
419 * copied, along with its credentials to the managed profile and removed from the primary user.
420 *
421 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
422 */
423
424 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
425 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
426
427 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100428 * A String extra that, holds the email address of the account which a managed profile is
429 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
430 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100431 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100432 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
433 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100434 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
435 * contains this extra, it is forwarded in the
436 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
437 * device management application that was set as the profile owner during provisioning.
438 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100439 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100440 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
441 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100442
443 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000444 * A integer extra indicating the predominant color to show during the provisioning.
445 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000446 *
447 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
448 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
449 */
450 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
451 "android.app.extra.PROVISIONING_MAIN_COLOR";
452
453 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000454 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700455 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000456 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100457 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
458 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000459 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000460 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
461 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000462
463 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100464 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
465 * will be set to.
466 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000467 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
468 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469 */
470 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100471 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100472
473 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100474 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
475 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100476 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000477 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
478 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100479 */
480 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100481 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100482
483 /**
484 * A String extra holding the {@link java.util.Locale} that the device will be set to.
485 * Format: xx_yy, where xx is the language code, and yy the country code.
486 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000487 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
488 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100489 */
490 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100491 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100492
493 /**
494 * A String extra holding the ssid of the wifi network that should be used during nfc device
495 * owner provisioning for downloading the mobile device management application.
496 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
498 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100499 */
500 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100501 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100502
503 /**
504 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
505 * is hidden or not.
506 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000507 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
508 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509 */
510 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100511 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100512
513 /**
514 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100515 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
516 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100517 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000518 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
519 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520 */
521 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100522 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100523
524 /**
525 * A String extra holding the password of the wifi network in
526 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
527 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000528 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
529 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100530 */
531 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100532 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100533
534 /**
535 * A String extra holding the proxy host for the wifi network in
536 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
537 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000538 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
539 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100540 */
541 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100542 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100543
544 /**
545 * An int extra holding the proxy port for the wifi network in
546 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
547 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000548 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
549 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100550 */
551 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100552 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100553
554 /**
555 * A String extra holding the proxy bypass for the wifi network in
556 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
557 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000558 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
559 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100560 */
561 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100562 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100563
564 /**
565 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
566 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
567 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000568 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
569 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570 */
571 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100572 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100573
574 /**
575 * A String extra holding a url that specifies the download location of the device admin
576 * package. When not provided it is assumed that the device admin package is already installed.
577 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000578 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
579 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580 */
581 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100582 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100583
584 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400585 * An int extra holding a minimum required version code for the device admin package. If the
586 * device admin is already installed on the device, it will only be re-downloaded from
587 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
588 * installed package is less than this version code.
589 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400590 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400591 * provisioning via an NFC bump.
592 */
593 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
594 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
595
596 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100597 * A String extra holding a http cookie header which should be used in the http request to the
598 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
599 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000600 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
601 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100602 */
603 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100604 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100605
606 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100607 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
608 * the file at download location specified in
609 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100610 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100611 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100612 * present. The provided checksum should match the checksum of the file at the download
613 * location. If the checksum doesn't match an error will be shown to the user and the user will
614 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100615 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000616 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
617 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100618 *
619 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
620 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700621 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100622 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623 */
624 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100625 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626
627 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100628 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100629 * android package archive at the download location specified in {@link
630 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
631 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100632 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100633 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
634 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
635 *
636 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100637 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100638 * the download location. If the checksum does not match an error will be shown to the user and
639 * the user will be asked to factory reset the device.
640 *
641 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
642 * provisioning via an NFC bump.
643 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100644 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
645 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100646
647 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000648 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
649 * has completed successfully.
650 *
651 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700652 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000653 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800654 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000655 * corresponds to the account requested to be migrated at provisioning time, if any.
656 */
657 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
658 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
659 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
660
661 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400662 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500663 * provisioning.
664 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400665 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100666 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500667 */
668 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
669 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
670
671 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000672 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
673 * provisioning. If this extra is not passed, a default image will be shown.
674 * <h5>The following URI schemes are accepted:</h5>
675 * <ul>
676 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
677 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
678 * </ul>
679 *
680 * <p> It is the responsability of the caller to provide an image with a reasonable
681 * pixed density for the device.
682 *
683 * <p> If a content: URI is passed, the intent should have the flag
684 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
685 * {@link android.content.ClipData} of the intent too.
686 *
687 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
688 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
689 */
690 public static final String EXTRA_PROVISIONING_LOGO_URI =
691 "android.app.extra.PROVISIONING_LOGO_URI";
692
693 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000694 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
695 * during setup-wizard.
696 *
697 * <p>If unspecified, defaults to {@code true} to match the behavior in
698 * {@link android.os.Build.VERSION_CODES#M} and earlier.
699 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000700 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
701 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000702 *
703 * @hide
704 */
705 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
706 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
707
708 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400709 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100710 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400711 * <p>During device owner provisioning a device admin app is set as the owner of the device.
712 * A device owner has full control over the device. The device owner can not be modified by the
713 * user and the only way of resetting the device is if the device owner app calls a factory
714 * reset.
715 *
716 * <p> A typical use case would be a device that is owned by a company, but used by either an
717 * employee or client.
718 *
719 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100720 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000721 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100722 * contains the following properties:
723 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400724 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
725 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100726 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400727 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100728 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
729 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
730 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
731 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
732 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
733 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
734 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
735 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
736 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
737 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100738 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
739 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
740 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100741 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000742 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700743 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400744 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
745 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
746 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400747 */
748 public static final String MIME_TYPE_PROVISIONING_NFC
749 = "application/com.android.managedprovisioning";
750
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100751 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800752 * Activity action: ask the user to add a new device administrator to the system.
753 * The desired policy is the ComponentName of the policy in the
754 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
755 * bring the user through adding the device administrator to the system (or
756 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700757 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800758 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
759 * field to provide the user with additional explanation (in addition
760 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800761 *
762 * <p>If your administrator is already active, this will ordinarily return immediately (without
763 * user intervention). However, if your administrator has been updated and is requesting
764 * additional uses-policy flags, the user will be presented with the new list. New policies
765 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800766 */
767 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
768 public static final String ACTION_ADD_DEVICE_ADMIN
769 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700770
Dianne Hackbornd6847842010-01-12 18:14:19 -0800771 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700772 * @hide
773 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700774 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700775 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700776 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
777 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700778 * to remotely control restrictions on the user.
779 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800780 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700781 * result of whether or not the user approved the action. If approved, the result will
782 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
783 * as a profile owner.
784 *
785 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
786 * field to provide the user with additional explanation (in addition
787 * to your component's description) about what is being added.
788 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700789 * <p>If there is already a profile owner active or the caller is not a system app, the
790 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700791 */
792 @SystemApi
793 public static final String ACTION_SET_PROFILE_OWNER
794 = "android.app.action.SET_PROFILE_OWNER";
795
796 /**
797 * @hide
798 * Name of the profile owner admin that controls the user.
799 */
800 @SystemApi
801 public static final String EXTRA_PROFILE_OWNER_NAME
802 = "android.app.extra.PROFILE_OWNER_NAME";
803
804 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100805 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700806 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700807 *
Jim Miller284b62e2010-06-08 14:27:42 -0700808 * @hide
809 */
810 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
811 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
812
813 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100814 * Broadcast action: sent when the device owner is set or changed.
815 *
816 * This broadcast is sent only to the primary user.
817 * @see #ACTION_PROVISION_MANAGED_DEVICE
818 */
819 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
820 public static final String ACTION_DEVICE_OWNER_CHANGED
821 = "android.app.action.DEVICE_OWNER_CHANGED";
822
823 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 * The ComponentName of the administrator component.
825 *
826 * @see #ACTION_ADD_DEVICE_ADMIN
827 */
828 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700829
Dianne Hackbornd6847842010-01-12 18:14:19 -0800830 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800831 * An optional CharSequence providing additional explanation for why the
832 * admin is being added.
833 *
834 * @see #ACTION_ADD_DEVICE_ADMIN
835 */
836 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700837
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800838 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700839 * Activity action: have the user enter a new password. This activity should
840 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
841 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
842 * enter a new password that meets the current requirements. You can use
843 * {@link #isActivePasswordSufficient()} to determine whether you need to
844 * have the user select a new password in order to meet the current
845 * constraints. Upon being resumed from this activity, you can check the new
846 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000847 *
848 * If the intent is launched from within a managed profile with a profile
849 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
850 * this will trigger entering a new password for the parent of the profile.
851 * For all other cases it will trigger entering a new password for the user
852 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000853 *
854 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800855 */
856 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
857 public static final String ACTION_SET_NEW_PASSWORD
858 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700859
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000860 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000861 * Activity action: have the user enter a new password for the parent profile.
862 * If the intent is launched from within a managed profile, this will trigger
863 * entering a new password for the parent of the profile. In all other cases
864 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
865 */
866 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
867 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
868 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
869
870 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000871 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
872 * the parent profile to access intents sent from the managed profile.
873 * That is, when an app in the managed profile calls
874 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
875 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000876 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100877 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000878
879 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000880 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
881 * the managed profile to access intents sent from the parent profile.
882 * That is, when an app in the parent profile calls
883 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
884 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000885 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100886 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700887
Dianne Hackbornd6847842010-01-12 18:14:19 -0800888 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100889 * Broadcast action: notify that a new local system update policy has been set by the device
890 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000891 */
892 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100893 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
894 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000895
Amith Yamasanid49489b2015-04-28 14:00:26 -0700896 /**
897 * Permission policy to prompt user for new permission requests for runtime permissions.
898 * Already granted or denied permissions are not affected by this.
899 */
900 public static final int PERMISSION_POLICY_PROMPT = 0;
901
902 /**
903 * Permission policy to always grant new permission requests for runtime permissions.
904 * Already granted or denied permissions are not affected by this.
905 */
906 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
907
908 /**
909 * Permission policy to always deny new permission requests for runtime permissions.
910 * Already granted or denied permissions are not affected by this.
911 */
912 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
913
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700914 /**
915 * Runtime permission state: The user can manage the permission
916 * through the UI.
917 */
918 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
919
920 /**
921 * Runtime permission state: The permission is granted to the app
922 * and the user cannot manage the permission through the UI.
923 */
924 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
925
926 /**
927 * Runtime permission state: The permission is denied to the app
928 * and the user cannot manage the permission through the UI.
929 */
930 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000931
932 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000933 * No management for current user in-effect. This is the default.
934 * @hide
935 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000936 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000937 public static final int STATE_USER_UNMANAGED = 0;
938
939 /**
940 * Management partially setup, user setup needs to be completed.
941 * @hide
942 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000943 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000944 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
945
946 /**
947 * Management partially setup, user setup completed.
948 * @hide
949 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000950 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000951 public static final int STATE_USER_SETUP_COMPLETE = 2;
952
953 /**
954 * Management setup and active on current user.
955 * @hide
956 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000957 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000958 public static final int STATE_USER_SETUP_FINALIZED = 3;
959
960 /**
961 * Management partially setup on a managed profile.
962 * @hide
963 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000964 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000965 public static final int STATE_USER_PROFILE_COMPLETE = 4;
966
967 /**
968 * @hide
969 */
970 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
971 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
972 @Retention(RetentionPolicy.SOURCE)
973 public @interface UserProvisioningState {}
974
975 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800976 * Return true if the given administrator component is currently
977 * active (enabled) in the system.
978 */
Robin Lee25e26452015-06-02 09:56:29 -0700979 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700980 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100981 }
982
983 /**
984 * @see #isAdminActive(ComponentName)
985 * @hide
986 */
Robin Lee25e26452015-06-02 09:56:29 -0700987 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800988 if (mService != null) {
989 try {
Robin Lee25e26452015-06-02 09:56:29 -0700990 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800991 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800992 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800993 }
994 }
995 return false;
996 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800997 /**
998 * Return true if the given administrator component is currently being removed
999 * for the user.
1000 * @hide
1001 */
Robin Lee25e26452015-06-02 09:56:29 -07001002 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001003 if (mService != null) {
1004 try {
Robin Lee25e26452015-06-02 09:56:29 -07001005 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001006 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001007 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001008 }
1009 }
1010 return false;
1011 }
1012
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001013
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 /**
Robin Lee25e26452015-06-02 09:56:29 -07001015 * Return a list of all currently active device administrators' component
1016 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001017 * returned.
1018 */
1019 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001020 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001021 }
1022
1023 /**
1024 * @see #getActiveAdmins()
1025 * @hide
1026 */
1027 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001028 if (mService != null) {
1029 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001030 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001031 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001032 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001033 }
1034 }
1035 return null;
1036 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001038 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001039 * Used by package administration code to determine if a package can be stopped
1040 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001041 * @hide
1042 */
1043 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001044 return packageHasActiveAdmins(packageName, myUserId());
1045 }
1046
1047 /**
1048 * Used by package administration code to determine if a package can be stopped
1049 * or uninstalled.
1050 * @hide
1051 */
1052 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001053 if (mService != null) {
1054 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001055 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001056 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001057 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001058 }
1059 }
1060 return false;
1061 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001062
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001063 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001064 * Remove a current administration component. This can only be called
1065 * by the application that owns the administration component; if you
1066 * try to remove someone else's component, a security exception will be
1067 * thrown.
1068 */
Robin Lee25e26452015-06-02 09:56:29 -07001069 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001070 if (mService != null) {
1071 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001072 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001074 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001075 }
1076 }
1077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001080 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001081 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001082 * but requires additional policies after an upgrade.
1083 *
1084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1085 * an active administrator, or an exception will be thrown.
1086 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1087 */
Robin Lee25e26452015-06-02 09:56:29 -07001088 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001089 if (mService != null) {
1090 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001091 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001092 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001093 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001094 }
1095 }
1096 return false;
1097 }
1098
1099 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001100 * Returns true if the Profile Challenge is available to use for the given profile user.
1101 *
1102 * @hide
1103 */
1104 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1105 if (mService != null) {
1106 try {
1107 return mService.isSeparateProfileChallengeAllowed(userHandle);
1108 } catch (RemoteException e) {
1109 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1110 }
1111 }
1112 return false;
1113 }
1114
1115 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001116 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1117 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001118 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001119 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001120 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001121
Dianne Hackbornd6847842010-01-12 18:14:19 -08001122 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001123 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1124 * recognition technology. This implies technologies that can recognize the identity of
1125 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1126 * Note that quality constants are ordered so that higher values are more restrictive.
1127 */
1128 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1129
1130 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001131 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001132 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001133 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001134 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001135 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001136
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001137 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001138 * Constant for {@link #setPasswordQuality}: the user must have entered a
1139 * password containing at least numeric characters. Note that quality
1140 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001141 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001142 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001143
Dianne Hackbornd6847842010-01-12 18:14:19 -08001144 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001145 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001146 * password containing at least numeric characters with no repeating (4444)
1147 * or ordered (1234, 4321, 2468) sequences. Note that quality
1148 * constants are ordered so that higher values are more restrictive.
1149 */
1150 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1151
1152 /**
1153 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001154 * password containing at least alphabetic (or other symbol) characters.
1155 * Note that quality constants are ordered so that higher values are more
1156 * restrictive.
1157 */
1158 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001160 /**
1161 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001162 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001163 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001164 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001165 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001166 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001167
Dianne Hackbornd6847842010-01-12 18:14:19 -08001168 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001170 * password containing at least a letter, a numerical digit and a special
1171 * symbol, by default. With this password quality, passwords can be
1172 * restricted to contain various sets of characters, like at least an
1173 * uppercase letter, etc. These are specified using various methods,
1174 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1175 * that quality constants are ordered so that higher values are more
1176 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001177 */
1178 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1179
1180 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001181 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1182 * modify password. In case this password quality is set, the password is
1183 * managed by a profile owner. The profile owner can set any password,
1184 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1185 * that quality constants are ordered so that higher values are more
1186 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1187 * the highest.
1188 * @hide
1189 */
1190 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1191
1192 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001193 * Called by an application that is administering the device to set the
1194 * password restrictions it is imposing. After setting this, the user
1195 * will not be able to enter a new password that is not at least as
1196 * restrictive as what has been set. Note that the current password
1197 * will remain until the user has set a new one, so the change does not
1198 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001199 * {@link #ACTION_SET_NEW_PASSWORD} or
1200 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001201 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001202 * <p>Quality constants are ordered so that higher values are more restrictive;
1203 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001204 * the user's preference, and any other considerations) is the one that
1205 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001206 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001207 * <p>The calling device admin must have requested
1208 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1209 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001210 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001211 * <p>This method can be called on the {@link DevicePolicyManager} instance
1212 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1213 * restrictions on the parent profile.
1214 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001216 * @param quality The new desired quality. One of
1217 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001218 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1219 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1220 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001221 */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001223 if (mService != null) {
1224 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001225 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001226 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001227 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001228 }
1229 }
1230 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001231
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001233 * Retrieve the current minimum password quality for a particular admin or all admins that set
1234 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1235 * a separate challenge are not taken into account.
1236 *
1237 * <p>This method can be called on the {@link DevicePolicyManager} instance
1238 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1239 * restrictions on the parent profile.
1240 *
Robin Lee25e26452015-06-02 09:56:29 -07001241 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001242 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001243 */
Robin Lee25e26452015-06-02 09:56:29 -07001244 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001245 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001246 }
1247
1248 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001249 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 if (mService != null) {
1251 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001252 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001253 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001254 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 }
1256 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001257 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001258 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001259
Dianne Hackbornd6847842010-01-12 18:14:19 -08001260 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001261 * Called by an application that is administering the device to set the
1262 * minimum allowed password length. After setting this, the user
1263 * will not be able to enter a new password that is not at least as
1264 * restrictive as what has been set. Note that the current password
1265 * will remain until the user has set a new one, so the change does not
1266 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001267 * {@link #ACTION_SET_NEW_PASSWORD} or
1268 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Dianne Hackbornd6847842010-01-12 18:14:19 -08001269 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001270 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1271 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1272 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001273 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001274 * <p>The calling device admin must have requested
1275 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1276 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001277 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001278 * <p>This method can be called on the {@link DevicePolicyManager} instance
1279 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1280 * restrictions on the parent profile.
1281 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001283 * @param length The new desired minimum password length. A value of 0
1284 * means there is no restriction.
1285 */
Robin Lee25e26452015-06-02 09:56:29 -07001286 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001287 if (mService != null) {
1288 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001289 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001291 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001292 }
1293 }
1294 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001295
Dianne Hackbornd6847842010-01-12 18:14:19 -08001296 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001297 * Retrieve the current minimum password length for a particular admin or all admins that set
1298 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1299 * a separate challenge are not taken into account.
1300 *
1301 * <p>This method can be called on the {@link DevicePolicyManager} instance
1302 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1303 * restrictions on the parent profile.
1304 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001305 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001306 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001307 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001308 */
Robin Lee25e26452015-06-02 09:56:29 -07001309 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001310 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001311 }
1312
1313 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001314 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001315 if (mService != null) {
1316 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001317 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001318 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001319 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001320 }
1321 }
1322 return 0;
1323 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001324
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 /**
1326 * Called by an application that is administering the device to set the
1327 * minimum number of upper case letters required in the password. After
1328 * setting this, the user will not be able to enter a new password that is
1329 * not at least as restrictive as what has been set. Note that the current
1330 * password will remain until the user has set a new one, so the change does
1331 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001332 * {@link #ACTION_SET_NEW_PASSWORD} or
1333 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001334 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001335 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1336 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001337 * <p>
1338 * The calling device admin must have requested
1339 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1340 * this method; if it has not, a security exception will be thrown.
1341 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001342 * <p>This method can be called on the {@link DevicePolicyManager} instance
1343 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1344 * restrictions on the parent profile.
1345 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001346 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1347 * with.
1348 * @param length The new desired minimum number of upper case letters
1349 * required in the password. A value of 0 means there is no
1350 * restriction.
1351 */
Robin Lee25e26452015-06-02 09:56:29 -07001352 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001353 if (mService != null) {
1354 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001355 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001356 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001357 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001358 }
1359 }
1360 }
1361
1362 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001363 * Retrieve the current number of upper case letters required in the password
1364 * for a particular admin or all admins that set retrictions on this user and
1365 * its participating profiles. Restrictions on profiles that have a separate challenge
1366 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001367 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001368 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001369 * and only applies when the password quality is
1370 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001371 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001372 * <p>This method can be called on the {@link DevicePolicyManager} instance
1373 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1374 * restrictions on the parent profile.
1375 *
Robin Lee25e26452015-06-02 09:56:29 -07001376 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001377 * aggregate all admins.
1378 * @return The minimum number of upper case letters required in the
1379 * password.
1380 */
Robin Lee25e26452015-06-02 09:56:29 -07001381 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001382 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001383 }
1384
1385 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001386 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 if (mService != null) {
1388 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001389 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001390 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001391 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001392 }
1393 }
1394 return 0;
1395 }
1396
1397 /**
1398 * Called by an application that is administering the device to set the
1399 * minimum number of lower case letters required in the password. After
1400 * setting this, the user will not be able to enter a new password that is
1401 * not at least as restrictive as what has been set. Note that the current
1402 * password will remain until the user has set a new one, so the change does
1403 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001404 * {@link #ACTION_SET_NEW_PASSWORD} or
1405 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001406 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001407 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1408 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001409 * <p>
1410 * The calling device admin must have requested
1411 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1412 * this method; if it has not, a security exception will be thrown.
1413 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001414 * <p>This method can be called on the {@link DevicePolicyManager} instance
1415 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1416 * restrictions on the parent profile.
1417 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001418 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1419 * with.
1420 * @param length The new desired minimum number of lower case letters
1421 * required in the password. A value of 0 means there is no
1422 * restriction.
1423 */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001425 if (mService != null) {
1426 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001427 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001428 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001429 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001430 }
1431 }
1432 }
1433
1434 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001435 * Retrieve the current number of lower case letters required in the password
1436 * for a particular admin or all admins that set retrictions on this user
1437 * and its participating profiles. Restrictions on profiles that have
1438 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001439 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001440 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001441 * and only applies when the password quality is
1442 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001444 * <p>This method can be called on the {@link DevicePolicyManager} instance
1445 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1446 * restrictions on the parent profile.
1447 *
Robin Lee25e26452015-06-02 09:56:29 -07001448 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001449 * aggregate all admins.
1450 * @return The minimum number of lower case letters required in the
1451 * password.
1452 */
Robin Lee25e26452015-06-02 09:56:29 -07001453 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001454 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001455 }
1456
1457 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001458 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001459 if (mService != null) {
1460 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001461 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001462 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001463 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001464 }
1465 }
1466 return 0;
1467 }
1468
1469 /**
1470 * Called by an application that is administering the device to set the
1471 * minimum number of letters required in the password. After setting this,
1472 * the user will not be able to enter a new password that is not at least as
1473 * restrictive as what has been set. Note that the current password will
1474 * remain until the user has set a new one, so the change does not take
1475 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001476 * {@link #ACTION_SET_NEW_PASSWORD} or
1477 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001478 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001479 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1480 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001481 * <p>
1482 * The calling device admin must have requested
1483 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1484 * this method; if it has not, a security exception will be thrown.
1485 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001486 * <p>This method can be called on the {@link DevicePolicyManager} instance
1487 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1488 * restrictions on the parent profile.
1489 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1491 * with.
1492 * @param length The new desired minimum number of letters required in the
1493 * password. A value of 0 means there is no restriction.
1494 */
Robin Lee25e26452015-06-02 09:56:29 -07001495 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001496 if (mService != null) {
1497 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001498 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001499 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001500 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 }
1502 }
1503 }
1504
1505 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001506 * Retrieve the current number of letters required in the password
1507 * for a particular admin or all admins that set retrictions on this user
1508 * and its participating profiles. Restrictions on profiles that have
1509 * a separate challenge are not taken into account.
1510 * This is the same value as set by
1511 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001512 * and only applies when the password quality is
1513 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001514 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001515 * <p>This method can be called on the {@link DevicePolicyManager} instance
1516 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1517 * restrictions on the parent profile.
1518 *
Robin Lee25e26452015-06-02 09:56:29 -07001519 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001520 * aggregate all admins.
1521 * @return The minimum number of letters required in the password.
1522 */
Robin Lee25e26452015-06-02 09:56:29 -07001523 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001524 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001525 }
1526
1527 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001528 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001529 if (mService != null) {
1530 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001531 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001532 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001533 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001534 }
1535 }
1536 return 0;
1537 }
1538
1539 /**
1540 * Called by an application that is administering the device to set the
1541 * minimum number of numerical digits required in the password. After
1542 * setting this, the user will not be able to enter a new password that is
1543 * not at least as restrictive as what has been set. Note that the current
1544 * password will remain until the user has set a new one, so the change does
1545 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001546 * {@link #ACTION_SET_NEW_PASSWORD} or
1547 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001548 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001549 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1550 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001551 * <p>
1552 * The calling device admin must have requested
1553 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1554 * this method; if it has not, a security exception will be thrown.
1555 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001556 * <p>This method can be called on the {@link DevicePolicyManager} instance
1557 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1558 * restrictions on the parent profile.
1559 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001560 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1561 * with.
1562 * @param length The new desired minimum number of numerical digits required
1563 * in the password. A value of 0 means there is no restriction.
1564 */
Robin Lee25e26452015-06-02 09:56:29 -07001565 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001566 if (mService != null) {
1567 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001568 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001569 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001570 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001571 }
1572 }
1573 }
1574
1575 /**
1576 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001577 * for a particular admin or all admins that set retrictions on this user
1578 * and its participating profiles. Restrictions on profiles that have
1579 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001580 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001581 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001582 * and only applies when the password quality is
1583 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001584 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001585 * <p>This method can be called on the {@link DevicePolicyManager} instance
1586 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1587 * restrictions on the parent profile.
1588 *
Robin Lee25e26452015-06-02 09:56:29 -07001589 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001590 * aggregate all admins.
1591 * @return The minimum number of numerical digits required in the password.
1592 */
Robin Lee25e26452015-06-02 09:56:29 -07001593 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001594 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001595 }
1596
1597 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001598 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001599 if (mService != null) {
1600 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001601 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001602 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001603 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001604 }
1605 }
1606 return 0;
1607 }
1608
1609 /**
1610 * Called by an application that is administering the device to set the
1611 * minimum number of symbols required in the password. After setting this,
1612 * the user will not be able to enter a new password that is not at least as
1613 * restrictive as what has been set. Note that the current password will
1614 * remain until the user has set a new one, so the change does not take
1615 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001616 * {@link #ACTION_SET_NEW_PASSWORD} or
1617 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001618 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001619 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1620 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001621 * <p>
1622 * The calling device admin must have requested
1623 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1624 * this method; if it has not, a security exception will be thrown.
1625 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001626 * <p>This method can be called on the {@link DevicePolicyManager} instance
1627 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1628 * restrictions on the parent profile.
1629 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001630 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1631 * with.
1632 * @param length The new desired minimum number of symbols required in the
1633 * password. A value of 0 means there is no restriction.
1634 */
Robin Lee25e26452015-06-02 09:56:29 -07001635 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001636 if (mService != null) {
1637 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001638 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001639 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001641 }
1642 }
1643 }
1644
1645 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001646 * Retrieve the current number of symbols required in the password
1647 * for a particular admin or all admins that set retrictions on this user
1648 * and its participating profiles. Restrictions on profiles that have
1649 * a separate challenge are not taken into account. This is the same value as
1650 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001651 * and only applies when the password quality is
1652 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001653 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001654 * <p>This method can be called on the {@link DevicePolicyManager} instance
1655 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1656 * restrictions on the parent profile.
1657 *
Robin Lee25e26452015-06-02 09:56:29 -07001658 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001659 * aggregate all admins.
1660 * @return The minimum number of symbols required in the password.
1661 */
Robin Lee25e26452015-06-02 09:56:29 -07001662 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001663 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001664 }
1665
1666 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001667 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001668 if (mService != null) {
1669 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001670 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001671 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001672 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001673 }
1674 }
1675 return 0;
1676 }
1677
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001678 /**
1679 * Called by an application that is administering the device to set the
1680 * minimum number of non-letter characters (numerical digits or symbols)
1681 * required in the password. After setting this, the user will not be able
1682 * to enter a new password that is not at least as restrictive as what has
1683 * been set. Note that the current password will remain until the user has
1684 * set a new one, so the change does not take place immediately. To prompt
Esteban Talaverac1c83592016-02-17 17:56:15 +00001685 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1686 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001687 * setting this value. This constraint is only imposed if the administrator
1688 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1689 * {@link #setPasswordQuality}. The default value is 0.
1690 * <p>
1691 * The calling device admin must have requested
1692 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1693 * this method; if it has not, a security exception will be thrown.
1694 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001695 * <p>This method can be called on the {@link DevicePolicyManager} instance
1696 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1697 * restrictions on the parent profile.
1698 *
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001699 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1700 * with.
1701 * @param length The new desired minimum number of letters required in the
1702 * password. A value of 0 means there is no restriction.
1703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001705 if (mService != null) {
1706 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001707 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001708 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001709 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001710 }
1711 }
1712 }
1713
1714 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001715 * Retrieve the current number of non-letter characters required in the password
1716 * for a particular admin or all admins that set retrictions on this user
1717 * and its participating profiles. Restrictions on profiles that have
1718 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001719 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001720 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001721 * and only applies when the password quality is
1722 * {@link #PASSWORD_QUALITY_COMPLEX}.
1723 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001724 * <p>This method can be called on the {@link DevicePolicyManager} instance
1725 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1726 * restrictions on the parent profile.
1727 *
Robin Lee25e26452015-06-02 09:56:29 -07001728 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001729 * aggregate all admins.
1730 * @return The minimum number of letters required in the password.
1731 */
Robin Lee25e26452015-06-02 09:56:29 -07001732 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001733 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001734 }
1735
1736 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001737 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001738 if (mService != null) {
1739 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001740 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001741 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001742 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001743 }
1744 }
1745 return 0;
1746 }
1747
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001748 /**
1749 * Called by an application that is administering the device to set the length
1750 * of the password history. After setting this, the user will not be able to
1751 * enter a new password that is the same as any password in the history. Note
1752 * that the current password will remain until the user has set a new one, so
1753 * the change does not take place immediately. To prompt the user for a new
Esteban Talaverac1c83592016-02-17 17:56:15 +00001754 * password, use {@link #ACTION_SET_NEW_PASSWORD} or
1755 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001757 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1758 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1759 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001760 *
1761 * <p>
1762 * The calling device admin must have requested
1763 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1764 * method; if it has not, a security exception will be thrown.
1765 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001766 * <p>This method can be called on the {@link DevicePolicyManager} instance
1767 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1768 * restrictions on the parent profile.
1769 *
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001770 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1771 * with.
1772 * @param length The new desired length of password history. A value of 0
1773 * means there is no restriction.
1774 */
Robin Lee25e26452015-06-02 09:56:29 -07001775 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001776 if (mService != null) {
1777 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001778 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001779 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001780 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001781 }
1782 }
1783 }
1784
1785 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001786 * Called by a device admin to set the password expiration timeout. Calling this method
1787 * will restart the countdown for password expiration for the given admin, as will changing
1788 * the device password (for all admins).
1789 *
1790 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1791 * For example, to have the password expire 5 days from now, timeout would be
1792 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1793 *
1794 * <p>To disable password expiration, a value of 0 may be used for timeout.
1795 *
Jim Millera4e28d12010-11-08 16:15:47 -08001796 * <p>The calling device admin must have requested
1797 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1798 * method; if it has not, a security exception will be thrown.
1799 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001800 * <p> Note that setting the password will automatically reset the expiration time for all
1801 * active admins. Active admins do not need to explicitly call this method in that case.
1802 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001803 * <p>This method can be called on the {@link DevicePolicyManager} instance
1804 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1805 * restrictions on the parent profile.
1806 *
Jim Millera4e28d12010-11-08 16:15:47 -08001807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1808 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1809 * means there is no restriction (unlimited).
1810 */
Robin Lee25e26452015-06-02 09:56:29 -07001811 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001812 if (mService != null) {
1813 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001814 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001815 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001816 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001817 }
1818 }
1819 }
1820
1821 /**
Jim Miller6b857682011-02-16 16:27:41 -08001822 * Get the password expiration timeout for the given admin. The expiration timeout is the
1823 * recurring expiration timeout provided in the call to
1824 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001825 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1826 * have set restrictions on profiles that have a separate challenge are not taken into account.
1827 *
1828 * <p>This method can be called on the {@link DevicePolicyManager} instance
1829 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1830 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001831 *
Robin Lee25e26452015-06-02 09:56:29 -07001832 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001833 * @return The timeout for the given admin or the minimum of all timeouts
1834 */
Robin Lee25e26452015-06-02 09:56:29 -07001835 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001836 if (mService != null) {
1837 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001838 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001839 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001840 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001841 }
1842 }
1843 return 0;
1844 }
1845
1846 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001847 * Get the current password expiration time for a particular admin or all admins that set
1848 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1849 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1850 * of all expiration times is returned - which will be the minimum of all of them.
1851 *
1852 * <p>This method can be called on the {@link DevicePolicyManager} instance
1853 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1854 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001855 *
Robin Lee25e26452015-06-02 09:56:29 -07001856 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001857 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001858 */
Robin Lee25e26452015-06-02 09:56:29 -07001859 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001860 if (mService != null) {
1861 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001862 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001863 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001864 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001865 }
1866 }
1867 return 0;
1868 }
1869
1870 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001871 * Retrieve the current password history length for a particular admin or all admins that
1872 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1873 * have a separate challenge are not taken into account.
1874 *
1875 * <p>This method can be called on the {@link DevicePolicyManager} instance
1876 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1877 * restrictions on the parent profile.
1878 *
Robin Lee25e26452015-06-02 09:56:29 -07001879 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001880 * all admins.
1881 * @return The length of the password history
1882 */
Robin Lee25e26452015-06-02 09:56:29 -07001883 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001884 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001885 }
1886
1887 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001888 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001889 if (mService != null) {
1890 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001891 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001892 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001893 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001894 }
1895 }
1896 return 0;
1897 }
1898
Dianne Hackbornd6847842010-01-12 18:14:19 -08001899 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001900 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001901 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001902 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001903 * @return Returns the maximum length that the user can enter.
1904 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001905 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001906 // Kind-of arbitrary.
1907 return 16;
1908 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001909
Dianne Hackborn254cb442010-01-27 19:23:59 -08001910 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001911 * Determine whether the current password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001912 * to meet the policy requirements (e.g. quality, minimum length) that have been
1913 * requested by the admins of this user and its participating profiles.
1914 * Restrictions on profiles that have a separate challenge are not taken into account.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001915 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001916 * <p>The calling device admin must have requested
1917 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1918 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001919 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001920 * <p>This method can be called on the {@link DevicePolicyManager} instance
1921 * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine
1922 * if the password set on the parent profile is sufficient.
1923 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001924 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001925 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001926 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001927 if (mService != null) {
1928 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001929 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001930 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001931 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001932 }
1933 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001934 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001935 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001936
Dianne Hackbornd6847842010-01-12 18:14:19 -08001937 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001938 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001939 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001940 * requested by the admins of the parent user and its profiles.
1941 *
1942 * @param userHandle the userId of the profile to check the password for.
1943 * @return Returns true if the password would meet the current requirements, else false.
1944 * @hide
1945 */
1946 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1947 if (mService != null) {
1948 try {
1949 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1950 } catch (RemoteException e) {
1951 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1952 }
1953 }
1954 return false;
1955 }
1956
1957 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001958 * Retrieve the number of times the user has failed at entering a
1959 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001960 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001961 * <p>This method can be called on the {@link DevicePolicyManager} instance
1962 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1963 * the number of failed password attemts for the parent user.
1964 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001965 * <p>The calling device admin must have requested
1966 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1967 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001968 */
1969 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001970 return getCurrentFailedPasswordAttempts(myUserId());
1971 }
1972
1973 /**
1974 * Retrieve the number of times the given user has failed at entering a
1975 * password since that last successful password entry.
1976 *
1977 * <p>The calling device admin must have requested
1978 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
1979 * not and it is not the system uid, a security exception will be thrown.
1980 *
1981 * @hide
1982 */
1983 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001984 if (mService != null) {
1985 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001986 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001987 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001988 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001989 }
1990 }
1991 return -1;
1992 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001993
1994 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001995 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001996 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001997 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001998 * @hide
1999 */
2000 public boolean getDoNotAskCredentialsOnBoot() {
2001 if (mService != null) {
2002 try {
2003 return mService.getDoNotAskCredentialsOnBoot();
2004 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002005 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002006 }
2007 }
2008 return false;
2009 }
2010
2011 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08002012 * Setting this to a value greater than zero enables a built-in policy
Esteban Talaverac1c83592016-02-17 17:56:15 +00002013 * that will perform a device or profile wipe after too many incorrect
Andrew Stadler88209d12010-02-08 22:59:36 -08002014 * device-unlock passwords have been entered. This built-in policy combines
2015 * watching for failed passwords and wiping the device, and requires
2016 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002017 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018 *
Andrew Stadler88209d12010-02-08 22:59:36 -08002019 * <p>To implement any other policy (e.g. wiping data for a particular
2020 * application only, erasing or revoking credentials, or reporting the
2021 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002022 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08002023 * instead. Do not use this API, because if the maximum count is reached,
Esteban Talaverac1c83592016-02-17 17:56:15 +00002024 * the device or profile will be wiped immediately, and your callback will not be invoked.
2025 *
2026 * <p>This method can be called on the {@link DevicePolicyManager} instance
2027 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2028 * a value on the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002029 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002031 * @param num The number of failed password attempts at which point the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002032 * device or profile will be wiped.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002033 */
Robin Lee25e26452015-06-02 09:56:29 -07002034 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002035 if (mService != null) {
2036 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002037 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002038 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002039 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002040 }
2041 }
2042 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002043
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002044 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002045 * Retrieve the current maximum number of login attempts that are allowed before the device
2046 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2047 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2048 * not taken into account.
2049 *
2050 * <p>This method can be called on the {@link DevicePolicyManager} instance
2051 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2052 * the value for the parent profile.
2053 *
Robin Lee25e26452015-06-02 09:56:29 -07002054 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002055 * all admins.
2056 */
Robin Lee25e26452015-06-02 09:56:29 -07002057 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002058 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002059 }
2060
2061 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002062 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002063 if (mService != null) {
2064 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002065 return mService.getMaximumFailedPasswordsForWipe(
2066 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002067 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002068 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002069 }
2070 }
2071 return 0;
2072 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002073
Dianne Hackborn254cb442010-01-27 19:23:59 -08002074 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002075 * Returns the profile with the smallest maximum failed passwords for wipe,
2076 * for the given user. So for primary user, it might return the primary or
2077 * a managed profile. For a secondary user, it would be the same as the
2078 * user passed in.
2079 * @hide Used only by Keyguard
2080 */
2081 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2082 if (mService != null) {
2083 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002084 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2085 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002086 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002088 }
2089 }
2090 return UserHandle.USER_NULL;
2091 }
2092
2093 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002094 * Flag for {@link #resetPassword}: don't allow other admins to change
2095 * the password again until the user has entered it.
2096 */
2097 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002098
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002099 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002100 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2101 * If the flag is set, the device can be booted without asking for user password.
2102 * The absence of this flag does not change the current boot requirements. This flag
2103 * can be set by the device owner only. If the app is not the device owner, the flag
2104 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2105 * device to factory defaults.
2106 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002107 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002108
2109 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002110 * Force a new device unlock password (the password needed to access the
2111 * entire device, not for individual accounts) on the user. This takes
2112 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08002113 *
2114 * <p>Calling this from a managed profile that shares the password with the owner profile
2115 * will throw a security exception.
2116 *
2117 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
2118 * device admins that are not device owner and not profile owner.
2119 * The password can now only be changed if there is currently no password set. Device owner
2120 * and profile owner can still do this.</em>
2121 *
2122 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002123 * current password quality and length constraints as returned by
2124 * {@link #getPasswordQuality(ComponentName)} and
2125 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
2126 * these constraints, then it will be rejected and false returned. Note
2127 * that the password may be a stronger quality (containing alphanumeric
2128 * characters when the requested quality is only numeric), in which case
2129 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002130 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002131 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08002132 * pattern or password if the current password constraints allow it. <em>Note: This will not
2133 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2134 * device owner and not profile owner. Once set, the password cannot be changed to null or
2135 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002136 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002137 * <p>The calling device admin must have requested
2138 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
2139 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002140 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002141 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002142 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002143 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002144 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08002145 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002146 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002147 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002148 if (mParentInstance) {
2149 throw new SecurityException("Reset password does not work across profiles.");
2150 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002151 if (mService != null) {
2152 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002153 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002154 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002155 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002156 }
2157 }
2158 return false;
2159 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002160
Dianne Hackbornd6847842010-01-12 18:14:19 -08002161 /**
2162 * Called by an application that is administering the device to set the
2163 * maximum time for user activity until the device will lock. This limits
2164 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002165 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002166 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002167 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002168 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002169 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002170 * <p>This method can be called on the {@link DevicePolicyManager} instance
2171 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2172 * restrictions on the parent profile.
2173 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002175 * @param timeMs The new desired maximum time to lock in milliseconds.
2176 * A value of 0 means there is no restriction.
2177 */
Robin Lee25e26452015-06-02 09:56:29 -07002178 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002179 if (mService != null) {
2180 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002181 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002182 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002183 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002184 }
2185 }
2186 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002187
Dianne Hackbornd6847842010-01-12 18:14:19 -08002188 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002189 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2190 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2191 * a separate challenge are not taken into account.
2192 *
2193 * <p>This method can be called on the {@link DevicePolicyManager} instance
2194 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2195 * restrictions on the parent profile.
2196 *
Robin Lee25e26452015-06-02 09:56:29 -07002197 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002198 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002199 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002200 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002201 */
Robin Lee25e26452015-06-02 09:56:29 -07002202 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002203 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002204 }
2205
2206 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002207 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002208 if (mService != null) {
2209 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002210 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002211 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002212 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002213 }
2214 }
2215 return 0;
2216 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002217
Dianne Hackbornd6847842010-01-12 18:14:19 -08002218 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002219 * Make the device lock immediately, as if the lock screen timeout has
2220 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002221 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002222 * <p>The calling device admin must have requested
2223 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2224 * this method; if it has not, a security exception will be thrown.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002225 *
2226 * <p>This method can be called on the {@link DevicePolicyManager} instance
2227 * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock
2228 * the parent profile.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002229 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002230 public void lockNow() {
2231 if (mService != null) {
2232 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002233 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002234 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002235 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002236 }
2237 }
2238 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002239
Dianne Hackbornd6847842010-01-12 18:14:19 -08002240 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002241 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002242 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002243 */
2244 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2245
2246 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002247 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2248 * data.
2249 *
Paul Crowley2934b262014-12-02 11:21:13 +00002250 * <p>This flag may only be set by device owner admins; if it is set by
2251 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002252 */
2253 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2254
2255 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002256 * Ask the user data be wiped. Wiping the primary user will cause the
2257 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002258 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002259 * <p>The calling device admin must have requested
2260 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2261 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002262 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002263 * @param flags Bit mask of additional options: currently supported flags
2264 * are {@link #WIPE_EXTERNAL_STORAGE} and
2265 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002266 */
2267 public void wipeData(int flags) {
2268 if (mService != null) {
2269 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002270 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002271 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002272 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002273 }
2274 }
2275 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002276
Dianne Hackbornd6847842010-01-12 18:14:19 -08002277 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002278 * Called by an application that is administering the device to set the
2279 * global proxy and exclusion list.
2280 * <p>
2281 * The calling device admin must have requested
2282 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2283 * this method; if it has not, a security exception will be thrown.
2284 * Only the first device admin can set the proxy. If a second admin attempts
2285 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002286 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002287 * be returned.
2288 * The method can be called repeatedly by the device admin alrady setting the
2289 * proxy to update the proxy and exclusion list.
2290 *
Robin Lee25e26452015-06-02 09:56:29 -07002291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002292 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2293 * Pass Proxy.NO_PROXY to reset the proxy.
2294 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002295 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2296 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002297 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002298 */
Robin Lee25e26452015-06-02 09:56:29 -07002299 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002300 List<String> exclusionList ) {
2301 if (proxySpec == null) {
2302 throw new NullPointerException();
2303 }
2304 if (mService != null) {
2305 try {
2306 String hostSpec;
2307 String exclSpec;
2308 if (proxySpec.equals(Proxy.NO_PROXY)) {
2309 hostSpec = null;
2310 exclSpec = null;
2311 } else {
2312 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2313 throw new IllegalArgumentException();
2314 }
2315 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2316 String hostName = sa.getHostName();
2317 int port = sa.getPort();
2318 StringBuilder hostBuilder = new StringBuilder();
2319 hostSpec = hostBuilder.append(hostName)
2320 .append(":").append(Integer.toString(port)).toString();
2321 if (exclusionList == null) {
2322 exclSpec = "";
2323 } else {
2324 StringBuilder listBuilder = new StringBuilder();
2325 boolean firstDomain = true;
2326 for (String exclDomain : exclusionList) {
2327 if (!firstDomain) {
2328 listBuilder = listBuilder.append(",");
2329 } else {
2330 firstDomain = false;
2331 }
2332 listBuilder = listBuilder.append(exclDomain.trim());
2333 }
2334 exclSpec = listBuilder.toString();
2335 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002336 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2337 != android.net.Proxy.PROXY_VALID)
2338 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002339 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002340 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002341 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002342 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002343 }
2344 }
2345 return null;
2346 }
2347
2348 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002349 * Set a network-independent global HTTP proxy. This is not normally what you want
2350 * for typical HTTP proxies - they are generally network dependent. However if you're
2351 * doing something unusual like general internal filtering this may be useful. On
2352 * a private network where the proxy is not accessible, you may break HTTP using this.
2353 *
2354 * <p>This method requires the caller to be the device owner.
2355 *
2356 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2357 * @see ProxyInfo
2358 *
2359 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2360 * with.
2361 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2362 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2363 */
Robin Lee25e26452015-06-02 09:56:29 -07002364 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2365 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002366 if (mService != null) {
2367 try {
2368 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2369 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002370 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002371 }
2372 }
2373 }
2374
2375 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002376 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002377 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2378 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002379 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002380 */
2381 public ComponentName getGlobalProxyAdmin() {
2382 if (mService != null) {
2383 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002384 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002385 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002386 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002387 }
2388 }
2389 return null;
2390 }
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 not supported.
2395 */
2396 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2397
2398 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002399 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002400 * indicating that encryption is supported, but is not currently active.
2401 */
2402 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2403
2404 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002405 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002406 * indicating that encryption is not currently active, but is currently
2407 * being activated. This is only reported by devices that support
2408 * encryption of data and only when the storage is currently
2409 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2410 * to become encrypted will never return this value.
2411 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002412 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002413
2414 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002415 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002416 * indicating that encryption is active.
2417 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002418 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002419
2420 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002421 * Result code for {@link #getStorageEncryptionStatus}:
2422 * indicating that encryption is active, but an encryption key has not
2423 * been set by the user.
2424 */
2425 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2426
2427 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002428 * Activity action: begin the process of encrypting data on the device. This activity should
2429 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2430 * After resuming from this activity, use {@link #getStorageEncryption}
2431 * to check encryption status. However, on some devices this activity may never return, as
2432 * it may trigger a reboot and in some cases a complete data wipe of the device.
2433 */
2434 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2435 public static final String ACTION_START_ENCRYPTION
2436 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002437 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002438 * Widgets are enabled in keyguard
2439 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002440 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002441
2442 /**
Jim Miller50e62182014-04-23 17:25:00 -07002443 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002444 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002445 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2446
2447 /**
2448 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2449 */
2450 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2451
2452 /**
Jim Miller50e62182014-04-23 17:25:00 -07002453 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2454 */
2455 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2456
2457 /**
2458 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2459 */
2460 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2461
2462 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002463 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002464 * (e.g. PIN/Pattern/Password).
2465 */
2466 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2467
2468 /**
Jim Miller06e34502014-07-17 14:46:05 -07002469 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2470 */
2471 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2472
2473 /**
Jim Miller35207742012-11-02 15:33:20 -07002474 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002475 */
2476 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002477
2478 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002479 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002480 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002481 *
2482 * <p>When multiple device administrators attempt to control device
2483 * encryption, the most secure, supported setting will always be
2484 * used. If any device administrator requests device encryption,
2485 * it will be enabled; Conversely, if a device administrator
2486 * attempts to disable device encryption while another
2487 * device administrator has enabled it, the call to disable will
2488 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2489 *
2490 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002491 * written to other storage areas may or may not be encrypted, and this policy does not require
2492 * or control the encryption of any other storage areas.
2493 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2494 * {@code true}, then the directory returned by
2495 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2496 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002497 *
2498 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2499 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2500 * the encryption key may not be fully secured. For maximum security, the administrator should
2501 * also require (and check for) a pattern, PIN, or password.
2502 *
2503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2504 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002505 * @return the new request status (for all active admins) - will be one of
2506 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2507 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2508 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002509 */
Robin Lee25e26452015-06-02 09:56:29 -07002510 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002511 if (mService != null) {
2512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002513 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002514 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002515 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002516 }
2517 }
2518 return ENCRYPTION_STATUS_UNSUPPORTED;
2519 }
2520
2521 /**
2522 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002523 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002524 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2526 * this will return the requested encryption setting as an aggregate of all active
2527 * administrators.
2528 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002529 */
Robin Lee25e26452015-06-02 09:56:29 -07002530 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002531 if (mService != null) {
2532 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002533 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002534 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002535 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002536 }
2537 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002538 return false;
2539 }
2540
2541 /**
2542 * Called by an application that is administering the device to
2543 * determine the current encryption status of the device.
2544 *
2545 * Depending on the returned status code, the caller may proceed in different
2546 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2547 * storage system does not support encryption. If the
2548 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2549 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002550 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2551 * storage system has enabled encryption but no password is set so further action
2552 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002553 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2554 *
Robin Lee7e678712014-07-24 16:41:31 +01002555 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002556 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002557 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2558 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002559 */
2560 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002561 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002562 }
2563
2564 /** @hide per-user version */
2565 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002566 if (mService != null) {
2567 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002568 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002569 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002570 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002571 }
2572 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002573 return ENCRYPTION_STATUS_UNSUPPORTED;
2574 }
2575
2576 /**
Robin Lee7e678712014-07-24 16:41:31 +01002577 * Installs the given certificate as a user CA.
2578 *
Robin Lee25e26452015-06-02 09:56:29 -07002579 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2580 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002581 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002582 *
2583 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002584 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002585 */
Robin Lee25e26452015-06-02 09:56:29 -07002586 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002587 if (mService != null) {
2588 try {
Robin Lee7e678712014-07-24 16:41:31 +01002589 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002590 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002591 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002592 }
2593 }
2594 return false;
2595 }
2596
2597 /**
Robin Lee7e678712014-07-24 16:41:31 +01002598 * Uninstalls the given certificate from trusted user CAs, if present.
2599 *
Robin Lee25e26452015-06-02 09:56:29 -07002600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2601 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002602 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002603 */
Robin Lee25e26452015-06-02 09:56:29 -07002604 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002605 if (mService != null) {
2606 try {
Robin Lee306fe082014-06-19 14:04:24 +00002607 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002608 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002609 } catch (CertificateException e) {
2610 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002611 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002612 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002613 }
2614 }
2615 }
2616
2617 /**
Robin Lee7e678712014-07-24 16:41:31 +01002618 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2619 * If a user has installed any certificates by other means than device policy these will be
2620 * included too.
2621 *
Robin Lee25e26452015-06-02 09:56:29 -07002622 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2623 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002624 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002625 */
Robin Lee25e26452015-06-02 09:56:29 -07002626 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002627 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002628 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002629 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002630 mService.enforceCanManageCaCerts(admin);
2631 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2632 for (String alias : certStore.userAliases()) {
2633 try {
2634 certs.add(certStore.getCertificate(alias).getEncoded());
2635 } catch (CertificateException ce) {
2636 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2637 }
2638 }
2639 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002641 }
2642 }
2643 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002644 }
2645
2646 /**
Robin Lee7e678712014-07-24 16:41:31 +01002647 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2648 * means other than device policy will also be removed, except for system CA certificates.
2649 *
Robin Lee25e26452015-06-02 09:56:29 -07002650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2651 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002652 */
Robin Lee25e26452015-06-02 09:56:29 -07002653 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002654 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002655 try {
2656 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2657 .toArray(new String[0]));
2658 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002659 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002660 }
2661 }
2662 }
2663
2664 /**
2665 * Returns whether this certificate is installed as a trusted CA.
2666 *
Robin Lee25e26452015-06-02 09:56:29 -07002667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2668 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002669 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002670 */
Robin Lee25e26452015-06-02 09:56:29 -07002671 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002672 if (mService != null) {
2673 try {
2674 mService.enforceCanManageCaCerts(admin);
2675 return getCaCertAlias(certBuffer) != null;
2676 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002677 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002678 } catch (CertificateException ce) {
2679 Log.w(TAG, "Could not parse certificate", ce);
2680 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002681 }
2682 return false;
2683 }
2684
2685 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002686 * Called by a device or profile owner to install a certificate and private key pair. The
2687 * keypair will be visible to all apps within the profile.
2688 *
Robin Lee25e26452015-06-02 09:56:29 -07002689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2690 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002691 * @param privKey The private key to install.
2692 * @param cert The certificate to install.
2693 * @param alias The private key alias under which to install the certificate. If a certificate
2694 * with that alias already exists, it will be overwritten.
2695 * @return {@code true} if the keys were installed, {@code false} otherwise.
2696 */
Robin Leefbc65642015-08-03 16:21:22 +01002697 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2698 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002699 try {
2700 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002701 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2702 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002703 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002704 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002705 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002706 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2707 Log.w(TAG, "Failed to obtain private key material", e);
2708 } catch (CertificateException | IOException e) {
2709 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002710 }
2711 return false;
2712 }
2713
2714 /**
Robin Leefbc65642015-08-03 16:21:22 +01002715 * Called by a device or profile owner to remove all user credentials installed under a given
2716 * alias.
2717 *
2718 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2719 * {@code null} if calling from a delegated certificate installer.
2720 * @param alias The private key alias under which the certificate is installed.
2721 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2722 */
2723 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2724 try {
2725 return mService.removeKeyPair(admin, alias);
2726 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00002727 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Leefbc65642015-08-03 16:21:22 +01002728 }
2729 return false;
2730 }
2731
2732 /**
Robin Lee25e26452015-06-02 09:56:29 -07002733 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002734 * doesn't exist.
2735 */
2736 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2737 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2738 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2739 new ByteArrayInputStream(certBuffer));
2740 return new TrustedCertificateStore().getCertificateAlias(cert);
2741 }
2742
2743 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002744 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002745 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002746 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002747 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002748 * <p>
2749 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2750 * it is later cleared by calling this method with a null value or uninstallling the certificate
2751 * installer.
Rubin Xuf03d0a62016-02-10 14:54:15 +00002752 *<p>
2753 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2754 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
2755 * supplied certificate installer package must be installed when calling this API,
2756 * otherwise an {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002757 *
Robin Lee25e26452015-06-02 09:56:29 -07002758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002759 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002760 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002761 */
Robin Lee25e26452015-06-02 09:56:29 -07002762 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2763 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002764 if (mService != null) {
2765 try {
Robin Lee25e26452015-06-02 09:56:29 -07002766 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002767 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002768 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002769 }
2770 }
2771 }
2772
2773 /**
2774 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002775 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002776 *
Robin Lee25e26452015-06-02 09:56:29 -07002777 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2778 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002779 * if none is set.
2780 */
Robin Lee25e26452015-06-02 09:56:29 -07002781 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002782 if (mService != null) {
2783 try {
Robin Lee25e26452015-06-02 09:56:29 -07002784 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002785 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002786 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002787 }
2788 }
2789 return null;
2790 }
2791
2792 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002793 * Called by a device or profile owner to configure an always-on VPN connection through a
2794 * specific application for the current user.
2795 * This connection is automatically granted and persisted after a reboot.
2796 *
2797 * <p>The designated package should declare a {@link android.net.VpnService} in its
2798 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2799 * otherwise the call will fail.
2800 *
2801 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2802 * to remove an existing always-on VPN configuration.
2803 *
2804 * @return {@code true} if the package is set as always-on VPN controller;
2805 * {@code false} otherwise.
2806 */
2807 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2808 @Nullable String vpnPackage) {
2809 if (mService != null) {
2810 try {
2811 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2812 } catch (RemoteException e) {
2813 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2814 }
2815 }
2816 return false;
2817 }
2818
2819 /**
2820 * Called by a device or profile owner to read the name of the package administering an
2821 * always-on VPN connection for the current user.
2822 * If there is no such package, or the always-on VPN is provided by the system instead
2823 * of by an application, {@code null} will be returned.
2824 *
2825 * @return Package name of VPN controller responsible for always-on VPN,
2826 * or {@code null} if none is set.
2827 */
2828 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2829 if (mService != null) {
2830 try {
2831 return mService.getAlwaysOnVpnPackage(admin);
2832 } catch (RemoteException e) {
2833 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2834 }
2835 }
2836 return null;
2837 }
2838
2839 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002840 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002841 * on the device, for this user. After setting this, no applications running as this user
2842 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002843 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002844 * <p>If the caller is device owner, then the restriction will be applied to all users.
2845 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002846 * <p>The calling device admin must have requested
2847 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2848 * this method; if it has not, a security exception will be thrown.
2849 *
2850 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2851 * @param disabled Whether or not the camera should be disabled.
2852 */
Robin Lee25e26452015-06-02 09:56:29 -07002853 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002854 if (mService != null) {
2855 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002856 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002857 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002858 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002859 }
2860 }
2861 }
2862
2863 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002864 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002865 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002866 * @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 -07002867 * have disabled the camera
2868 */
Robin Lee25e26452015-06-02 09:56:29 -07002869 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002870 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002871 }
2872
2873 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002874 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002875 if (mService != null) {
2876 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002877 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002878 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002879 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002880 }
2881 }
2882 return false;
2883 }
2884
2885 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002886 * Called by a device owner to request a bugreport.
2887 *
2888 * <p>There must be only one user on the device, managed by the device owner.
2889 * Otherwise a security exception will be thrown.
2890 *
2891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2892 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2893 * if it wasn't triggered because a previous bugreport operation is still active
2894 * (either the bugreport is still running or waiting for the user to share or decline)
2895 */
2896 public boolean requestBugreport(@NonNull ComponentName admin) {
2897 if (mService != null) {
2898 try {
2899 return mService.requestBugreport(admin);
2900 } catch (RemoteException e) {
2901 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2902 }
2903 }
2904 return false;
2905 }
2906
2907 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002908 * Determine whether or not creating a guest user has been disabled for the device
2909 *
2910 * @hide
2911 */
2912 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2913 // Currently guest users can always be created if multi-user is enabled
2914 // TODO introduce a policy for guest user creation
2915 return false;
2916 }
2917
2918 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002919 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2920 * screen capture also prevents the content from being shown on display devices that do not have
2921 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2922 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002923 *
2924 * <p>The calling device admin must be a device or profile owner. If it is not, a
2925 * security exception will be thrown.
2926 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002927 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002928 * blocks assist requests for all activities of the relevant user.
2929 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002931 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002932 */
Robin Lee25e26452015-06-02 09:56:29 -07002933 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002934 if (mService != null) {
2935 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002936 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002937 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002938 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002939 }
2940 }
2941 }
2942
2943 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002944 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002945 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002946 * @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 +01002947 * have disabled screen capture.
2948 */
Robin Lee25e26452015-06-02 09:56:29 -07002949 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002950 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002951 }
2952
2953 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002954 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002955 if (mService != null) {
2956 try {
2957 return mService.getScreenCaptureDisabled(admin, userHandle);
2958 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002959 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002960 }
2961 }
2962 return false;
2963 }
2964
2965 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002966 * Called by a device owner to set whether auto time is required. If auto time is
2967 * required the user cannot set the date and time, but has to use network date and time.
2968 *
2969 * <p>Note: if auto time is required the user can still manually set the time zone.
2970 *
2971 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2972 * be thrown.
2973 *
2974 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2975 * @param required Whether auto time is set required or not.
2976 */
Robin Lee25e26452015-06-02 09:56:29 -07002977 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002978 if (mService != null) {
2979 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002980 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002981 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002982 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002983 }
2984 }
2985 }
2986
2987 /**
2988 * @return true if auto time is required.
2989 */
2990 public boolean getAutoTimeRequired() {
2991 if (mService != null) {
2992 try {
2993 return mService.getAutoTimeRequired();
2994 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002995 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002996 }
2997 }
2998 return false;
2999 }
3000
3001 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003002 * Called by a device owner to set whether all users created on the device should be ephemeral.
3003 *
3004 * <p>The system user is exempt from this policy - it is never ephemeral.
3005 *
3006 * <p>The calling device admin must be the device owner. If it is not, a security exception will
3007 * be thrown.
3008 *
3009 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3010 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
3011 * subsequently created users will be ephemeral.
3012 * @hide
3013 */
3014 public void setForceEphemeralUsers(
3015 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3016 if (mService != null) {
3017 try {
3018 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3019 } catch (RemoteException e) {
3020 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3021 }
3022 }
3023 }
3024
3025 /**
3026 * @return true if all users are created ephemeral.
3027 * @hide
3028 */
3029 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3030 if (mService != null) {
3031 try {
3032 return mService.getForceEphemeralUsers(admin);
3033 } catch (RemoteException e) {
3034 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3035 }
3036 }
3037 return false;
3038 }
3039
3040 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003041 * Called by an application that is administering the device to disable keyguard customizations,
3042 * such as widgets. After setting this, keyguard features will be disabled according to the
3043 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003044 *
3045 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07003046 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07003047 * this method; if it has not, a security exception will be thrown.
3048 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003049 * <p>Calling this from a managed profile before version
Esteban Talaverac1c83592016-02-17 17:56:15 +00003050 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version
3051 * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003052 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003053 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
3054 * is no separate challenge set on the managed profile.
3055 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
3056 * there is one, or the parent user otherwise.
3057 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications
3058 * generated by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003059 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003060 *
3061 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3062 * set on the {@link DevicePolicyManager} instance returned by
3063 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the
3064 * parent profile.
3065 *
3066 * <p>Requests to disable other features on a managed profile will be ignored.
3067 *
3068 * <p>The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003069 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003070 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003071 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003072 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
3073 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07003074 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003075 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
3076 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07003077 */
Robin Lee25e26452015-06-02 09:56:29 -07003078 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003079 if (mService != null) {
3080 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003081 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003082 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003083 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07003084 }
3085 }
3086 }
3087
3088 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003089 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003090 * admin, if specified, or all admins that set retrictions on this user and its participating
3091 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3092 *
3093 * <p>This method can be called on the {@link DevicePolicyManager} instance
3094 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3095 * restrictions on the parent profile.
3096 *
Esteban Talavera62399912016-01-11 15:37:55 +00003097 * @param admin The name of the admin component to check, or {@code null} to check whether any
3098 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003099 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3100 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003101 */
Robin Lee25e26452015-06-02 09:56:29 -07003102 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003103 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003104 }
3105
3106 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003107 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003108 if (mService != null) {
3109 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003110 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003111 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003112 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07003113 }
3114 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003115 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003116 }
3117
3118 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003119 * @hide
3120 */
Robin Lee25e26452015-06-02 09:56:29 -07003121 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3122 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003123 if (mService != null) {
3124 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003125 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003126 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003127 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003128 }
3129 }
3130 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003131
Dianne Hackbornd6847842010-01-12 18:14:19 -08003132 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003133 * @hide
3134 */
Robin Lee25e26452015-06-02 09:56:29 -07003135 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003136 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003137 }
3138
3139 /**
Robin Lee25e26452015-06-02 09:56:29 -07003140 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08003141 * @hide
3142 */
Robin Lee25e26452015-06-02 09:56:29 -07003143 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003144 ActivityInfo ai;
3145 try {
3146 ai = mContext.getPackageManager().getReceiverInfo(cn,
3147 PackageManager.GET_META_DATA);
3148 } catch (PackageManager.NameNotFoundException e) {
3149 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
3150 return null;
3151 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003152
Dianne Hackbornd6847842010-01-12 18:14:19 -08003153 ResolveInfo ri = new ResolveInfo();
3154 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003155
Dianne Hackbornd6847842010-01-12 18:14:19 -08003156 try {
3157 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08003158 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003159 Log.w(TAG, "Unable to parse device policy " + cn, e);
3160 return null;
3161 }
3162 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003163
Dianne Hackbornd6847842010-01-12 18:14:19 -08003164 /**
3165 * @hide
3166 */
Robin Lee25e26452015-06-02 09:56:29 -07003167 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003168 if (mService != null) {
3169 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003170 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003171 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003173 }
3174 }
3175 }
3176
3177 /**
3178 * @hide
3179 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003180 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003181 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003182 if (mService != null) {
3183 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003184 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003185 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003186 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003187 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003188 }
3189 }
3190 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003191
Dianne Hackbornd6847842010-01-12 18:14:19 -08003192 /**
3193 * @hide
3194 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003195 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003196 if (mService != null) {
3197 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003198 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003199 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003200 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003201 }
3202 }
3203 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003204
Dianne Hackbornd6847842010-01-12 18:14:19 -08003205 /**
3206 * @hide
3207 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003208 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003209 if (mService != null) {
3210 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003211 mService.reportSuccessfulPasswordAttempt(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 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003217
3218 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003219 * @hide
3220 */
3221 public void reportFailedFingerprintAttempt(int userHandle) {
3222 if (mService != null) {
3223 try {
3224 mService.reportFailedFingerprintAttempt(userHandle);
3225 } catch (RemoteException e) {
3226 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3227 }
3228 }
3229 }
3230
3231 /**
3232 * @hide
3233 */
3234 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3235 if (mService != null) {
3236 try {
3237 mService.reportSuccessfulFingerprintAttempt(userHandle);
3238 } catch (RemoteException e) {
3239 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3240 }
3241 }
3242 }
3243
3244 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003245 * Should be called when keyguard has been dismissed.
3246 * @hide
3247 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003248 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003249 if (mService != null) {
3250 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003251 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003252 } catch (RemoteException e) {
3253 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3254 }
3255 }
3256 }
3257
3258 /**
3259 * Should be called when keyguard view has been shown to the user.
3260 * @hide
3261 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003262 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003263 if (mService != null) {
3264 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003265 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003266 } catch (RemoteException e) {
3267 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3268 }
3269 }
3270 }
3271
3272 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003273 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003274 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003275 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3276 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003277 * @return whether the package was successfully registered as the device owner.
3278 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003279 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003280 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003281 public boolean setDeviceOwner(ComponentName who) {
3282 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003283 }
3284
3285 /**
3286 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003287 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003288 public boolean setDeviceOwner(ComponentName who, int userId) {
3289 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003290 }
3291
3292 /**
3293 * @hide
3294 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003295 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3296 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003297 }
3298
3299 /**
3300 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003301 * Sets the given package as the device owner. The package must already be installed. There
3302 * must not already be a device owner.
3303 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3304 * this method.
3305 * Calling this after the setup phase of the primary user has completed is allowed only if
3306 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003307 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003308 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003309 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003310 * @return whether the package was successfully registered as the device owner.
3311 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003312 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003313 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003314 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003315 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003316 if (mService != null) {
3317 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003318 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003319 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003320 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003321 }
3322 }
3323 return false;
3324 }
3325
3326 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003327 * Used to determine if a particular package has been registered as a Device Owner app.
3328 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003329 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003330 * package is currently registered as the device owner app, pass in the package name from
3331 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003332 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003333 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3334 * the setup process.
3335 * @param packageName the package name of the app, to compare with the registered device owner
3336 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003337 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003338 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003339 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003340 return isDeviceOwnerAppOnCallingUser(packageName);
3341 }
3342
3343 /**
3344 * @return true if a package is registered as device owner, only when it's running on the
3345 * calling user.
3346 *
3347 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3348 * @hide
3349 */
3350 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3351 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3352 }
3353
3354 /**
3355 * @return true if a package is registered as device owner, even if it's running on a different
3356 * user.
3357 *
3358 * <p>Requires the MANAGE_USERS permission.
3359 *
3360 * @hide
3361 */
3362 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3363 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3364 }
3365
3366 /**
3367 * @return device owner component name, only when it's running on the calling user.
3368 *
3369 * @hide
3370 */
3371 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3372 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3373 }
3374
3375 /**
3376 * @return device owner component name, even if it's running on a different user.
3377 *
3378 * <p>Requires the MANAGE_USERS permission.
3379 *
3380 * @hide
3381 */
3382 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3383 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3384 }
3385
3386 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003387 if (packageName == null) {
3388 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003389 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003390 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003391 if (deviceOwner == null) {
3392 return false;
3393 }
3394 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003395 }
3396
Makoto Onukic8a5a552015-11-19 14:29:12 -08003397 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3398 if (mService != null) {
3399 try {
3400 return mService.getDeviceOwnerComponent(callingUserOnly);
3401 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003402 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003403 }
3404 }
3405 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003406 }
3407
Jason Monkb0dced82014-06-06 14:36:20 -04003408 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003409 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3410 * no device owner.
3411 *
3412 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003413 *
3414 * @hide
3415 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003416 public int getDeviceOwnerUserId() {
3417 if (mService != null) {
3418 try {
3419 return mService.getDeviceOwnerUserId();
3420 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003421 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003422 }
3423 }
3424 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003425 }
3426
3427 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003428 * Clears the current device owner. The caller must be the device owner.
3429 *
3430 * This function should be used cautiously as once it is called it cannot
3431 * be undone. The device owner can only be set as a part of device setup
3432 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003433 *
3434 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003435 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003436 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003437 if (mService != null) {
3438 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003439 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003440 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003441 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003442 }
3443 }
3444 }
3445
Makoto Onukia52562c2015-10-01 16:12:31 -07003446 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003447 * Returns the device owner package name, only if it's running on the calling user.
3448 *
3449 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003450 *
3451 * @hide
3452 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003453 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003454 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003455 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3456 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003457 }
3458
3459 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003460 * @return true if the device is managed by any device owner.
3461 *
3462 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003463 *
3464 * @hide
3465 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003466 public boolean isDeviceManaged() {
3467 return getDeviceOwnerComponentOnAnyUser() != null;
3468 }
3469
3470 /**
3471 * Returns the device owner name. Note this method *will* return the device owner
3472 * name when it's running on a different user.
3473 *
3474 * <p>Requires the MANAGE_USERS permission.
3475 *
3476 * @hide
3477 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003478 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003479 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003480 if (mService != null) {
3481 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003482 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003483 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003484 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003485 }
3486 }
3487 return null;
3488 }
Adam Connors776c5552014-01-09 10:42:56 +00003489
3490 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003491 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003492 * @deprecated Do not use
3493 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003494 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003495 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003496 @SystemApi
3497 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003498 return null;
3499 }
3500
3501 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003502 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003503 * @deprecated Do not use
3504 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003505 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003506 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003507 @SystemApi
3508 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003509 return null;
3510 }
3511
Julia Reynolds20118f12015-02-11 12:34:08 -05003512 /**
Adam Connors776c5552014-01-09 10:42:56 +00003513 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003514 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303515 * Sets the given component as an active admin and registers the package as the profile
3516 * owner for this user. The package must already be installed and there shouldn't be
3517 * an existing profile owner registered for this user. Also, this method must be called
3518 * before the user setup has been completed.
3519 * <p>
3520 * This method can only be called by system apps that hold MANAGE_USERS permission and
3521 * MANAGE_DEVICE_ADMINS permission.
3522 * @param admin The component to register as an active admin and profile owner.
3523 * @param ownerName The user-visible name of the entity that is managing this user.
3524 * @return whether the admin was successfully registered as the profile owner.
3525 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3526 * the user has already been set up.
3527 */
Justin Morey80440cc2014-07-24 09:16:35 -05003528 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003529 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303530 throws IllegalArgumentException {
3531 if (mService != null) {
3532 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003533 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303534 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003535 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303536 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303537 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3538 }
3539 }
3540 return false;
3541 }
3542
3543 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003544 * Clears the active profile owner and removes all user restrictions. The caller must
3545 * be from the same package as the active profile owner for this user, otherwise a
3546 * SecurityException will be thrown.
3547 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003548 * <p>This doesn't work for managed profile owners.
3549 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003550 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003551 */
Robin Lee25e26452015-06-02 09:56:29 -07003552 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003553 if (mService != null) {
3554 try {
3555 mService.clearProfileOwner(admin);
3556 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003557 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003558 }
3559 }
3560 }
3561
3562 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003563 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003564 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003565 */
3566 public boolean hasUserSetupCompleted() {
3567 if (mService != null) {
3568 try {
3569 return mService.hasUserSetupCompleted();
3570 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003571 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003572 }
3573 }
3574 return true;
3575 }
3576
3577 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003578 * @hide
3579 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003580 * already be installed. There must not already be a profile owner for this user.
3581 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3582 * this method.
3583 * Calling this after the setup phase of the specified user has completed is allowed only if:
3584 * - the caller is SYSTEM_UID.
3585 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003586 * @param admin the component name to be registered as profile owner.
3587 * @param ownerName the human readable name of the organisation associated with this DPM.
3588 * @param userHandle the userId to set the profile owner for.
3589 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003590 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3591 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003592 */
Robin Lee25e26452015-06-02 09:56:29 -07003593 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003594 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003595 if (mService != null) {
3596 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003597 if (ownerName == null) {
3598 ownerName = "";
3599 }
3600 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003601 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003602 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003603 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3604 }
3605 }
3606 return false;
3607 }
3608
3609 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003610 * Sets the device owner information to be shown on the lock screen.
3611 *
3612 * <p>If the device owner information is {@code null} or empty then the device owner info is
3613 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003614 * <p>If the device owner information contains only whitespaces then the message on the lock
3615 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003616 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003617 * <p>If the device owner information needs to be localized, it is the responsibility of the
3618 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3619 * and set a new version of this string accordingly.
3620 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003621 * @param admin The name of the admin component to check.
3622 * @param info Device owner information which will be displayed instead of the user
3623 * owner info.
3624 * @return Whether the device owner information has been set.
3625 */
3626 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3627 if (mService != null) {
3628 try {
3629 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3630 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003631 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003632 }
3633 }
3634 return false;
3635 }
3636
3637 /**
3638 * @return The device owner information. If it is not set returns {@code null}.
3639 */
3640 public String getDeviceOwnerLockScreenInfo() {
3641 if (mService != null) {
3642 try {
3643 return mService.getDeviceOwnerLockScreenInfo();
3644 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003645 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003646 }
3647 }
3648 return null;
3649 }
3650
3651 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003652 * Called by device or profile owners to suspend packages for this user.
3653 *
3654 * <p>A suspended package will not be able to start activities. Its notifications will
3655 * be hidden, it will not show up in recents, will not be able to show toasts or dialogs
3656 * or ring the device.
3657 *
3658 * <p>The package must already be installed.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003659 *
3660 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003661 * @param packageNames The package names to suspend or unsuspend.
3662 * @param suspended If set to {@code true} than the packages will be suspended, if set to
3663 * {@code false} the packages will be unsuspended.
3664 * @return an array of package names for which the suspended status is not set as requested in
3665 * this method.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003666 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003667 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003668 boolean suspended) {
3669 if (mService != null) {
3670 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003671 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003672 } catch (RemoteException re) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00003673 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003674 }
3675 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003676 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003677 }
3678
3679 /**
3680 * Called by device or profile owners to determine if a package is suspended.
3681 *
3682 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3683 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003684 * @return {@code true} if the package is suspended or {@code false} if the package is not
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003685 * suspended, could not be found or an error occurred.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003686 */
3687 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3688 if (mService != null) {
3689 try {
3690 return mService.getPackageSuspended(admin, packageName);
3691 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00003692 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003693 }
3694 }
3695 return false;
3696 }
3697
3698 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003699 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3700 * be used. Only the profile owner can call this.
3701 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003702 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003703 *
3704 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3705 */
Robin Lee25e26452015-06-02 09:56:29 -07003706 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003707 if (mService != null) {
3708 try {
3709 mService.setProfileEnabled(admin);
3710 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003711 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003712 }
3713 }
3714 }
3715
3716 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003717 * Sets the name of the profile. In the device owner case it sets the name of the user
3718 * 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 +01003719 * never called by the profile or device owner, the name will be set to default values.
3720 *
3721 * @see #isProfileOwnerApp
3722 * @see #isDeviceOwnerApp
3723 *
Robin Lee25e26452015-06-02 09:56:29 -07003724 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003725 * @param profileName The name of the profile.
3726 */
Robin Lee25e26452015-06-02 09:56:29 -07003727 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003728 if (mService != null) {
3729 try {
Robin Lee25e26452015-06-02 09:56:29 -07003730 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003731 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003732 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003733 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003734 }
3735 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003736
3737 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003738 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003739 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003740 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003741 *
3742 * @param packageName The package name of the app to compare with the registered profile owner.
3743 * @return Whether or not the package is registered as the profile owner.
3744 */
3745 public boolean isProfileOwnerApp(String packageName) {
3746 if (mService != null) {
3747 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003748 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003749 return profileOwner != null
3750 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003751 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003752 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003753 }
3754 }
3755 return false;
3756 }
3757
3758 /**
3759 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003760 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003761 * owner has been set for that user.
3762 * @throws IllegalArgumentException if the userId is invalid.
3763 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003764 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003765 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003766 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3767 }
3768
3769 /**
3770 * @see #getProfileOwner()
3771 * @hide
3772 */
3773 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003774 if (mService != null) {
3775 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003776 return mService.getProfileOwner(userId);
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 throw new IllegalArgumentException(
3780 "Requested profile owner for invalid userId", re);
3781 }
3782 }
3783 return null;
3784 }
3785
3786 /**
3787 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003788 * @return the human readable name of the organisation associated with this DPM or {@code null}
3789 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003790 * @throws IllegalArgumentException if the userId is invalid.
3791 */
3792 public String getProfileOwnerName() throws IllegalArgumentException {
3793 if (mService != null) {
3794 try {
3795 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3796 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003797 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003798 throw new IllegalArgumentException(
3799 "Requested profile owner for invalid userId", re);
3800 }
3801 }
3802 return null;
3803 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003804
3805 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003806 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003807 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003808 * @return the human readable name of the organisation associated with this profile owner or
3809 * null if one is not set.
3810 * @throws IllegalArgumentException if the userId is invalid.
3811 */
3812 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003813 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003814 if (mService != null) {
3815 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003816 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003817 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003818 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003819 throw new IllegalArgumentException(
3820 "Requested profile owner for invalid userId", re);
3821 }
3822 }
3823 return null;
3824 }
3825
3826 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003827 * Called by a profile owner or device owner to add a default intent handler activity for
3828 * intents that match a certain intent filter. This activity will remain the default intent
3829 * handler even if the set of potential event handlers for the intent filter changes and if
3830 * the intent preferences are reset.
3831 *
3832 * <p>The default disambiguation mechanism takes over if the activity is not installed
3833 * (anymore). When the activity is (re)installed, it is automatically reset as default
3834 * intent handler for the filter.
3835 *
3836 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3837 * security exception will be thrown.
3838 *
3839 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3840 * @param filter The IntentFilter for which a default handler is added.
3841 * @param activity The Activity that is added as default intent handler.
3842 */
Robin Lee25e26452015-06-02 09:56:29 -07003843 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3844 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003845 if (mService != null) {
3846 try {
3847 mService.addPersistentPreferredActivity(admin, filter, activity);
3848 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003849 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003850 }
3851 }
3852 }
3853
3854 /**
3855 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003856 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003857 *
3858 * <p>The calling device admin must be a profile owner. If it is not, a security
3859 * exception will be thrown.
3860 *
3861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3862 * @param packageName The name of the package for which preferences are removed.
3863 */
Robin Lee25e26452015-06-02 09:56:29 -07003864 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003865 String packageName) {
3866 if (mService != null) {
3867 try {
3868 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3869 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003870 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003871 }
3872 }
3873 }
Robin Lee66e5d962014-04-09 16:44:21 +01003874
3875 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003876 * Called by a profile owner or device owner to grant permission to a package to manage
3877 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3878 * {@link #getApplicationRestrictions}.
3879 * <p>
3880 * This permission is persistent until it is later cleared by calling this method with a
3881 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00003882 * <p>
3883 * The supplied application restriction managing package must be installed when calling this
3884 * API, otherwise an {@link IllegalArgumentException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00003885 *
3886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3887 * @param packageName The package name which will be given access to application restrictions
3888 * APIs. If {@code null} is given the current package will be cleared.
3889 */
3890 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3891 @Nullable String packageName) {
3892 if (mService != null) {
3893 try {
3894 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3895 } catch (RemoteException e) {
3896 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3897 }
3898 }
3899 }
3900
3901 /**
3902 * Called by a profile owner or device owner to retrieve the application restrictions managing
3903 * package for the current user, or {@code null} if none is set.
3904 *
3905 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3906 * @return The package name allowed to manage application restrictions on the current user, or
3907 * {@code null} if none is set.
3908 */
3909 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3910 if (mService != null) {
3911 try {
3912 return mService.getApplicationRestrictionsManagingPackage(admin);
3913 } catch (RemoteException e) {
3914 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3915 }
3916 }
3917 return null;
3918 }
3919
3920 /**
3921 * Returns {@code true} if the calling package has been granted permission via
3922 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3923 * restrictions for the calling user.
3924 */
3925 public boolean isCallerApplicationRestrictionsManagingPackage() {
3926 if (mService != null) {
3927 try {
3928 return mService.isCallerApplicationRestrictionsManagingPackage();
3929 } catch (RemoteException e) {
3930 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3931 }
3932 }
3933 return false;
3934 }
3935
3936 /**
3937 * Sets the application restrictions for a given target application running in the calling user.
3938 *
3939 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3940 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3941 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003942 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003943 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3944 * <ul>
3945 * <li>{@code boolean}
3946 * <li>{@code int}
3947 * <li>{@code String} or {@code String[]}
3948 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3949 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003950 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003951 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003952 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003953 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3954 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003955 * <p>The application restrictions are only made visible to the target application via
3956 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3957 * device owner, and the application restrictions managing package via
3958 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003959 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3961 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003962 * @param packageName The name of the package to update restricted settings for.
3963 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3964 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003965 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003966 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003967 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003968 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003969 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003970 Bundle settings) {
3971 if (mService != null) {
3972 try {
3973 mService.setApplicationRestrictions(admin, packageName, settings);
3974 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003975 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003976 }
3977 }
3978 }
3979
3980 /**
Jim Millere303bf42014-08-26 17:12:29 -07003981 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3982 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3983 * trust agents but those enabled by this function call. If flag
3984 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003985 *
3986 * <p>The calling device admin must have requested
3987 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003988 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003989 *
3990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003991 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003992 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003993 * will be strictly disabled according to the state of the
3994 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3995 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3996 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3997 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003998 */
Robin Lee25e26452015-06-02 09:56:29 -07003999 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4000 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004001 if (mService != null) {
4002 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004003 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004004 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004005 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07004006 }
4007 }
4008 }
4009
4010 /**
Jim Millere303bf42014-08-26 17:12:29 -07004011 * Gets configuration for the given trust agent based on aggregating all calls to
4012 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4013 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004014 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004015 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4016 * this function returns a list of configurations for all admins that declare
4017 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4018 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4019 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4020 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004021 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004022 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004023 */
Robin Lee25e26452015-06-02 09:56:29 -07004024 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4025 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004026 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004027 }
4028
4029 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004030 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4031 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004032 if (mService != null) {
4033 try {
Jim Millere303bf42014-08-26 17:12:29 -07004034 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004035 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004036 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07004037 }
4038 }
Jim Millere303bf42014-08-26 17:12:29 -07004039 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004040 }
4041
4042 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004043 * Called by a profile owner of a managed profile to set whether caller-Id information from
4044 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01004045 *
4046 * <p>The calling device admin must be a profile owner. If it is not, a
4047 * security exception will be thrown.
4048 *
Robin Lee25e26452015-06-02 09:56:29 -07004049 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004050 * @param disabled If true caller-Id information in the managed profile is not displayed.
4051 */
Robin Lee25e26452015-06-02 09:56:29 -07004052 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004053 if (mService != null) {
4054 try {
Robin Lee25e26452015-06-02 09:56:29 -07004055 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004056 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004057 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01004058 }
4059 }
4060 }
4061
4062 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004063 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4064 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01004065 *
4066 * <p>The calling device admin must be a profile owner. If it is not, a
4067 * security exception will be thrown.
4068 *
Robin Lee25e26452015-06-02 09:56:29 -07004069 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004070 */
Robin Lee25e26452015-06-02 09:56:29 -07004071 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004072 if (mService != null) {
4073 try {
Robin Lee25e26452015-06-02 09:56:29 -07004074 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004075 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004076 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01004077 }
4078 }
4079 return false;
4080 }
4081
4082 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004083 * Determine whether or not caller-Id information has been disabled.
4084 *
4085 * @param userHandle The user for whom to check the caller-id permission
4086 * @hide
4087 */
4088 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4089 if (mService != null) {
4090 try {
4091 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4092 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004093 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07004094 }
4095 }
4096 return false;
4097 }
4098
4099 /**
Victor Chang1060c6182016-01-04 20:16:23 +00004100 * Called by a profile owner of a managed profile to set whether contacts search from
4101 * the managed profile will be shown in the parent profile, for incoming calls.
4102 *
4103 * <p>The calling device admin must be a profile owner. If it is not, a
4104 * security exception will be thrown.
4105 *
4106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4107 * @param disabled If true contacts search in the managed profile is not displayed.
4108 */
4109 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4110 boolean disabled) {
4111 if (mService != null) {
4112 try {
4113 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4114 } catch (RemoteException e) {
4115 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4116 }
4117 }
4118 }
4119
4120 /**
4121 * Called by a profile owner of a managed profile to determine whether or not contacts search
4122 * has been disabled.
4123 *
4124 * <p>The calling device admin must be a profile owner. If it is not, a
4125 * security exception will be thrown.
4126 *
4127 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4128 */
4129 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4130 if (mService != null) {
4131 try {
4132 return mService.getCrossProfileContactsSearchDisabled(admin);
4133 } catch (RemoteException e) {
4134 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4135 }
4136 }
4137 return false;
4138 }
4139
4140
4141 /**
4142 * Determine whether or not contacts search has been disabled.
4143 *
4144 * @param userHandle The user for whom to check the contacts search permission
4145 * @hide
4146 */
4147 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4148 if (mService != null) {
4149 try {
4150 return mService
4151 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4152 } catch (RemoteException e) {
4153 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4154 }
4155 }
4156 return false;
4157 }
4158
4159 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004160 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004161 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004162 * @hide
4163 */
4164 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004165 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004166 if (mService != null) {
4167 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004168 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4169 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004170 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004171 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07004172 }
4173 }
4174 }
4175
4176 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004177 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004178 * @hide
4179 */
4180 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4181 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004182 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004183 originalIntent);
4184 }
4185
4186 /**
Ricky Wai778ba132015-03-31 14:21:22 +01004187 * Called by a profile owner of a managed profile to set whether bluetooth
4188 * devices can access enterprise contacts.
4189 * <p>
4190 * The calling device admin must be a profile owner. If it is not, a
4191 * security exception will be thrown.
4192 * <p>
4193 * This API works on managed profile only.
4194 *
Robin Lee25e26452015-06-02 09:56:29 -07004195 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004196 * with.
4197 * @param disabled If true, bluetooth devices cannot access enterprise
4198 * contacts.
4199 */
Robin Lee25e26452015-06-02 09:56:29 -07004200 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004201 if (mService != null) {
4202 try {
Robin Lee25e26452015-06-02 09:56:29 -07004203 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004204 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004205 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004206 }
4207 }
4208 }
4209
4210 /**
4211 * Called by a profile owner of a managed profile to determine whether or
4212 * not Bluetooth devices cannot access enterprise contacts.
4213 * <p>
4214 * The calling device admin must be a profile owner. If it is not, a
4215 * security exception will be thrown.
4216 * <p>
4217 * This API works on managed profile only.
4218 *
Robin Lee25e26452015-06-02 09:56:29 -07004219 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004220 * with.
4221 */
Robin Lee25e26452015-06-02 09:56:29 -07004222 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004223 if (mService != null) {
4224 try {
Robin Lee25e26452015-06-02 09:56:29 -07004225 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004226 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004227 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004228 }
4229 }
4230 return true;
4231 }
4232
4233 /**
4234 * Determine whether or not Bluetooth devices cannot access contacts.
4235 * <p>
4236 * This API works on managed profile UserHandle only.
4237 *
4238 * @param userHandle The user for whom to check the caller-id permission
4239 * @hide
4240 */
4241 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4242 if (mService != null) {
4243 try {
4244 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4245 .getIdentifier());
4246 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004247 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004248 }
4249 }
4250 return true;
4251 }
4252
4253 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004254 * Called by the profile owner of a managed profile so that some intents sent in the managed
4255 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004256 * Only activity intents are supported.
4257 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004259 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4260 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004261 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4262 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004263 */
Robin Lee25e26452015-06-02 09:56:29 -07004264 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004265 if (mService != null) {
4266 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004267 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004268 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004269 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004270 }
4271 }
4272 }
4273
4274 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004275 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4276 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004277 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4279 */
Robin Lee25e26452015-06-02 09:56:29 -07004280 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004281 if (mService != null) {
4282 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004283 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004284 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004285 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004286 }
4287 }
4288 }
4289
4290 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004291 * Called by a profile or device owner to set the permitted accessibility services. When
4292 * set by a device owner or profile owner the restriction applies to all profiles of the
4293 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004294 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004295 * By default the user can use any accessiblity service. When zero or more packages have
4296 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004297 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004298 *
4299 * <p> Calling with a null value for the list disables the restriction so that all services
4300 * can be used, calling with an empty list only allows the builtin system's services.
4301 *
4302 * <p> System accesibility services are always available to the user the list can't modify
4303 * this.
4304 *
4305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4306 * @param packageNames List of accessibility service package names.
4307 *
4308 * @return true if setting the restriction succeeded. It fail if there is
4309 * one or more non-system accessibility services enabled, that are not in the list.
4310 */
Robin Lee25e26452015-06-02 09:56:29 -07004311 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004312 List<String> packageNames) {
4313 if (mService != null) {
4314 try {
4315 return mService.setPermittedAccessibilityServices(admin, packageNames);
4316 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004317 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004318 }
4319 }
4320 return false;
4321 }
4322
4323 /**
4324 * Returns the list of permitted accessibility services set by this device or profile owner.
4325 *
4326 * <p>An empty list means no accessibility services except system services are allowed.
4327 * Null means all accessibility services are allowed.
4328 *
4329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4330 * @return List of accessiblity service package names.
4331 */
Robin Lee25e26452015-06-02 09:56:29 -07004332 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004333 if (mService != null) {
4334 try {
4335 return mService.getPermittedAccessibilityServices(admin);
4336 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004337 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004338 }
4339 }
4340 return null;
4341 }
4342
4343 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004344 * Called by the system to check if a specific accessibility service is disabled by admin.
4345 *
4346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4347 * @param packageName Accessibility service package name that needs to be checked.
4348 * @param userHandle user id the admin is running as.
4349 * @return true if the accessibility service is permitted, otherwise false.
4350 *
4351 * @hide
4352 */
4353 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4354 @NonNull String packageName, int userHandle) {
4355 if (mService != null) {
4356 try {
4357 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4358 userHandle);
4359 } catch (RemoteException e) {
4360 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4361 }
4362 }
4363 return false;
4364 }
4365
4366 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004367 * Returns the list of accessibility services permitted by the device or profiles
4368 * owners of this user.
4369 *
4370 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4371 * it will contain the intersection of the permitted lists for any device or profile
4372 * owners that apply to this user. It will also include any system accessibility services.
4373 *
4374 * @param userId which user to check for.
4375 * @return List of accessiblity service package names.
4376 * @hide
4377 */
4378 @SystemApi
4379 public List<String> getPermittedAccessibilityServices(int userId) {
4380 if (mService != null) {
4381 try {
4382 return mService.getPermittedAccessibilityServicesForUser(userId);
4383 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004384 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004385 }
4386 }
4387 return null;
4388 }
4389
4390 /**
4391 * Called by a profile or device owner to set the permitted input methods services. When
4392 * set by a device owner or profile owner the restriction applies to all profiles of the
4393 * user the device owner or profile owner is an admin for.
4394 *
4395 * By default the user can use any input method. When zero or more packages have
4396 * been added, input method that are not in the list and not part of the system
4397 * can not be enabled by the user.
4398 *
4399 * This method will fail if it is called for a admin that is not for the foreground user
4400 * or a profile of the foreground user.
4401 *
4402 * <p> Calling with a null value for the list disables the restriction so that all input methods
4403 * can be used, calling with an empty list disables all but the system's own input methods.
4404 *
4405 * <p> System input methods are always available to the user this method can't modify this.
4406 *
4407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4408 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004409 * @return true if setting the restriction succeeded. It will fail if there are
4410 * one or more non-system input methods currently enabled that are not in
4411 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004412 */
Robin Lee25e26452015-06-02 09:56:29 -07004413 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004414 if (mService != null) {
4415 try {
4416 return mService.setPermittedInputMethods(admin, packageNames);
4417 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004418 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004419 }
4420 }
4421 return false;
4422 }
4423
4424
4425 /**
4426 * Returns the list of permitted input methods set by this device or profile owner.
4427 *
4428 * <p>An empty list means no input methods except system input methods are allowed.
4429 * Null means all input methods are allowed.
4430 *
4431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4432 * @return List of input method package names.
4433 */
Robin Lee25e26452015-06-02 09:56:29 -07004434 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004435 if (mService != null) {
4436 try {
4437 return mService.getPermittedInputMethods(admin);
4438 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004439 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004440 }
4441 }
4442 return null;
4443 }
4444
4445 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004446 * Called by the system to check if a specific input method is disabled by admin.
4447 *
4448 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4449 * @param packageName Input method package name that needs to be checked.
4450 * @param userHandle user id the admin is running as.
4451 * @return true if the input method is permitted, otherwise false.
4452 *
4453 * @hide
4454 */
4455 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4456 @NonNull String packageName, int userHandle) {
4457 if (mService != null) {
4458 try {
4459 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4460 } catch (RemoteException e) {
4461 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4462 }
4463 }
4464 return false;
4465 }
4466
4467 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004468 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004469 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004470 *
4471 * <p>Null means all input methods are allowed, if a non-null list is returned
4472 * it will contain the intersection of the permitted lists for any device or profile
4473 * owners that apply to this user. It will also include any system input methods.
4474 *
4475 * @return List of input method package names.
4476 * @hide
4477 */
4478 @SystemApi
4479 public List<String> getPermittedInputMethodsForCurrentUser() {
4480 if (mService != null) {
4481 try {
4482 return mService.getPermittedInputMethodsForCurrentUser();
4483 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004484 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004485 }
4486 }
4487 return null;
4488 }
4489
4490 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004491 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4492 * currently installed it.
4493 *
4494 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4495 *
4496 * @return List of package names to keep cached.
4497 * @hide
4498 */
4499 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4500 if (mService != null) {
4501 try {
4502 return mService.getKeepUninstalledPackages(admin);
4503 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004504 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004505 }
4506 }
4507 return null;
4508 }
4509
4510 /**
4511 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4512 * currently installed it.
4513 *
4514 * <p>Please note that setting this policy does not imply that specified apps will be
4515 * automatically pre-cached.</p>
4516 *
4517 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4518 * @param packageNames List of package names to keep cached.
4519 * @hide
4520 */
4521 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4522 @NonNull List<String> packageNames) {
4523 if (mService != null) {
4524 try {
4525 mService.setKeepUninstalledPackages(admin, packageNames);
4526 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004527 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004528 }
4529 }
4530 }
4531
4532 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004533 * Called by a device owner to create a user with the specified name. The UserHandle returned
4534 * by this method should not be persisted as user handles are recycled as users are removed and
4535 * created. If you need to persist an identifier for this user, use
4536 * {@link UserManager#getSerialNumberForUser}.
4537 *
4538 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4539 * @param name the user's name
4540 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004541 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4542 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004543 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004544 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004545 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004546 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004547 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004548 try {
4549 return mService.createUser(admin, name);
4550 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004551 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004552 }
4553 return null;
4554 }
4555
4556 /**
Jason Monk03978a42014-06-10 15:05:30 -04004557 * Called by a device owner to create a user with the specified name. The UserHandle returned
4558 * by this method should not be persisted as user handles are recycled as users are removed and
4559 * created. If you need to persist an identifier for this user, use
4560 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4561 * immediately.
4562 *
4563 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4564 * as registered as an active admin on the new user. The profile owner package will be
4565 * installed on the new user if it already is installed on the device.
4566 *
4567 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4568 * profileOwnerComponent when onEnable is called.
4569 *
4570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4571 * @param name the user's name
4572 * @param ownerName the human readable name of the organisation associated with this DPM.
4573 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4574 * the user.
4575 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4576 * on the new user.
4577 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004578 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4579 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004580 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004581 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004582 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004583 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004584 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4585 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004586 try {
4587 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4588 adminExtras);
4589 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004590 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004591 }
4592 return null;
4593 }
4594
4595 /**
phweissa92e1212016-01-25 17:14:10 +01004596 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004597 */
4598 public static final int SKIP_SETUP_WIZARD = 0x0001;
4599
4600 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004601 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4602 * ephemeral.
4603 * @hide
4604 */
4605 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4606
4607 /**
phweissa92e1212016-01-25 17:14:10 +01004608 * Called by a device owner to create a user with the specified name and a given component of
4609 * the calling package as profile owner. The UserHandle returned by this method should not be
4610 * persisted as user handles are recycled as users are removed and created. If you need to
4611 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4612 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004613 *
phweissa92e1212016-01-25 17:14:10 +01004614 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4615 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4616 * will be registered as an active admin on the new user. The profile owner package will be
4617 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004618 *
4619 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4620 * started for the first time. Then the extras will be passed to the admin when
4621 * onEnable is called.
4622 *
4623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4624 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004625 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4626 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4627 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004628 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4629 * user.
phweissa92e1212016-01-25 17:14:10 +01004630 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004631 * @see UserHandle
4632 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4633 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004634 */
4635 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004636 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4637 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004638 try {
phweissa92e1212016-01-25 17:14:10 +01004639 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004640 } catch (RemoteException re) {
4641 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4642 }
4643 return null;
4644 }
4645
4646 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004647 * Called by a device owner to remove a user and all associated data. The primary user can
4648 * not be removed.
4649 *
4650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4651 * @param userHandle the user to remove.
4652 * @return {@code true} if the user was removed, {@code false} otherwise.
4653 */
Robin Lee25e26452015-06-02 09:56:29 -07004654 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004655 try {
4656 return mService.removeUser(admin, userHandle);
4657 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004658 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004659 return false;
4660 }
4661 }
4662
4663 /**
Jason Monk582d9112014-07-09 19:57:08 -04004664 * Called by a device owner to switch the specified user to the foreground.
4665 *
4666 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4667 * @param userHandle the user to switch to; null will switch to primary.
4668 * @return {@code true} if the switch was successful, {@code false} otherwise.
4669 *
4670 * @see Intent#ACTION_USER_FOREGROUND
4671 */
Robin Lee25e26452015-06-02 09:56:29 -07004672 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004673 try {
4674 return mService.switchUser(admin, userHandle);
4675 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004676 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004677 return false;
4678 }
4679 }
4680
4681 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004682 * Retrieves the application restrictions for a given target application running in the calling
4683 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004684 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004685 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4686 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4687 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004688 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4690 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004691 * @param packageName The name of the package to fetch restricted settings of.
4692 * @return {@link Bundle} of settings corresponding to what was set last time
4693 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4694 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004695 *
4696 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004697 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004698 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004699 if (mService != null) {
4700 try {
4701 return mService.getApplicationRestrictions(admin, packageName);
4702 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004703 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004704 }
4705 }
4706 return null;
4707 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004708
4709 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004710 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004711 * <p>
4712 * The calling device admin must be a profile or device owner; if it is not,
4713 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004714 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004715 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4716 * with.
4717 * @param key The key of the restriction. See the constants in
4718 * {@link android.os.UserManager} for the list of keys.
4719 */
Robin Lee25e26452015-06-02 09:56:29 -07004720 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004721 if (mService != null) {
4722 try {
4723 mService.setUserRestriction(admin, key, true);
4724 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004725 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004726 }
4727 }
4728 }
4729
4730 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004731 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004732 * <p>
4733 * The calling device admin must be a profile or device owner; if it is not,
4734 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004735 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004736 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4737 * with.
4738 * @param key The key of the restriction. See the constants in
4739 * {@link android.os.UserManager} for the list of keys.
4740 */
Robin Lee25e26452015-06-02 09:56:29 -07004741 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004742 if (mService != null) {
4743 try {
4744 mService.setUserRestriction(admin, key, false);
4745 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004746 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004747 }
4748 }
4749 }
Adam Connors010cfd42014-04-16 12:48:13 +01004750
4751 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004752 * Called by a profile or device owner to get user restrictions set with
4753 * {@link #addUserRestriction(ComponentName, String)}.
4754 * <p>
4755 * The target user may have more restrictions set by the system or other device owner / profile
4756 * owner. To get all the user restrictions currently set, use
4757 * {@link UserManager#getUserRestrictions()}.
4758 *
4759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004760 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004761 */
4762 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004763 return getUserRestrictions(admin, myUserId());
4764 }
4765
4766 /** @hide per-user version */
4767 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004768 Bundle ret = null;
4769 if (mService != null) {
4770 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004771 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004772 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004773 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004774 }
4775 }
4776 return ret == null ? new Bundle() : ret;
4777 }
4778
4779 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004780 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004781 * is unavailable for use, but the data and actual package file remain.
4782 *
4783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004784 * @param packageName The name of the package to hide or unhide.
4785 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4786 * unhidden.
4787 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004788 */
Robin Lee25e26452015-06-02 09:56:29 -07004789 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004790 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004791 if (mService != null) {
4792 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004793 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004794 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004795 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004796 }
4797 }
4798 return false;
4799 }
4800
4801 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004802 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004803 *
4804 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004805 * @param packageName The name of the package to retrieve the hidden status of.
4806 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004807 */
Robin Lee25e26452015-06-02 09:56:29 -07004808 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004809 if (mService != null) {
4810 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004811 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004812 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004813 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004814 }
4815 }
4816 return false;
4817 }
4818
4819 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004820 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004821 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004822 *
4823 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004824 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004825 */
Robin Lee25e26452015-06-02 09:56:29 -07004826 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004827 if (mService != null) {
4828 try {
4829 mService.enableSystemApp(admin, packageName);
4830 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004831 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004832 }
4833 }
4834 }
4835
4836 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004837 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004838 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004839 *
4840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4841 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004842 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004843 * @return int The number of activities that matched the intent and were installed.
4844 */
Robin Lee25e26452015-06-02 09:56:29 -07004845 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004846 if (mService != null) {
4847 try {
4848 return mService.enableSystemAppWithIntent(admin, intent);
4849 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004850 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004851 }
4852 }
4853 return 0;
4854 }
4855
4856 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004857 * Called by a device owner or profile owner to disable account management for a specific type
4858 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004859 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004860 * <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 +01004861 * security exception will be thrown.
4862 *
4863 * <p>When account management is disabled for an account type, adding or removing an account
4864 * of that type will not be possible.
4865 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004866 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4867 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4868 * management for a specific type is disabled.
4869 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004870 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4871 * @param accountType For which account management is disabled or enabled.
4872 * @param disabled The boolean indicating that account management will be disabled (true) or
4873 * enabled (false).
4874 */
Robin Lee25e26452015-06-02 09:56:29 -07004875 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004876 boolean disabled) {
4877 if (mService != null) {
4878 try {
4879 mService.setAccountManagementDisabled(admin, accountType, disabled);
4880 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004881 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004882 }
4883 }
4884 }
4885
4886 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004887 * Gets the array of accounts for which account management is disabled by the profile owner.
4888 *
4889 * <p> Account management can be disabled/enabled by calling
4890 * {@link #setAccountManagementDisabled}.
4891 *
4892 * @return a list of account types for which account management has been disabled.
4893 *
4894 * @see #setAccountManagementDisabled
4895 */
4896 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004897 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004898 }
4899
4900 /**
4901 * @see #getAccountTypesWithManagementDisabled()
4902 * @hide
4903 */
4904 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004905 if (mService != null) {
4906 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004907 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004908 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004909 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004910 }
4911 }
4912
4913 return null;
4914 }
justinzhang511e0d82014-03-24 16:09:24 -04004915
4916 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004917 * Sets which packages may enter lock task mode.
4918 *
4919 * <p>Any packages that shares uid with an allowed package will also be allowed
4920 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004921 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004922 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004923 * package list results in locked tasks belonging to those packages to be finished.
4924 *
Jason Monkc5185f22014-06-24 11:12:42 -04004925 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004926 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004927 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004928 *
4929 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004930 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4931 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004932 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004933 */
Robin Lee25e26452015-06-02 09:56:29 -07004934 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004935 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004936 if (mService != null) {
4937 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004938 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004939 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004941 }
4942 }
4943 }
4944
4945 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004946 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004947 *
4948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004949 * @hide
4950 */
Robin Lee25e26452015-06-02 09:56:29 -07004951 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004952 if (mService != null) {
4953 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004954 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004955 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004956 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004957 }
4958 }
4959 return null;
4960 }
4961
4962 /**
4963 * This function lets the caller know whether the given component is allowed to start the
4964 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004965 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004966 */
Jason Monkd7b86212014-06-16 13:15:38 -04004967 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004968 if (mService != null) {
4969 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004970 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004971 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004972 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004973 }
4974 }
4975 return false;
4976 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004977
4978 /**
4979 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4980 * 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 -04004981 * <p>The settings that can be updated with this method are:
4982 * <ul>
4983 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4984 * <li>{@link Settings.Global#AUTO_TIME}</li>
4985 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004986 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004987 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004988 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004989 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004990 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004991 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004992 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004993 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004994 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004995 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004996 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004997 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004998 * <ul>
4999 * <li>{@link Settings.Global#BLUETOOTH_ON}.
5000 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
5001 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
5002 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
5003 * <li>{@link Settings.Global#MODE_RINGER}.
5004 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
5005 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
5006 * <li>{@link Settings.Global#WIFI_ON}.
5007 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
5008 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005009 *
5010 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5011 * @param setting The name of the setting to update.
5012 * @param value The value to update the setting to.
5013 */
Robin Lee25e26452015-06-02 09:56:29 -07005014 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005015 if (mService != null) {
5016 try {
5017 mService.setGlobalSetting(admin, setting, value);
5018 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005019 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04005020 }
5021 }
5022 }
5023
5024 /**
5025 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5026 * that the value of the setting is in the correct form for the setting type should be performed
5027 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04005028 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005029 * <ul>
5030 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005031 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005032 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5033 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04005034 * <p>A device owner can additionally update the following settings:
5035 * <ul>
5036 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5037 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005038 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5039 * @param setting The name of the setting to update.
5040 * @param value The value to update the setting to.
5041 */
Robin Lee25e26452015-06-02 09:56:29 -07005042 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005043 if (mService != null) {
5044 try {
5045 mService.setSecureSetting(admin, setting, value);
5046 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005047 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04005048 }
5049 }
5050 }
5051
Amith Yamasanif20d6402014-05-24 15:34:37 -07005052 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005053 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07005054 * making permission requests of a local or remote administrator of the user.
5055 * <p/>
5056 * Only a profile owner can designate the restrictions provider.
5057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005058 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07005059 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07005060 * it removes the restrictions provider previously assigned.
5061 */
Robin Lee25e26452015-06-02 09:56:29 -07005062 public void setRestrictionsProvider(@NonNull ComponentName admin,
5063 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005064 if (mService != null) {
5065 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005066 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005067 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005068 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005069 }
5070 }
5071 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005072
5073 /**
5074 * Called by profile or device owners to set the master volume mute on or off.
5075 *
5076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5077 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
5078 */
Robin Lee25e26452015-06-02 09:56:29 -07005079 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005080 if (mService != null) {
5081 try {
5082 mService.setMasterVolumeMuted(admin, on);
5083 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005084 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04005085 }
5086 }
5087 }
5088
5089 /**
5090 * Called by profile or device owners to check whether the master volume mute is on or off.
5091 *
5092 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5093 * @return {@code true} if master volume is muted, {@code false} if it's not.
5094 */
Robin Lee25e26452015-06-02 09:56:29 -07005095 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005096 if (mService != null) {
5097 try {
5098 return mService.isMasterVolumeMuted(admin);
5099 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005100 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04005101 }
5102 }
5103 return false;
5104 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005105
5106 /**
5107 * Called by profile or device owners to change whether a user can uninstall
5108 * a package.
5109 *
5110 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5111 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005112 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005113 */
Robin Lee25e26452015-06-02 09:56:29 -07005114 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005115 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005116 if (mService != null) {
5117 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005118 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005119 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005120 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01005121 }
5122 }
5123 }
5124
5125 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005126 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005127 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005128 * <p>
5129 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07005130 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00005131 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07005132 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005133 *
Robin Lee25e26452015-06-02 09:56:29 -07005134 * @param admin The name of the admin component whose blocking policy will be checked, or
5135 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005136 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005137 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01005138 */
Robin Lee25e26452015-06-02 09:56:29 -07005139 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005140 if (mService != null) {
5141 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005142 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005143 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005144 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01005145 }
5146 }
5147 return false;
5148 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005149
5150 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005151 * Called by the profile owner of a managed profile to enable widget providers from a
5152 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07005153 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005154 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07005155 * a package may have zero or more provider components, where each component
5156 * provides a different widget type.
5157 * <p>
5158 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005159 *
5160 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5161 * @param packageName The package from which widget providers are white-listed.
5162 * @return Whether the package was added.
5163 *
5164 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5165 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5166 */
Robin Lee25e26452015-06-02 09:56:29 -07005167 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005168 if (mService != null) {
5169 try {
5170 return mService.addCrossProfileWidgetProvider(admin, packageName);
5171 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005172 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005173 }
5174 }
5175 return false;
5176 }
5177
5178 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005179 * Called by the profile owner of a managed profile to disable widget providers from a given
5180 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07005181 * package should have been added via {@link #addCrossProfileWidgetProvider(
5182 * android.content.ComponentName, String)}.
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 no longer
5188 * white-listed.
5189 * @return Whether the package was removed.
5190 *
5191 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5192 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5193 */
Esteban Talavera62399912016-01-11 15:37:55 +00005194 public boolean removeCrossProfileWidgetProvider(
5195 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005196 if (mService != null) {
5197 try {
5198 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5199 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005200 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005201 }
5202 }
5203 return false;
5204 }
5205
5206 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005207 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005208 * available in the parent profile.
5209 *
5210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5211 * @return The white-listed package list.
5212 *
5213 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5214 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5215 */
Robin Lee25e26452015-06-02 09:56:29 -07005216 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005217 if (mService != null) {
5218 try {
5219 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5220 if (providers != null) {
5221 return providers;
5222 }
5223 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005224 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005225 }
5226 }
5227 return Collections.emptyList();
5228 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005229
5230 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005231 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005232 *
5233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5234 * @param icon the bitmap to set as the photo.
5235 */
Robin Lee25e26452015-06-02 09:56:29 -07005236 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005237 try {
5238 mService.setUserIcon(admin, icon);
5239 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005240 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005241 }
5242 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005243
5244 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005245 * Called by device owners to set a local system update policy. When a new policy is set,
5246 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005247 *
Robin Lee25e26452015-06-02 09:56:29 -07005248 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5249 * components in the device owner package can set system update policies and the
5250 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005251 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005252 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005253 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005254 */
Robin Lee25e26452015-06-02 09:56:29 -07005255 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005256 if (mService != null) {
5257 try {
Robin Lee25e26452015-06-02 09:56:29 -07005258 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005259 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005260 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005261 }
5262 }
5263 }
5264
5265 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005266 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005267 *
Robin Lee25e26452015-06-02 09:56:29 -07005268 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005269 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005270 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005271 if (mService != null) {
5272 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005273 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005274 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005275 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005276 }
5277 }
5278 return null;
5279 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005280
5281 /**
5282 * Called by a device owner to disable the keyguard altogether.
5283 *
5284 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5285 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5286 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5287 * being disabled.
5288 *
5289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005290 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005291 *
5292 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005293 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005294 */
Robin Lee25e26452015-06-02 09:56:29 -07005295 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005296 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005297 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005298 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005299 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01005300 return false;
5301 }
5302 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005303
5304 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005305 * Called by device owner to disable the status bar. Disabling the status bar blocks
5306 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005307 * a single use device.
5308 *
5309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005310 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5311 *
5312 * @return {@code false} if attempting to disable the status bar failed.
5313 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005314 */
Robin Lee25e26452015-06-02 09:56:29 -07005315 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005316 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005317 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005318 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005319 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01005320 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00005321 }
5322 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005323
5324 /**
5325 * Callable by the system update service to notify device owners about pending updates.
5326 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5327 * permission.
5328 *
5329 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5330 * when the current pending update was first available. -1 if no update is available.
5331 * @hide
5332 */
5333 @SystemApi
5334 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5335 if (mService != null) {
5336 try {
5337 mService.notifyPendingSystemUpdate(updateReceivedTime);
5338 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01005340 }
5341 }
5342 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005343
5344 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005345 * Called by profile or device owners to set the default response for future runtime permission
5346 * requests by applications. The policy can allow for normal operation which prompts the
5347 * user to grant a permission, or can allow automatic granting or denying of runtime
5348 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005349 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5350 * the permission grant state via {@link #setPermissionGrantState}.
5351 *
5352 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005353 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005354 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005355 * @param admin Which profile or device owner this request is associated with.
5356 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5357 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005358 *
5359 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005360 */
Robin Lee25e26452015-06-02 09:56:29 -07005361 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005362 try {
5363 mService.setPermissionPolicy(admin, policy);
5364 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005365 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005366 }
5367 }
5368
5369 /**
5370 * Returns the current runtime permission policy set by the device or profile owner. The
5371 * default is {@link #PERMISSION_POLICY_PROMPT}.
5372 * @param admin Which profile or device owner this request is associated with.
5373 * @return the current policy for future permission requests.
5374 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005375 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005376 try {
5377 return mService.getPermissionPolicy(admin);
5378 } catch (RemoteException re) {
5379 return PERMISSION_POLICY_PROMPT;
5380 }
5381 }
5382
5383 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005384 * Sets the grant state of a runtime permission for a specific application. The state
5385 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5386 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5387 * is denied and the user cannot manage it through the UI, and {@link
5388 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5389 * user cannot manage it through the UI. This might affect all permissions in a
5390 * group that the runtime permission belongs to. This method can only be called
5391 * by a profile or device owner.
5392 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005393 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5394 * revoke the permission. It retains the previous grant, if any.
5395 *
5396 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005397 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005398 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005399 * @param admin Which profile or device owner this request is associated with.
5400 * @param packageName The application to grant or revoke a permission to.
5401 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005402 * @param grantState The permission grant state which is one of {@link
5403 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5404 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5405 * @return whether the permission was successfully granted or revoked.
5406 *
5407 * @see #PERMISSION_GRANT_STATE_DENIED
5408 * @see #PERMISSION_GRANT_STATE_DEFAULT
5409 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005410 */
Robin Lee25e26452015-06-02 09:56:29 -07005411 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005412 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005413 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005414 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005415 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005416 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005417 return false;
5418 }
5419 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005420
5421 /**
5422 * Returns the current grant state of a runtime permission for a specific application.
5423 *
5424 * @param admin Which profile or device owner this request is associated with.
5425 * @param packageName The application to check the grant state for.
5426 * @param permission The permission to check for.
5427 * @return the current grant state specified by device policy. If the profile or device owner
5428 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5429 * This does not indicate whether or not the permission is currently granted for the package.
5430 *
5431 * <p/>If a grant state was set by the profile or device owner, then the return value will
5432 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5433 * which indicates if the permission is currently denied or granted.
5434 *
5435 * @see #setPermissionGrantState(ComponentName, String, String, int)
5436 * @see PackageManager#checkPermission(String, String)
5437 */
Robin Lee25e26452015-06-02 09:56:29 -07005438 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005439 String permission) {
5440 try {
5441 return mService.getPermissionGrantState(admin, packageName, permission);
5442 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005443 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005444 return PERMISSION_GRANT_STATE_DEFAULT;
5445 }
5446 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005447
5448 /**
5449 * Returns if provisioning a managed profile or device is possible or not.
5450 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5451 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5452 * Note that even if this method returns true, there is a slight possibility that the
5453 * provisioning will not be allowed when it is actually initiated because some event has
5454 * happened in between.
5455 * @return if provisioning a managed profile or device is possible or not.
5456 * @throws IllegalArgumentException if the supplied action is not valid.
5457 */
5458 public boolean isProvisioningAllowed(String action) {
5459 try {
5460 return mService.isProvisioningAllowed(action);
5461 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005462 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005463 return false;
5464 }
5465 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005466
5467 /**
5468 * @hide
5469 * Return if this user is a managed profile of another user. An admin can become the profile
5470 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5471 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5472 * @param admin Which profile owner this request is associated with.
5473 * @return if this user is a managed profile of another user.
5474 */
5475 public boolean isManagedProfile(@NonNull ComponentName admin) {
5476 try {
5477 return mService.isManagedProfile(admin);
5478 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005479 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005480 return false;
5481 }
5482 }
5483
5484 /**
5485 * @hide
5486 * Return if this user is a system-only user. An admin can manage a device from a system only
5487 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5488 * @param admin Which device owner this request is associated with.
5489 * @return if this user is a system-only user.
5490 */
5491 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5492 try {
5493 return mService.isSystemOnlyUser(admin);
5494 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005495 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005496 return false;
5497 }
5498 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005499
5500 /**
5501 * Called by device owner to get the MAC address of the Wi-Fi device.
5502 *
5503 * @return the MAC address of the Wi-Fi device, or null when the information is not
5504 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5505 *
5506 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5507 */
5508 public String getWifiMacAddress() {
5509 try {
5510 return mService.getWifiMacAddress();
5511 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005512 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005513 return null;
5514 }
5515 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005516
5517 /**
5518 * Called by device owner to reboot the device.
5519 */
5520 public void reboot(@NonNull ComponentName admin) {
5521 try {
5522 mService.reboot(admin);
5523 } catch (RemoteException re) {
5524 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5525 }
5526 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005527
5528 /**
5529 * Called by a device admin to set the short support message. This will
5530 * be displayed to the user in settings screens where funtionality has
5531 * been disabled by the admin.
5532 *
5533 * The message should be limited to a short statement such as
5534 * "This setting is disabled by your administrator. Contact someone@example.com
5535 * for support."
5536 * If the message is longer than 200 characters it may be truncated.
5537 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005538 * <p>If the short support message needs to be localized, it is the responsibility of the
5539 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5540 * and set a new version of this string accordingly.
5541 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005542 * @see #setLongSupportMessage
5543 *
5544 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5545 * @param message Short message to be displayed to the user in settings or null to
5546 * clear the existing message.
5547 */
5548 public void setShortSupportMessage(@NonNull ComponentName admin,
5549 @Nullable String message) {
5550 if (mService != null) {
5551 try {
5552 mService.setShortSupportMessage(admin, message);
5553 } catch (RemoteException e) {
5554 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5555 }
5556 }
5557 }
5558
5559 /**
5560 * Called by a device admin to get the short support message.
5561 *
5562 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5563 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5564 * or null if no message has been set.
5565 */
5566 public String getShortSupportMessage(@NonNull ComponentName admin) {
5567 if (mService != null) {
5568 try {
5569 return mService.getShortSupportMessage(admin);
5570 } catch (RemoteException e) {
5571 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5572 }
5573 }
5574 return null;
5575 }
5576
5577 /**
5578 * Called by a device admin to set the long support message. This will
5579 * be displayed to the user in the device administators settings screen.
5580 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005581 * <p>If the long support message needs to be localized, it is the responsibility of the
5582 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5583 * and set a new version of this string accordingly.
5584 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005585 * @see #setShortSupportMessage
5586 *
5587 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5588 * @param message Long message to be displayed to the user in settings or null to
5589 * clear the existing message.
5590 */
5591 public void setLongSupportMessage(@NonNull ComponentName admin,
5592 @Nullable String message) {
5593 if (mService != null) {
5594 try {
5595 mService.setLongSupportMessage(admin, message);
5596 } catch (RemoteException e) {
5597 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5598 }
5599 }
5600 }
5601
5602 /**
5603 * Called by a device admin to get the long support message.
5604 *
5605 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5606 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5607 * or null if no message has been set.
5608 */
5609 public String getLongSupportMessage(@NonNull ComponentName admin) {
5610 if (mService != null) {
5611 try {
5612 return mService.getLongSupportMessage(admin);
5613 } catch (RemoteException e) {
5614 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5615 }
5616 }
5617 return null;
5618 }
5619
5620 /**
5621 * Called by the system to get the short support message.
5622 *
5623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5624 * @param userHandle user id the admin is running as.
5625 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5626 *
5627 * @hide
5628 */
5629 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5630 if (mService != null) {
5631 try {
5632 return mService.getShortSupportMessageForUser(admin, userHandle);
5633 } catch (RemoteException e) {
5634 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5635 }
5636 }
5637 return null;
5638 }
5639
5640
5641 /**
5642 * Called by the system to get the long support message.
5643 *
5644 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5645 * @param userHandle user id the admin is running as.
5646 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5647 *
5648 * @hide
5649 */
5650 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5651 if (mService != null) {
5652 try {
5653 return mService.getLongSupportMessageForUser(admin, userHandle);
5654 } catch (RemoteException e) {
5655 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5656 }
5657 }
5658 return null;
5659 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005660
5661 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005662 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5663 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005664 *
5665 * <p> Note only some methods will work on the parent Manager.
5666 *
5667 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5668 */
5669 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5670 try {
5671 if (!mService.isManagedProfile(admin)) {
5672 throw new SecurityException("The current user does not have a parent profile.");
5673 }
5674 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005675 } catch (RemoteException e) {
5676 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5677 return null;
5678 }
5679 }
5680
5681 /**
5682 * Called by device owner to control the device logging feature. Logging can only be
5683 * enabled on single user devices where the sole user is managed by the device owner.
5684 *
5685 * <p> Device logs contain various information intended for security auditing purposes.
5686 * See {@link SecurityEvent} for details.
5687 *
5688 * @param admin Which device owner this request is associated with.
5689 * @param enabled whether device logging should be enabled or not.
5690 * @see #retrieveDeviceLogs
5691 */
5692 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5693 try {
5694 mService.setDeviceLoggingEnabled(admin, enabled);
5695 } catch (RemoteException re) {
5696 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5697 }
5698 }
5699
5700 /**
5701 * Return whether device logging is enabled or not by the device owner.
5702 *
5703 * @param admin Which device owner this request is associated with.
5704 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5705 */
5706 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5707 try {
5708 return mService.getDeviceLoggingEnabled(admin);
5709 } catch (RemoteException re) {
5710 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5711 return false;
5712 }
5713 }
5714
5715 /**
5716 * Called by device owner to retrieve all new device logging entries since the last call to
5717 * this API after device boots.
5718 *
5719 * <p> Access to the logs is rate limited and it will only return new logs after the device
5720 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5721 *
5722 * @param admin Which device owner this request is associated with.
5723 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5724 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5725 */
5726 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5727 try {
5728 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5729 if (list != null) {
5730 return list.getList();
5731 } else {
5732 // Rate limit exceeded.
5733 return null;
5734 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005735 } catch (RemoteException re) {
5736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5737 return null;
5738 }
5739 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005740
5741 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005742 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5743 * profile.
5744 *
5745 * @hide
5746 */
5747 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5748 mContext.checkSelfPermission(
5749 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5750 if (!uInfo.isManagedProfile()) {
5751 throw new SecurityException("The user " + uInfo.id
5752 + " does not have a parent profile.");
5753 }
5754 return new DevicePolicyManager(mContext, true);
5755 }
5756
5757 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005758 * Called by device owners to retrieve device logs from before the device's last reboot.
5759 *
5760 * <p>
5761 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5762 * corruption-free during power cycles, due to hardware variations and limitations. As a
5763 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5764 * </strong>
5765 *
5766 * @param admin Which device owner this request is associated with.
5767 * @return Device logs from before the latest reboot of the system.
5768 */
5769 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5770 try {
5771 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5772 return list.getList();
5773 } catch (RemoteException re) {
5774 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5775 return Collections.<SecurityEvent>emptyList();
5776 }
5777 }
5778
5779 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005780 * Called by a profile owner of a managed profile to set the color used for customization.
5781 * This color is used as background color of the confirm credentials screen for that user.
5782 * The default color is {@link android.graphics.Color#GRAY}.
5783 *
5784 * <p>The confirm credentials screen can be created using
5785 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5786 *
5787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5788 * @param color The 32bit representation of the color to be used.
5789 */
5790 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5791 try {
5792 mService.setOrganizationColor(admin, color);
5793 } catch (RemoteException re) {
5794 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5795 }
5796 }
5797
5798 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005799 * @hide
5800 *
5801 * Sets the color used for customization.
5802 *
5803 * @param color The 32bit representation of the color to be used.
5804 * @param userId which user to set the color to.
5805 * @RequiresPermission(allOf = {
5806 * Manifest.permission.MANAGE_USERS,
5807 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5808 */
5809 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5810 try {
5811 mService.setOrganizationColorForUser(color, userId);
5812 } catch (RemoteException re) {
5813 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5814 }
5815 }
5816
5817 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005818 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5819 * This color is used as background color of the confirm credentials screen for that user.
5820 *
5821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5822 * @return The 32bit representation of the color to be used.
5823 */
5824 public int getOrganizationColor(@NonNull ComponentName admin) {
5825 try {
5826 return mService.getOrganizationColor(admin);
5827 } catch (RemoteException re) {
5828 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5829 return 0;
5830 }
5831 }
5832
5833 /**
5834 * @hide
5835 * Retrieve the customization color for a given user.
5836 *
5837 * @param userHandle The user id of the user we're interested in.
5838 * @return The 32bit representation of the color to be used.
5839 */
5840 public int getOrganizationColorForUser(int userHandle) {
5841 try {
5842 return mService.getOrganizationColorForUser(userHandle);
5843 } catch (RemoteException re) {
5844 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5845 return 0;
5846 }
5847 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005848
5849 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005850 * Called by a profile owner of a managed profile to set the name of the organization under
5851 * management.
5852 *
5853 * <p>If the organization name needs to be localized, it is the responsibility of the
5854 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5855 * and set a new version of this string accordingly.
5856 *
5857 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5858 * @param title The organization name or {@code null} to clear a previously set name.
5859 */
5860 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5861 try {
5862 mService.setOrganizationName(admin, title);
5863 } catch (RemoteException re) {
5864 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5865 }
5866 }
5867
5868 /**
5869 * Called by a profile owner of a managed profile to retrieve the name of the organization
5870 * under management.
5871 *
5872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5873 * @return The organization name or {@code null} if none is set.
5874 */
5875 public String getOrganizationName(@NonNull ComponentName admin) {
5876 try {
5877 return mService.getOrganizationName(admin);
5878 } catch (RemoteException re) {
5879 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5880 return null;
5881 }
5882 }
5883
5884 /**
5885 * Retrieve the default title message used in the confirm credentials screen for a given user.
5886 *
5887 * @param userHandle The user id of the user we're interested in.
5888 * @return The organization name or {@code null} if none is set.
5889 *
5890 * @hide
5891 */
5892 public String getOrganizationNameForUser(int userHandle) {
5893 try {
5894 return mService.getOrganizationNameForUser(userHandle);
5895 } catch (RemoteException re) {
5896 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5897 return null;
5898 }
5899 }
5900
5901 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005902 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5903 * return {@link #STATE_USER_UNMANAGED}
5904 * @hide
5905 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00005906 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00005907 @UserProvisioningState
5908 public int getUserProvisioningState() {
5909 if (mService != null) {
5910 try {
5911 return mService.getUserProvisioningState();
5912 } catch (RemoteException e) {
5913 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5914 }
5915 }
5916 return STATE_USER_UNMANAGED;
5917 }
5918
5919 /**
5920 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5921 *
5922 * @param state to store
5923 * @param userHandle for user
5924 * @hide
5925 */
5926 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5927 if (mService != null) {
5928 try {
5929 mService.setUserProvisioningState(state, userHandle);
5930 } catch (RemoteException e) {
5931 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5932 }
5933 }
5934 }
5935
5936 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005937 * @hide
5938 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5939 * affiliated if it is managed by the same entity as the device.
5940 *
5941 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5942 * user/profile is considered affiliated if the following conditions are both met:
5943 * <ul>
5944 * <li>The device owner and the user's/profile's profile owner have called this method,
5945 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5946 * and a profile owner intersect, they must have come from the same source, which means that
5947 * the device owner and profile owner are controlled by the same entity.</li>
5948 * <li>The device owner's and profile owner's package names are the same.</li>
5949 * </ul>
5950 *
5951 * @param admin Which profile or device owner this request is associated with.
5952 * @param ids A set of opaque affiliation ids.
5953 */
5954 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5955 try {
5956 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5957 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00005958 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005959 }
5960 }
5961
5962 /**
5963 * @hide
5964 * Returns whether this user/profile is affiliated with the device. See
5965 * {@link #setAffiliationIds} for the definition of affiliation.
5966 *
5967 * @return whether this user/profile is affiliated with the device.
5968 */
5969 public boolean isAffiliatedUser() {
5970 try {
5971 return mService != null && mService.isAffiliatedUser();
5972 } catch (RemoteException e) {
Esteban Talaverac1c83592016-02-17 17:56:15 +00005973 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005974 return false;
5975 }
5976 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005977
5978 /**
5979 * @hide
5980 * Returns whether the uninstall for {@code packageName} for the current user is in queue
5981 * to be started
5982 * @param packageName the package to check for
5983 * @return whether the uninstall intent for {@code packageName} is pending
5984 */
5985 public boolean isUninstallInQueue(String packageName) {
5986 try {
5987 return mService.isUninstallInQueue(packageName);
5988 } catch (RemoteException re) {
5989 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5990 return false;
5991 }
5992 }
5993
5994 /**
5995 * @hide
5996 * @param packageName the package containing active DAs to be uninstalled
5997 */
5998 public void uninstallPackageWithActiveAdmins(String packageName) {
5999 try {
6000 mService.uninstallPackageWithActiveAdmins(packageName);
6001 } catch (RemoteException re) {
6002 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
6003 }
6004 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006005}