blob: 53a6351b36e6e78942c17b8c4d2af4a17618d67a [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
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000103 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000104 this(context,
105 IDevicePolicyManager.Stub.asInterface(
106 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
107 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108 }
109
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800110 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000112 protected DevicePolicyManager(
113 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 mContext = context;
115 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000116 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 }
118
119 /** @hide */
120 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000121 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800122 return me.mService != null ? me : null;
123 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700124
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700125 /** @hide test will override it. */
126 @VisibleForTesting
127 protected int myUserId() {
128 return UserHandle.myUserId();
129 }
130
Dianne Hackbornd6847842010-01-12 18:14:19 -0800131 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 * <p>A managed profile allows data separation for example for the usage of a
135 * device as a personal and corporate device. The user which provisioning is started from and
136 * the managed profile share a launcher.
137 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800138 * <p>This intent will typically be sent by a mobile device management application (MDM).
139 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
140 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100141 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000142 * <p>It is possible to check if provisioning is allowed or not by querying the method
143 * {@link #isProvisioningAllowed(String)}.
144 *
145 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000146 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700147 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000148 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
149 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000150 *
151 * <p> The intent may also contain the following extras:
152 * <ul>
153 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
154 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
155 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000157 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
158 * in the provisioning intent. The
159 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
160 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
161 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100162 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100163 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
164 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100165 *
166 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
167 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
168 * the provisioning flow was successful, although this doesn't guarantee the full flow will
169 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
170 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000171 */
172 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
173 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100174 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000175
176 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000177 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000178 * Activity action: Starts the provisioning flow which sets up a managed user.
179 *
180 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800181 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000182 * owner who has full control over the user. Provisioning can only happen before user setup has
183 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
184 * allowed.
185 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000186 * <p>This intent should contain the extra
187 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000188 *
189 * <p> If provisioning fails, the device returns to its previous state.
190 *
191 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
192 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
193 * the provisioning flow was successful, although this doesn't guarantee the full flow will
194 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
195 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000196 */
197 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
198 public static final String ACTION_PROVISION_MANAGED_USER
199 = "android.app.action.PROVISION_MANAGED_USER";
200
201 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100202 * Activity action: Starts the provisioning flow which sets up a managed device.
203 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
204 *
205 * <p> During device owner provisioning a device admin app is set as the owner of the device.
206 * A device owner has full control over the device. The device owner can not be modified by the
207 * user.
208 *
209 * <p> A typical use case would be a device that is owned by a company, but used by either an
210 * employee or client.
211 *
212 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000213 * It is possible to check if provisioning is allowed or not by querying the method
214 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100215 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000216 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100217 * <ul>
218 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
219 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
220 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100221 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000222 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000223 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100224 * </ul>
225 *
226 * <p> When device owner provisioning has completed, an intent of the type
227 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
228 * device owner.
229 *
230 * <p> If provisioning fails, the device is factory reset.
231 *
Alan Treadway4582f812015-07-28 11:49:35 +0100232 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
233 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
234 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
235 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100236 */
237 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
238 public static final String ACTION_PROVISION_MANAGED_DEVICE
239 = "android.app.action.PROVISION_MANAGED_DEVICE";
240
241 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000242 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000243 *
244 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
245 * the device. A device owner has full control over the device. The device owner can not be
246 * modified by the user and the only way of resetting the device is via factory reset.
247 *
248 * <p>A typical use case would be a device that is owned by a company, but used by either an
249 * employee or client.
250 *
251 * <p>The provisioning message should be sent to an unprovisioned device.
252 *
253 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
254 * by a privileged app with the permission
255 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
256 *
257 * <p>The provisioning intent contains the following properties:
258 * <ul>
259 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
260 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
261 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
263 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
275 *
276 * @hide
277 */
278 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
279 @SystemApi
280 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
281 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
282
283 /**
284 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000285 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
286 *
287 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
288 * management state that is distinct from that reached by
289 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
290 * user, and only has control over device-wide policies, not individual users and their data.
291 * The primary benefit is that multiple non-system users are supported when provisioning using
292 * this form of device management.
293 *
294 * <p> During device owner provisioning a device admin app is set as the owner of the device.
295 * A device owner has full control over the device. The device owner can not be modified by the
296 * user.
297 *
298 * <p> A typical use case would be a device that is owned by a company, but used by either an
299 * employee or client.
300 *
301 * <p> An intent with this action can be sent only on an unprovisioned device.
302 * It is possible to check if provisioning is allowed or not by querying the method
303 * {@link #isProvisioningAllowed(String)}.
304 *
305 * <p>The intent contains the following extras:
306 * <ul>
307 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
308 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
310 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
311 * </ul>
312 *
313 * <p> When device owner provisioning has completed, an intent of the type
314 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
315 * device owner.
316 *
317 * <p> If provisioning fails, the device is factory reset.
318 *
319 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
320 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
321 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
322 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
323 *
324 * @hide
325 */
326 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
327 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
328 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
329
330 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000331 * Activity action: Finalizes management provisioning, should be used after user-setup
332 * has been completed and {@link #getUserProvisioningState()} returns one of:
333 * <ul>
334 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
335 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
336 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
337 * </ul>
338 *
339 * @hide
340 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000341 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000342 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
343 public static final String ACTION_PROVISION_FINALIZATION
344 = "android.app.action.PROVISION_FINALIZATION";
345
346 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000347 * Action: Bugreport sharing with device owner has been accepted by the user.
348 *
349 * @hide
350 */
351 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
352 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
353
354 /**
355 * Action: Bugreport sharing with device owner has been declined by the user.
356 *
357 * @hide
358 */
359 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
360 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
361
362 /**
363 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
364 *
365 * @hide
366 */
367 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
368 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
369
370 /**
371 * Extra for shared bugreport's SHA-256 hash.
372 *
373 * @hide
374 */
375 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
376 "android.intent.extra.REMOTE_BUGREPORT_HASH";
377
378 /**
379 * Extra for remote bugreport notification shown type.
380 *
381 * @hide
382 */
383 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
384 "android.app.extra.bugreport_notification_type";
385
386 /**
387 * Notification type for a started remote bugreport flow.
388 *
389 * @hide
390 */
391 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
392
393 /**
394 * Notification type for a bugreport that has already been accepted to be shared, but is still
395 * being taken.
396 *
397 * @hide
398 */
399 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
400
401 /**
402 * Notification type for a bugreport that has been taken and can be shared or declined.
403 *
404 * @hide
405 */
406 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
407
408 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100409 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100410 * allows a mobile device management application or NFC programmer application which starts
411 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100412 * <p>
413 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
414 * sends the intent to pass data to itself on the newly created profile.
415 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
416 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100417 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
418 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
419 * message should contain a stringified {@link java.util.Properties} instance, whose string
420 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
421 * management application after provisioning.
422 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100423 * <p>
424 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700425 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
426 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100427 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100428 */
429 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100430 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100431
432 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100433 * A String extra holding the package name of the mobile device management application that
434 * will be set as the profile owner or device owner.
435 *
436 * <p>If an application starts provisioning directly via an intent with action
437 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
438 * application that started provisioning. The package will be set as profile owner in that case.
439 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000440 * <p>This package is set as device owner when device owner provisioning is started by an NFC
441 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000442 *
443 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700444 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000445
446 * @see DeviceAdminReceiver
447 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100448 * supported, but only if there is only one device admin receiver in the package that requires
449 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000450 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000451 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000452 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100453 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000454
455 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000456 * A ComponentName extra indicating the device admin receiver of the mobile device management
457 * application that will be set as the profile owner or device owner and active admin.
458 *
459 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100460 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
461 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
462 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000463 *
464 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100465 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
466 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400467 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000468 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000469 *
470 * @see DeviceAdminReceiver
471 */
472 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
473 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
474
475 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000476 * An {@link android.accounts.Account} extra holding the account to migrate during managed
477 * profile provisioning. If the account supplied is present in the primary user, it will be
478 * copied, along with its credentials to the managed profile and removed from the primary user.
479 *
480 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
481 */
482
483 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
484 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
485
486 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100487 * A String extra that, holds the email address of the account which a managed profile is
488 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
489 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100490 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100491 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
492 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100493 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
494 * contains this extra, it is forwarded in the
495 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
496 * device management application that was set as the profile owner during provisioning.
497 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100498 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100499 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
500 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100501
502 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000503 * A integer extra indicating the predominant color to show during the provisioning.
504 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000505 *
506 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
507 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
508 */
509 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
510 "android.app.extra.PROVISIONING_MAIN_COLOR";
511
512 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000513 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700514 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000515 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100516 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
517 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000518 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000519 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
520 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000521
522 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100523 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
524 * will be set to.
525 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000526 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
527 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100528 */
529 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100530 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100531
532 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100533 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
534 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100535 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000536 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
537 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100538 */
539 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100540 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100541
542 /**
543 * A String extra holding the {@link java.util.Locale} that the device will be set to.
544 * Format: xx_yy, where xx is the language code, and yy the country code.
545 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000546 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
547 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100548 */
549 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100550 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100551
552 /**
553 * A String extra holding the ssid of the wifi network that should be used during nfc device
554 * owner provisioning for downloading the mobile device management application.
555 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000556 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
557 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100558 */
559 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100560 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100561
562 /**
563 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
564 * is hidden or not.
565 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000566 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
567 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100568 */
569 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100570 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571
572 /**
573 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100574 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
575 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100576 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000577 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
578 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 */
580 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
584 * A String extra holding the password of the wifi network in
585 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
586 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
588 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 */
590 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100591 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592
593 /**
594 * A String extra holding the proxy host for the wifi network in
595 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100599 */
600 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602
603 /**
604 * An int extra holding the proxy port for the wifi network in
605 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
606 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000607 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
608 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 */
610 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100611 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612
613 /**
614 * A String extra holding the proxy bypass for the wifi network in
615 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
616 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000617 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
618 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 */
620 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100621 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622
623 /**
624 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
625 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
626 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000627 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
628 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 */
630 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100631 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632
633 /**
634 * A String extra holding a url that specifies the download location of the device admin
635 * package. When not provided it is assumed that the device admin package is already installed.
636 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000637 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
638 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 */
640 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100641 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642
643 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400644 * An int extra holding a minimum required version code for the device admin package. If the
645 * device admin is already installed on the device, it will only be re-downloaded from
646 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
647 * installed package is less than this version code.
648 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400649 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400650 * provisioning via an NFC bump.
651 */
652 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
653 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
654
655 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100656 * A String extra holding a http cookie header which should be used in the http request to the
657 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
658 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000659 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
660 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100661 */
662 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100663 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100664
665 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100666 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
667 * the file at download location specified in
668 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100669 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100670 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100671 * present. The provided checksum should match the checksum of the file at the download
672 * location. If the checksum doesn't match an error will be shown to the user and the user will
673 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100674 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000675 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
676 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100677 *
678 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
679 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700680 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100681 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100682 */
683 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100684 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100685
686 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100687 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100688 * android package archive at the download location specified in {@link
689 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
690 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100691 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100692 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
693 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
694 *
695 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100696 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100697 * the download location. If the checksum does not match an error will be shown to the user and
698 * the user will be asked to factory reset the device.
699 *
700 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
701 * provisioning via an NFC bump.
702 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100703 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
704 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100705
706 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000707 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
708 * has completed successfully.
709 *
710 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700711 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000712 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800713 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000714 * corresponds to the account requested to be migrated at provisioning time, if any.
715 */
716 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
717 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
718 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
719
720 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400721 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500722 * provisioning.
723 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400724 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100725 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500726 */
727 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
728 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
729
730 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000731 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
732 * provisioning. If this extra is not passed, a default image will be shown.
733 * <h5>The following URI schemes are accepted:</h5>
734 * <ul>
735 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
736 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
737 * </ul>
738 *
739 * <p> It is the responsability of the caller to provide an image with a reasonable
740 * pixed density for the device.
741 *
742 * <p> If a content: URI is passed, the intent should have the flag
743 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
744 * {@link android.content.ClipData} of the intent too.
745 *
746 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
747 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
748 */
749 public static final String EXTRA_PROVISIONING_LOGO_URI =
750 "android.app.extra.PROVISIONING_LOGO_URI";
751
752 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000753 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
754 * during setup-wizard.
755 *
756 * <p>If unspecified, defaults to {@code true} to match the behavior in
757 * {@link android.os.Build.VERSION_CODES#M} and earlier.
758 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000759 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
760 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000761 *
762 * @hide
763 */
764 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
765 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
766
767 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400768 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100769 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400770 * <p>During device owner provisioning a device admin app is set as the owner of the device.
771 * A device owner has full control over the device. The device owner can not be modified by the
772 * user and the only way of resetting the device is if the device owner app calls a factory
773 * reset.
774 *
775 * <p> A typical use case would be a device that is owned by a company, but used by either an
776 * employee or client.
777 *
778 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100779 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000780 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100781 * contains the following properties:
782 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400783 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
784 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100785 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400786 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100787 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
788 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
789 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
790 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
791 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
792 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
793 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
794 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
795 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
796 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100797 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
798 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
799 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100800 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000801 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700802 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400803 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
804 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
805 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400806 */
807 public static final String MIME_TYPE_PROVISIONING_NFC
808 = "application/com.android.managedprovisioning";
809
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100810 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800811 * Activity action: ask the user to add a new device administrator to the system.
812 * The desired policy is the ComponentName of the policy in the
813 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
814 * bring the user through adding the device administrator to the system (or
815 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700816 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800817 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
818 * field to provide the user with additional explanation (in addition
819 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800820 *
821 * <p>If your administrator is already active, this will ordinarily return immediately (without
822 * user intervention). However, if your administrator has been updated and is requesting
823 * additional uses-policy flags, the user will be presented with the new list. New policies
824 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800825 */
826 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
827 public static final String ACTION_ADD_DEVICE_ADMIN
828 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700829
Dianne Hackbornd6847842010-01-12 18:14:19 -0800830 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700831 * @hide
832 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700833 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700834 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700835 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
836 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700837 * to remotely control restrictions on the user.
838 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800839 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700840 * result of whether or not the user approved the action. If approved, the result will
841 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
842 * as a profile owner.
843 *
844 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
845 * field to provide the user with additional explanation (in addition
846 * to your component's description) about what is being added.
847 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700848 * <p>If there is already a profile owner active or the caller is not a system app, the
849 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700850 */
851 @SystemApi
852 public static final String ACTION_SET_PROFILE_OWNER
853 = "android.app.action.SET_PROFILE_OWNER";
854
855 /**
856 * @hide
857 * Name of the profile owner admin that controls the user.
858 */
859 @SystemApi
860 public static final String EXTRA_PROFILE_OWNER_NAME
861 = "android.app.extra.PROFILE_OWNER_NAME";
862
863 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100864 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700865 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700866 *
Jim Miller284b62e2010-06-08 14:27:42 -0700867 * @hide
868 */
869 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
870 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
871
872 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100873 * Broadcast action: sent when the device owner is set or changed.
874 *
875 * This broadcast is sent only to the primary user.
876 * @see #ACTION_PROVISION_MANAGED_DEVICE
877 */
878 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
879 public static final String ACTION_DEVICE_OWNER_CHANGED
880 = "android.app.action.DEVICE_OWNER_CHANGED";
881
882 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800883 * The ComponentName of the administrator component.
884 *
885 * @see #ACTION_ADD_DEVICE_ADMIN
886 */
887 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700888
Dianne Hackbornd6847842010-01-12 18:14:19 -0800889 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800890 * An optional CharSequence providing additional explanation for why the
891 * admin is being added.
892 *
893 * @see #ACTION_ADD_DEVICE_ADMIN
894 */
895 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700896
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800897 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700898 * Activity action: have the user enter a new password. This activity should
899 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
900 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
901 * enter a new password that meets the current requirements. You can use
902 * {@link #isActivePasswordSufficient()} to determine whether you need to
903 * have the user select a new password in order to meet the current
904 * constraints. Upon being resumed from this activity, you can check the new
905 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000906 *
907 * If the intent is launched from within a managed profile with a profile
908 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
909 * this will trigger entering a new password for the parent of the profile.
910 * For all other cases it will trigger entering a new password for the user
911 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000912 *
913 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800914 */
915 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
916 public static final String ACTION_SET_NEW_PASSWORD
917 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700918
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000919 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000920 * Activity action: have the user enter a new password for the parent profile.
921 * If the intent is launched from within a managed profile, this will trigger
922 * entering a new password for the parent of the profile. In all other cases
923 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
924 */
925 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
926 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
927 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
928
929 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000930 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
931 * the parent profile to access intents sent from the managed profile.
932 * That is, when an app in the managed profile calls
933 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
934 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000935 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100936 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000937
938 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000939 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
940 * the managed profile to access intents sent from the parent profile.
941 * That is, when an app in the parent profile calls
942 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
943 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000944 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100945 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700946
Dianne Hackbornd6847842010-01-12 18:14:19 -0800947 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100948 * Broadcast action: notify that a new local system update policy has been set by the device
949 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000950 */
951 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100952 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
953 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000954
Amith Yamasanid49489b2015-04-28 14:00:26 -0700955 /**
956 * Permission policy to prompt user for new permission requests for runtime permissions.
957 * Already granted or denied permissions are not affected by this.
958 */
959 public static final int PERMISSION_POLICY_PROMPT = 0;
960
961 /**
962 * Permission policy to always grant new permission requests for runtime permissions.
963 * Already granted or denied permissions are not affected by this.
964 */
965 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
966
967 /**
968 * Permission policy to always deny new permission requests for runtime permissions.
969 * Already granted or denied permissions are not affected by this.
970 */
971 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
972
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700973 /**
974 * Runtime permission state: The user can manage the permission
975 * through the UI.
976 */
977 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
978
979 /**
980 * Runtime permission state: The permission is granted to the app
981 * and the user cannot manage the permission through the UI.
982 */
983 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
984
985 /**
986 * Runtime permission state: The permission is denied to the app
987 * and the user cannot manage the permission through the UI.
988 */
989 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000990
991 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000992 * No management for current user in-effect. This is the default.
993 * @hide
994 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000995 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000996 public static final int STATE_USER_UNMANAGED = 0;
997
998 /**
999 * Management partially setup, user setup needs to be completed.
1000 * @hide
1001 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001002 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001003 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1004
1005 /**
1006 * Management partially setup, user setup completed.
1007 * @hide
1008 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001009 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001010 public static final int STATE_USER_SETUP_COMPLETE = 2;
1011
1012 /**
1013 * Management setup and active on current user.
1014 * @hide
1015 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001016 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001017 public static final int STATE_USER_SETUP_FINALIZED = 3;
1018
1019 /**
1020 * Management partially setup on a managed profile.
1021 * @hide
1022 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001023 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001024 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1025
1026 /**
1027 * @hide
1028 */
1029 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1030 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1031 @Retention(RetentionPolicy.SOURCE)
1032 public @interface UserProvisioningState {}
1033
1034 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001035 * Return true if the given administrator component is currently
1036 * active (enabled) in the system.
1037 */
Robin Lee25e26452015-06-02 09:56:29 -07001038 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001039 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001040 }
1041
1042 /**
1043 * @see #isAdminActive(ComponentName)
1044 * @hide
1045 */
Robin Lee25e26452015-06-02 09:56:29 -07001046 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001047 if (mService != null) {
1048 try {
Robin Lee25e26452015-06-02 09:56:29 -07001049 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001050 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001051 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001052 }
1053 }
1054 return false;
1055 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001056 /**
1057 * Return true if the given administrator component is currently being removed
1058 * for the user.
1059 * @hide
1060 */
Robin Lee25e26452015-06-02 09:56:29 -07001061 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001062 if (mService != null) {
1063 try {
Robin Lee25e26452015-06-02 09:56:29 -07001064 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001065 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001066 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001067 }
1068 }
1069 return false;
1070 }
1071
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001072
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 /**
Robin Lee25e26452015-06-02 09:56:29 -07001074 * Return a list of all currently active device administrators' component
1075 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001076 * returned.
1077 */
1078 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001079 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001080 }
1081
1082 /**
1083 * @see #getActiveAdmins()
1084 * @hide
1085 */
1086 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001087 if (mService != null) {
1088 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001089 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001090 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001091 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001092 }
1093 }
1094 return null;
1095 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001096
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001097 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001098 * Used by package administration code to determine if a package can be stopped
1099 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001100 * @hide
1101 */
1102 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001103 return packageHasActiveAdmins(packageName, myUserId());
1104 }
1105
1106 /**
1107 * Used by package administration code to determine if a package can be stopped
1108 * or uninstalled.
1109 * @hide
1110 */
1111 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001112 if (mService != null) {
1113 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001114 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001115 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001116 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001117 }
1118 }
1119 return false;
1120 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001121
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001122 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001123 * Remove a current administration component. This can only be called
1124 * by the application that owns the administration component; if you
1125 * try to remove someone else's component, a security exception will be
1126 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001127 *
1128 * <p>Note that the operation is not synchronous and the admin might still be active (as
1129 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001130 */
Robin Lee25e26452015-06-02 09:56:29 -07001131 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001132 if (mService != null) {
1133 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001134 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001135 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001136 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001137 }
1138 }
1139 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001140
Dianne Hackbornd6847842010-01-12 18:14:19 -08001141 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001142 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001143 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001144 * but requires additional policies after an upgrade.
1145 *
1146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1147 * an active administrator, or an exception will be thrown.
1148 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1149 */
Robin Lee25e26452015-06-02 09:56:29 -07001150 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001151 if (mService != null) {
1152 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001153 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001155 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001156 }
1157 }
1158 return false;
1159 }
1160
1161 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001162 * Returns true if the Profile Challenge is available to use for the given profile user.
1163 *
1164 * @hide
1165 */
1166 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1167 if (mService != null) {
1168 try {
1169 return mService.isSeparateProfileChallengeAllowed(userHandle);
1170 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001171 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001172 }
1173 }
1174 return false;
1175 }
1176
1177 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001178 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1179 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001180 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001181 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001182 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001183
Dianne Hackbornd6847842010-01-12 18:14:19 -08001184 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001185 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1186 * recognition technology. This implies technologies that can recognize the identity of
1187 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1188 * Note that quality constants are ordered so that higher values are more restrictive.
1189 */
1190 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1191
1192 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001193 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001194 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001195 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001196 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001197 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001198
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001199 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001200 * Constant for {@link #setPasswordQuality}: the user must have entered a
1201 * password containing at least numeric characters. Note that quality
1202 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001203 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001204 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001205
Dianne Hackbornd6847842010-01-12 18:14:19 -08001206 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001207 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001208 * password containing at least numeric characters with no repeating (4444)
1209 * or ordered (1234, 4321, 2468) sequences. Note that quality
1210 * constants are ordered so that higher values are more restrictive.
1211 */
1212 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1213
1214 /**
1215 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001216 * password containing at least alphabetic (or other symbol) characters.
1217 * Note that quality constants are ordered so that higher values are more
1218 * restrictive.
1219 */
1220 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001221
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001222 /**
1223 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001224 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001225 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001226 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001227 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001228 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001229
Dianne Hackbornd6847842010-01-12 18:14:19 -08001230 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001231 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001232 * password containing at least a letter, a numerical digit and a special
1233 * symbol, by default. With this password quality, passwords can be
1234 * restricted to contain various sets of characters, like at least an
1235 * uppercase letter, etc. These are specified using various methods,
1236 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1237 * that quality constants are ordered so that higher values are more
1238 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001239 */
1240 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1241
1242 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001243 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1244 * modify password. In case this password quality is set, the password is
1245 * managed by a profile owner. The profile owner can set any password,
1246 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1247 * that quality constants are ordered so that higher values are more
1248 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1249 * the highest.
1250 * @hide
1251 */
1252 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1253
1254 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 * Called by an application that is administering the device to set the
1256 * password restrictions it is imposing. After setting this, the user
1257 * will not be able to enter a new password that is not at least as
1258 * restrictive as what has been set. Note that the current password
1259 * will remain until the user has set a new one, so the change does not
1260 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001261 * {@link #ACTION_SET_NEW_PASSWORD} or
1262 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001263 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001264 * <p>Quality constants are ordered so that higher values are more restrictive;
1265 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001266 * the user's preference, and any other considerations) is the one that
1267 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001268 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001269 * <p>The calling device admin must have requested
1270 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1271 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001272 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001273 * <p>This method can be called on the {@link DevicePolicyManager} instance
1274 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1275 * restrictions on the parent profile.
1276 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001278 * @param quality The new desired quality. One of
1279 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001280 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1281 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1282 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001283 */
Robin Lee25e26452015-06-02 09:56:29 -07001284 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001285 if (mService != null) {
1286 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001287 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001288 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001289 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 }
1291 }
1292 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001293
Dianne Hackbornd6847842010-01-12 18:14:19 -08001294 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001295 * Retrieve the current minimum password quality for a particular admin or all admins that set
1296 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1297 * a separate challenge are not taken into account.
1298 *
1299 * <p>This method can be called on the {@link DevicePolicyManager} instance
1300 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1301 * restrictions on the parent profile.
1302 *
Robin Lee25e26452015-06-02 09:56:29 -07001303 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001304 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001305 */
Robin Lee25e26452015-06-02 09:56:29 -07001306 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001307 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001308 }
1309
1310 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001311 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001312 if (mService != null) {
1313 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001314 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001316 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001317 }
1318 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001319 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001320 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001321
Dianne Hackbornd6847842010-01-12 18:14:19 -08001322 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001323 * Called by an application that is administering the device to set the
1324 * minimum allowed password length. After setting this, the user
1325 * will not be able to enter a new password that is not at least as
1326 * restrictive as what has been set. Note that the current password
1327 * will remain until the user has set a new one, so the change does not
1328 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001329 * {@link #ACTION_SET_NEW_PASSWORD} or
1330 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Dianne Hackbornd6847842010-01-12 18:14:19 -08001331 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001332 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1333 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1334 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001335 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001336 * <p>The calling device admin must have requested
1337 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1338 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001339 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001340 * <p>This method can be called on the {@link DevicePolicyManager} instance
1341 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1342 * restrictions on the parent profile.
1343 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001344 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001345 * @param length The new desired minimum password length. A value of 0
1346 * means there is no restriction.
1347 */
Robin Lee25e26452015-06-02 09:56:29 -07001348 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001349 if (mService != null) {
1350 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001351 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001352 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001353 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001354 }
1355 }
1356 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001357
Dianne Hackbornd6847842010-01-12 18:14:19 -08001358 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001359 * Retrieve the current minimum password length for a particular admin or all admins that set
1360 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1361 * a separate challenge are not taken into account.
1362 *
1363 * <p>This method can be called on the {@link DevicePolicyManager} instance
1364 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1365 * restrictions on the parent profile.
1366 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001367 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001368 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001369 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001370 */
Robin Lee25e26452015-06-02 09:56:29 -07001371 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001372 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001373 }
1374
1375 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001376 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001377 if (mService != null) {
1378 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001379 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001380 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001381 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001382 }
1383 }
1384 return 0;
1385 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001386
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 /**
1388 * Called by an application that is administering the device to set the
1389 * minimum number of upper case letters required in the password. After
1390 * setting this, the user will not be able to enter a new password that is
1391 * not at least as restrictive as what has been set. Note that the current
1392 * password will remain until the user has set a new one, so the change does
1393 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001394 * {@link #ACTION_SET_NEW_PASSWORD} or
1395 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001396 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001397 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1398 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001399 * <p>
1400 * The calling device admin must have requested
1401 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1402 * this method; if it has not, a security exception will be thrown.
1403 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001404 * <p>This method can be called on the {@link DevicePolicyManager} instance
1405 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1406 * restrictions on the parent profile.
1407 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001408 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1409 * with.
1410 * @param length The new desired minimum number of upper case letters
1411 * required in the password. A value of 0 means there is no
1412 * restriction.
1413 */
Robin Lee25e26452015-06-02 09:56:29 -07001414 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001415 if (mService != null) {
1416 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001417 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001418 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001419 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001420 }
1421 }
1422 }
1423
1424 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001425 * Retrieve the current number of upper case letters required in the password
1426 * for a particular admin or all admins that set retrictions on this user and
1427 * its participating profiles. Restrictions on profiles that have a separate challenge
1428 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001429 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001430 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001431 * and only applies when the password quality is
1432 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001433 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001434 * <p>This method can be called on the {@link DevicePolicyManager} instance
1435 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1436 * restrictions on the parent profile.
1437 *
Robin Lee25e26452015-06-02 09:56:29 -07001438 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001439 * aggregate all admins.
1440 * @return The minimum number of upper case letters required in the
1441 * password.
1442 */
Robin Lee25e26452015-06-02 09:56:29 -07001443 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001444 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001445 }
1446
1447 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001448 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001449 if (mService != null) {
1450 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001451 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001452 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001453 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001454 }
1455 }
1456 return 0;
1457 }
1458
1459 /**
1460 * Called by an application that is administering the device to set the
1461 * minimum number of lower case letters required in the password. After
1462 * setting this, the user will not be able to enter a new password that is
1463 * not at least as restrictive as what has been set. Note that the current
1464 * password will remain until the user has set a new one, so the change does
1465 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001466 * {@link #ACTION_SET_NEW_PASSWORD} or
1467 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001468 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001469 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1470 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001471 * <p>
1472 * The calling device admin must have requested
1473 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1474 * this method; if it has not, a security exception will be thrown.
1475 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001476 * <p>This method can be called on the {@link DevicePolicyManager} instance
1477 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1478 * restrictions on the parent profile.
1479 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001480 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1481 * with.
1482 * @param length The new desired minimum number of lower case letters
1483 * required in the password. A value of 0 means there is no
1484 * restriction.
1485 */
Robin Lee25e26452015-06-02 09:56:29 -07001486 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001487 if (mService != null) {
1488 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001489 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001491 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001492 }
1493 }
1494 }
1495
1496 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001497 * Retrieve the current number of lower case letters required in the password
1498 * for a particular admin or all admins that set retrictions on this user
1499 * and its participating profiles. Restrictions on profiles that have
1500 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001501 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001502 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001503 * and only applies when the password quality is
1504 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001505 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001506 * <p>This method can be called on the {@link DevicePolicyManager} instance
1507 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1508 * restrictions on the parent profile.
1509 *
Robin Lee25e26452015-06-02 09:56:29 -07001510 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001511 * aggregate all admins.
1512 * @return The minimum number of lower case letters required in the
1513 * password.
1514 */
Robin Lee25e26452015-06-02 09:56:29 -07001515 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001516 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001517 }
1518
1519 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001520 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001521 if (mService != null) {
1522 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001523 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001525 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001526 }
1527 }
1528 return 0;
1529 }
1530
1531 /**
1532 * Called by an application that is administering the device to set the
1533 * minimum number of letters required in the password. After setting this,
1534 * the user will not be able to enter a new password that is not at least as
1535 * restrictive as what has been set. Note that the current password will
1536 * remain until the user has set a new one, so the change does not take
1537 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001538 * {@link #ACTION_SET_NEW_PASSWORD} or
1539 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001540 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001541 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1542 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001543 * <p>
1544 * The calling device admin must have requested
1545 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1546 * this method; if it has not, a security exception will be thrown.
1547 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001548 * <p>This method can be called on the {@link DevicePolicyManager} instance
1549 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1550 * restrictions on the parent profile.
1551 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001552 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1553 * with.
1554 * @param length The new desired minimum number of letters required in the
1555 * password. A value of 0 means there is no restriction.
1556 */
Robin Lee25e26452015-06-02 09:56:29 -07001557 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001558 if (mService != null) {
1559 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001560 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001562 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001563 }
1564 }
1565 }
1566
1567 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001568 * Retrieve the current number of letters required in the password
1569 * for a particular admin or all admins that set retrictions on this user
1570 * and its participating profiles. Restrictions on profiles that have
1571 * a separate challenge are not taken into account.
1572 * This is the same value as set by
1573 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001574 * and only applies when the password quality is
1575 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001576 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001577 * <p>This method can be called on the {@link DevicePolicyManager} instance
1578 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1579 * restrictions on the parent profile.
1580 *
Robin Lee25e26452015-06-02 09:56:29 -07001581 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001582 * aggregate all admins.
1583 * @return The minimum number of letters required in the password.
1584 */
Robin Lee25e26452015-06-02 09:56:29 -07001585 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001586 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001587 }
1588
1589 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001590 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001591 if (mService != null) {
1592 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001593 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001594 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001595 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001596 }
1597 }
1598 return 0;
1599 }
1600
1601 /**
1602 * Called by an application that is administering the device to set the
1603 * minimum number of numerical digits required in the password. After
1604 * setting this, the user will not be able to enter a new password that is
1605 * not at least as restrictive as what has been set. Note that the current
1606 * password will remain until the user has set a new one, so the change does
1607 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001608 * {@link #ACTION_SET_NEW_PASSWORD} or
1609 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001610 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001611 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1612 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001613 * <p>
1614 * The calling device admin must have requested
1615 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1616 * this method; if it has not, a security exception will be thrown.
1617 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001618 * <p>This method can be called on the {@link DevicePolicyManager} instance
1619 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1620 * restrictions on the parent profile.
1621 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001622 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1623 * with.
1624 * @param length The new desired minimum number of numerical digits required
1625 * in the password. A value of 0 means there is no restriction.
1626 */
Robin Lee25e26452015-06-02 09:56:29 -07001627 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001628 if (mService != null) {
1629 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001630 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001631 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001632 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001633 }
1634 }
1635 }
1636
1637 /**
1638 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001639 * for a particular admin or all admins that set retrictions on this user
1640 * and its participating profiles. Restrictions on profiles that have
1641 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001642 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001643 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001644 * and only applies when the password quality is
1645 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001646 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001647 * <p>This method can be called on the {@link DevicePolicyManager} instance
1648 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1649 * restrictions on the parent profile.
1650 *
Robin Lee25e26452015-06-02 09:56:29 -07001651 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001652 * aggregate all admins.
1653 * @return The minimum number of numerical digits required in the password.
1654 */
Robin Lee25e26452015-06-02 09:56:29 -07001655 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001656 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001657 }
1658
1659 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001660 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001661 if (mService != null) {
1662 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001663 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001664 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001665 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001666 }
1667 }
1668 return 0;
1669 }
1670
1671 /**
1672 * Called by an application that is administering the device to set the
1673 * minimum number of symbols required in the password. After setting this,
1674 * the user will not be able to enter a new password that is not at least as
1675 * restrictive as what has been set. Note that the current password will
1676 * remain until the user has set a new one, so the change does not take
1677 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001678 * {@link #ACTION_SET_NEW_PASSWORD} or
1679 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001680 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001681 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1682 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001683 * <p>
1684 * The calling device admin must have requested
1685 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1686 * this method; if it has not, a security exception will be thrown.
1687 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001688 * <p>This method can be called on the {@link DevicePolicyManager} instance
1689 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1690 * restrictions on the parent profile.
1691 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001692 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1693 * with.
1694 * @param length The new desired minimum number of symbols required in the
1695 * password. A value of 0 means there is no restriction.
1696 */
Robin Lee25e26452015-06-02 09:56:29 -07001697 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001698 if (mService != null) {
1699 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001700 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001701 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001702 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001703 }
1704 }
1705 }
1706
1707 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001708 * Retrieve the current number of symbols required in the password
1709 * for a particular admin or all admins that set retrictions on this user
1710 * and its participating profiles. Restrictions on profiles that have
1711 * a separate challenge are not taken into account. This is the same value as
1712 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001713 * and only applies when the password quality is
1714 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001715 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001716 * <p>This method can be called on the {@link DevicePolicyManager} instance
1717 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1718 * restrictions on the parent profile.
1719 *
Robin Lee25e26452015-06-02 09:56:29 -07001720 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001721 * aggregate all admins.
1722 * @return The minimum number of symbols required in the password.
1723 */
Robin Lee25e26452015-06-02 09:56:29 -07001724 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001725 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001726 }
1727
1728 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001729 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001730 if (mService != null) {
1731 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001732 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001733 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001734 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001735 }
1736 }
1737 return 0;
1738 }
1739
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001740 /**
1741 * Called by an application that is administering the device to set the
1742 * minimum number of non-letter characters (numerical digits or symbols)
1743 * required in the password. After setting this, the user will not be able
1744 * to enter a new password that is not at least as restrictive as what has
1745 * been set. Note that the current password will remain until the user has
1746 * set a new one, so the change does not take place immediately. To prompt
Esteban Talaverac1c83592016-02-17 17:56:15 +00001747 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1748 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001749 * setting this value. This constraint is only imposed if the administrator
1750 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1751 * {@link #setPasswordQuality}. The default value is 0.
1752 * <p>
1753 * The calling device admin must have requested
1754 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1755 * this method; if it has not, a security exception will be thrown.
1756 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001757 * <p>This method can be called on the {@link DevicePolicyManager} instance
1758 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1759 * restrictions on the parent profile.
1760 *
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001761 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1762 * with.
1763 * @param length The new desired minimum number of letters required in the
1764 * password. A value of 0 means there is no restriction.
1765 */
Robin Lee25e26452015-06-02 09:56:29 -07001766 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001767 if (mService != null) {
1768 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001769 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001770 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001771 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001772 }
1773 }
1774 }
1775
1776 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001777 * Retrieve the current number of non-letter characters required in the password
1778 * for a particular admin or all admins that set retrictions on this user
1779 * and its participating profiles. Restrictions on profiles that have
1780 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001781 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001782 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001783 * and only applies when the password quality is
1784 * {@link #PASSWORD_QUALITY_COMPLEX}.
1785 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001786 * <p>This method can be called on the {@link DevicePolicyManager} instance
1787 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1788 * restrictions on the parent profile.
1789 *
Robin Lee25e26452015-06-02 09:56:29 -07001790 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001791 * aggregate all admins.
1792 * @return The minimum number of letters required in the password.
1793 */
Robin Lee25e26452015-06-02 09:56:29 -07001794 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001795 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001796 }
1797
1798 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001799 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001800 if (mService != null) {
1801 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001802 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001803 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001804 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001805 }
1806 }
1807 return 0;
1808 }
1809
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001810 /**
1811 * Called by an application that is administering the device to set the length
1812 * of the password history. After setting this, the user will not be able to
1813 * enter a new password that is the same as any password in the history. Note
1814 * that the current password will remain until the user has set a new one, so
1815 * the change does not take place immediately. To prompt the user for a new
Esteban Talaverac1c83592016-02-17 17:56:15 +00001816 * password, use {@link #ACTION_SET_NEW_PASSWORD} or
1817 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001818 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001819 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1820 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1821 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001822 *
1823 * <p>
1824 * The calling device admin must have requested
1825 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1826 * method; if it has not, a security exception will be thrown.
1827 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001828 * <p>This method can be called on the {@link DevicePolicyManager} instance
1829 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1830 * restrictions on the parent profile.
1831 *
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001832 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1833 * with.
1834 * @param length The new desired length of password history. A value of 0
1835 * means there is no restriction.
1836 */
Robin Lee25e26452015-06-02 09:56:29 -07001837 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001838 if (mService != null) {
1839 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001840 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001841 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001842 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001843 }
1844 }
1845 }
1846
1847 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001848 * Called by a device admin to set the password expiration timeout. Calling this method
1849 * will restart the countdown for password expiration for the given admin, as will changing
1850 * the device password (for all admins).
1851 *
1852 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1853 * For example, to have the password expire 5 days from now, timeout would be
1854 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1855 *
1856 * <p>To disable password expiration, a value of 0 may be used for timeout.
1857 *
Jim Millera4e28d12010-11-08 16:15:47 -08001858 * <p>The calling device admin must have requested
1859 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1860 * method; if it has not, a security exception will be thrown.
1861 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001862 * <p> Note that setting the password will automatically reset the expiration time for all
1863 * active admins. Active admins do not need to explicitly call this method in that case.
1864 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001865 * <p>This method can be called on the {@link DevicePolicyManager} instance
1866 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1867 * restrictions on the parent profile.
1868 *
Jim Millera4e28d12010-11-08 16:15:47 -08001869 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1870 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1871 * means there is no restriction (unlimited).
1872 */
Robin Lee25e26452015-06-02 09:56:29 -07001873 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001874 if (mService != null) {
1875 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001876 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001877 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001878 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001879 }
1880 }
1881 }
1882
1883 /**
Jim Miller6b857682011-02-16 16:27:41 -08001884 * Get the password expiration timeout for the given admin. The expiration timeout is the
1885 * recurring expiration timeout provided in the call to
1886 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001887 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1888 * have set restrictions on profiles that have a separate challenge are not taken into account.
1889 *
1890 * <p>This method can be called on the {@link DevicePolicyManager} instance
1891 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1892 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001893 *
Robin Lee25e26452015-06-02 09:56:29 -07001894 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001895 * @return The timeout for the given admin or the minimum of all timeouts
1896 */
Robin Lee25e26452015-06-02 09:56:29 -07001897 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001898 if (mService != null) {
1899 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001900 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001902 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001903 }
1904 }
1905 return 0;
1906 }
1907
1908 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001909 * Get the current password expiration time for a particular admin or all admins that set
1910 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1911 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1912 * of all expiration times is returned - which will be the minimum of all of them.
1913 *
1914 * <p>This method can be called on the {@link DevicePolicyManager} instance
1915 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1916 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001917 *
Robin Lee25e26452015-06-02 09:56:29 -07001918 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001919 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001920 */
Robin Lee25e26452015-06-02 09:56:29 -07001921 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001922 if (mService != null) {
1923 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001924 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001925 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001926 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001927 }
1928 }
1929 return 0;
1930 }
1931
1932 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001933 * Retrieve the current password history length for a particular admin or all admins that
1934 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1935 * have a separate challenge are not taken into account.
1936 *
1937 * <p>This method can be called on the {@link DevicePolicyManager} instance
1938 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1939 * restrictions on the parent profile.
1940 *
Robin Lee25e26452015-06-02 09:56:29 -07001941 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001942 * all admins.
1943 * @return The length of the password history
1944 */
Robin Lee25e26452015-06-02 09:56:29 -07001945 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001946 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001947 }
1948
1949 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001950 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001951 if (mService != null) {
1952 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001953 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001954 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001955 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001956 }
1957 }
1958 return 0;
1959 }
1960
Dianne Hackbornd6847842010-01-12 18:14:19 -08001961 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001962 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001963 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001964 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001965 * @return Returns the maximum length that the user can enter.
1966 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001967 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001968 // Kind-of arbitrary.
1969 return 16;
1970 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001971
Dianne Hackborn254cb442010-01-27 19:23:59 -08001972 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001973 * Determine whether the current password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001974 * to meet the policy requirements (e.g. quality, minimum length) that have been
1975 * requested by the admins of this user and its participating profiles.
1976 * Restrictions on profiles that have a separate challenge are not taken into account.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001977 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001978 * <p>The calling device admin must have requested
1979 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1980 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001981 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001982 * <p>This method can be called on the {@link DevicePolicyManager} instance
1983 * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine
1984 * if the password set on the parent profile is sufficient.
1985 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001986 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001987 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001988 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001989 if (mService != null) {
1990 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001991 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001993 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001994 }
1995 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001996 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001997 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001998
Dianne Hackbornd6847842010-01-12 18:14:19 -08001999 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002000 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002001 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002002 * requested by the admins of the parent user and its profiles.
2003 *
2004 * @param userHandle the userId of the profile to check the password for.
2005 * @return Returns true if the password would meet the current requirements, else false.
2006 * @hide
2007 */
2008 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2009 if (mService != null) {
2010 try {
2011 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002013 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002014 }
2015 }
2016 return false;
2017 }
2018
2019 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002020 * Retrieve the number of times the user has failed at entering a
2021 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002022 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002023 * <p>This method can be called on the {@link DevicePolicyManager} instance
2024 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2025 * the number of failed password attemts for the parent user.
2026 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002027 * <p>The calling device admin must have requested
2028 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
2029 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002030 */
2031 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002032 return getCurrentFailedPasswordAttempts(myUserId());
2033 }
2034
2035 /**
2036 * Retrieve the number of times the given user has failed at entering a
2037 * password since that last successful password entry.
2038 *
2039 * <p>The calling device admin must have requested
2040 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2041 * not and it is not the system uid, a security exception will be thrown.
2042 *
2043 * @hide
2044 */
2045 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002046 if (mService != null) {
2047 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002048 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002049 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002050 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002051 }
2052 }
2053 return -1;
2054 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002055
2056 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002057 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002058 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002059 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002060 * @hide
2061 */
2062 public boolean getDoNotAskCredentialsOnBoot() {
2063 if (mService != null) {
2064 try {
2065 return mService.getDoNotAskCredentialsOnBoot();
2066 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002067 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002068 }
2069 }
2070 return false;
2071 }
2072
2073 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08002074 * Setting this to a value greater than zero enables a built-in policy
Esteban Talaverac1c83592016-02-17 17:56:15 +00002075 * that will perform a device or profile wipe after too many incorrect
Andrew Stadler88209d12010-02-08 22:59:36 -08002076 * device-unlock passwords have been entered. This built-in policy combines
2077 * watching for failed passwords and wiping the device, and requires
2078 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002079 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002080 *
Andrew Stadler88209d12010-02-08 22:59:36 -08002081 * <p>To implement any other policy (e.g. wiping data for a particular
2082 * application only, erasing or revoking credentials, or reporting the
2083 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002084 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08002085 * instead. Do not use this API, because if the maximum count is reached,
Esteban Talaverac1c83592016-02-17 17:56:15 +00002086 * the device or profile will be wiped immediately, and your callback will not be invoked.
2087 *
2088 * <p>This method can be called on the {@link DevicePolicyManager} instance
2089 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2090 * a value on the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002091 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002092 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002093 * @param num The number of failed password attempts at which point the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002094 * device or profile will be wiped.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002095 */
Robin Lee25e26452015-06-02 09:56:29 -07002096 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002097 if (mService != null) {
2098 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002099 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002100 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002101 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002102 }
2103 }
2104 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002105
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002106 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002107 * Retrieve the current maximum number of login attempts that are allowed before the device
2108 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2109 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2110 * not taken into account.
2111 *
2112 * <p>This method can be called on the {@link DevicePolicyManager} instance
2113 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2114 * the value for the parent profile.
2115 *
Robin Lee25e26452015-06-02 09:56:29 -07002116 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002117 * all admins.
2118 */
Robin Lee25e26452015-06-02 09:56:29 -07002119 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002120 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002121 }
2122
2123 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002124 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002125 if (mService != null) {
2126 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002127 return mService.getMaximumFailedPasswordsForWipe(
2128 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002129 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002130 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002131 }
2132 }
2133 return 0;
2134 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002135
Dianne Hackborn254cb442010-01-27 19:23:59 -08002136 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002137 * Returns the profile with the smallest maximum failed passwords for wipe,
2138 * for the given user. So for primary user, it might return the primary or
2139 * a managed profile. For a secondary user, it would be the same as the
2140 * user passed in.
2141 * @hide Used only by Keyguard
2142 */
2143 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2144 if (mService != null) {
2145 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002146 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2147 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002148 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002149 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002150 }
2151 }
2152 return UserHandle.USER_NULL;
2153 }
2154
2155 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002156 * Flag for {@link #resetPassword}: don't allow other admins to change
2157 * the password again until the user has entered it.
2158 */
2159 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002160
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002161 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002162 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2163 * If the flag is set, the device can be booted without asking for user password.
2164 * The absence of this flag does not change the current boot requirements. This flag
2165 * can be set by the device owner only. If the app is not the device owner, the flag
2166 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2167 * device to factory defaults.
2168 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002169 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002170
2171 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002172 * Force a new device unlock password (the password needed to access the
2173 * entire device, not for individual accounts) on the user. This takes
2174 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08002175 *
2176 * <p>Calling this from a managed profile that shares the password with the owner profile
2177 * will throw a security exception.
2178 *
2179 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
2180 * device admins that are not device owner and not profile owner.
2181 * The password can now only be changed if there is currently no password set. Device owner
2182 * and profile owner can still do this.</em>
2183 *
2184 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002185 * current password quality and length constraints as returned by
2186 * {@link #getPasswordQuality(ComponentName)} and
2187 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
2188 * these constraints, then it will be rejected and false returned. Note
2189 * that the password may be a stronger quality (containing alphanumeric
2190 * characters when the requested quality is only numeric), in which case
2191 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002192 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002193 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08002194 * pattern or password if the current password constraints allow it. <em>Note: This will not
2195 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2196 * device owner and not profile owner. Once set, the password cannot be changed to null or
2197 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002198 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002199 * <p>The calling device admin must have requested
2200 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
2201 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002202 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002203 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002204 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002205 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002206 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08002207 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002208 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002209 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002210 if (mParentInstance) {
2211 throw new SecurityException("Reset password does not work across profiles.");
2212 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002213 if (mService != null) {
2214 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002215 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002217 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002218 }
2219 }
2220 return false;
2221 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002222
Dianne Hackbornd6847842010-01-12 18:14:19 -08002223 /**
2224 * Called by an application that is administering the device to set the
2225 * maximum time for user activity until the device will lock. This limits
2226 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002227 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002228 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002229 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002230 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002231 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002232 * <p>This method can be called on the {@link DevicePolicyManager} instance
2233 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2234 * restrictions on the parent profile.
2235 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002237 * @param timeMs The new desired maximum time to lock in milliseconds.
2238 * A value of 0 means there is no restriction.
2239 */
Robin Lee25e26452015-06-02 09:56:29 -07002240 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002241 if (mService != null) {
2242 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002243 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002244 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002245 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002246 }
2247 }
2248 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002249
Dianne Hackbornd6847842010-01-12 18:14:19 -08002250 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002251 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2252 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2253 * a separate challenge are not taken into account.
2254 *
2255 * <p>This method can be called on the {@link DevicePolicyManager} instance
2256 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2257 * restrictions on the parent profile.
2258 *
Robin Lee25e26452015-06-02 09:56:29 -07002259 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002260 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002261 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002262 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002263 */
Robin Lee25e26452015-06-02 09:56:29 -07002264 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002265 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002266 }
2267
2268 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002269 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002270 if (mService != null) {
2271 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002272 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002273 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002274 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002275 }
2276 }
2277 return 0;
2278 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002279
Dianne Hackbornd6847842010-01-12 18:14:19 -08002280 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002281 * Make the device lock immediately, as if the lock screen timeout has
2282 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002283 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002284 * <p>The calling device admin must have requested
2285 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2286 * this method; if it has not, a security exception will be thrown.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002287 *
2288 * <p>This method can be called on the {@link DevicePolicyManager} instance
2289 * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock
2290 * the parent profile.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002291 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002292 public void lockNow() {
2293 if (mService != null) {
2294 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002295 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002296 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002297 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002298 }
2299 }
2300 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002301
Dianne Hackbornd6847842010-01-12 18:14:19 -08002302 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002303 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002304 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002305 */
2306 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2307
2308 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002309 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2310 * data.
2311 *
Paul Crowley2934b262014-12-02 11:21:13 +00002312 * <p>This flag may only be set by device owner admins; if it is set by
2313 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002314 */
2315 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2316
2317 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002318 * Ask the user data be wiped. Wiping the primary user will cause the
2319 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002320 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002321 * <p>The calling device admin must have requested
2322 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2323 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002324 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002325 * @param flags Bit mask of additional options: currently supported flags
2326 * are {@link #WIPE_EXTERNAL_STORAGE} and
2327 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002328 */
2329 public void wipeData(int flags) {
2330 if (mService != null) {
2331 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002332 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002333 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002334 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002335 }
2336 }
2337 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002338
Dianne Hackbornd6847842010-01-12 18:14:19 -08002339 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002340 * Called by an application that is administering the device to set the
2341 * global proxy and exclusion list.
2342 * <p>
2343 * The calling device admin must have requested
2344 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2345 * this method; if it has not, a security exception will be thrown.
2346 * Only the first device admin can set the proxy. If a second admin attempts
2347 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002348 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002349 * be returned.
2350 * The method can be called repeatedly by the device admin alrady setting the
2351 * proxy to update the proxy and exclusion list.
2352 *
Robin Lee25e26452015-06-02 09:56:29 -07002353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002354 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2355 * Pass Proxy.NO_PROXY to reset the proxy.
2356 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002357 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2358 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002359 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002360 */
Robin Lee25e26452015-06-02 09:56:29 -07002361 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002362 List<String> exclusionList ) {
2363 if (proxySpec == null) {
2364 throw new NullPointerException();
2365 }
2366 if (mService != null) {
2367 try {
2368 String hostSpec;
2369 String exclSpec;
2370 if (proxySpec.equals(Proxy.NO_PROXY)) {
2371 hostSpec = null;
2372 exclSpec = null;
2373 } else {
2374 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2375 throw new IllegalArgumentException();
2376 }
2377 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2378 String hostName = sa.getHostName();
2379 int port = sa.getPort();
2380 StringBuilder hostBuilder = new StringBuilder();
2381 hostSpec = hostBuilder.append(hostName)
2382 .append(":").append(Integer.toString(port)).toString();
2383 if (exclusionList == null) {
2384 exclSpec = "";
2385 } else {
2386 StringBuilder listBuilder = new StringBuilder();
2387 boolean firstDomain = true;
2388 for (String exclDomain : exclusionList) {
2389 if (!firstDomain) {
2390 listBuilder = listBuilder.append(",");
2391 } else {
2392 firstDomain = false;
2393 }
2394 listBuilder = listBuilder.append(exclDomain.trim());
2395 }
2396 exclSpec = listBuilder.toString();
2397 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002398 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2399 != android.net.Proxy.PROXY_VALID)
2400 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002401 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002402 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002403 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002404 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002405 }
2406 }
2407 return null;
2408 }
2409
2410 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002411 * Set a network-independent global HTTP proxy. This is not normally what you want
2412 * for typical HTTP proxies - they are generally network dependent. However if you're
2413 * doing something unusual like general internal filtering this may be useful. On
2414 * a private network where the proxy is not accessible, you may break HTTP using this.
2415 *
2416 * <p>This method requires the caller to be the device owner.
2417 *
2418 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2419 * @see ProxyInfo
2420 *
2421 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2422 * with.
2423 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2424 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2425 */
Robin Lee25e26452015-06-02 09:56:29 -07002426 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2427 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002428 if (mService != null) {
2429 try {
2430 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2431 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002432 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002433 }
2434 }
2435 }
2436
2437 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002438 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002439 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2440 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002441 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002442 */
2443 public ComponentName getGlobalProxyAdmin() {
2444 if (mService != null) {
2445 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002446 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002447 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002448 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002449 }
2450 }
2451 return null;
2452 }
2453
2454 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002455 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002456 * indicating that encryption is not supported.
2457 */
2458 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2459
2460 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002461 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002462 * indicating that encryption is supported, but is not currently active.
2463 */
2464 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2465
2466 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002467 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002468 * indicating that encryption is not currently active, but is currently
2469 * being activated. This is only reported by devices that support
2470 * encryption of data and only when the storage is currently
2471 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2472 * to become encrypted will never return this value.
2473 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002474 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002475
2476 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002477 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002478 * indicating that encryption is active.
2479 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002480 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002481
2482 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002483 * Result code for {@link #getStorageEncryptionStatus}:
2484 * indicating that encryption is active, but an encryption key has not
2485 * been set by the user.
2486 */
2487 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2488
2489 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002490 * Activity action: begin the process of encrypting data on the device. This activity should
2491 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2492 * After resuming from this activity, use {@link #getStorageEncryption}
2493 * to check encryption status. However, on some devices this activity may never return, as
2494 * it may trigger a reboot and in some cases a complete data wipe of the device.
2495 */
2496 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2497 public static final String ACTION_START_ENCRYPTION
2498 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002499 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002500 * Widgets are enabled in keyguard
2501 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002502 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002503
2504 /**
Jim Miller50e62182014-04-23 17:25:00 -07002505 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002506 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002507 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2508
2509 /**
2510 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2511 */
2512 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2513
2514 /**
Jim Miller50e62182014-04-23 17:25:00 -07002515 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2516 */
2517 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2518
2519 /**
2520 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2521 */
2522 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2523
2524 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002525 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002526 * (e.g. PIN/Pattern/Password).
2527 */
2528 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2529
2530 /**
Jim Miller06e34502014-07-17 14:46:05 -07002531 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2532 */
2533 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2534
2535 /**
Jim Miller35207742012-11-02 15:33:20 -07002536 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002537 */
2538 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002539
2540 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002541 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002542 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002543 *
2544 * <p>When multiple device administrators attempt to control device
2545 * encryption, the most secure, supported setting will always be
2546 * used. If any device administrator requests device encryption,
2547 * it will be enabled; Conversely, if a device administrator
2548 * attempts to disable device encryption while another
2549 * device administrator has enabled it, the call to disable will
2550 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2551 *
2552 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002553 * written to other storage areas may or may not be encrypted, and this policy does not require
2554 * or control the encryption of any other storage areas.
2555 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2556 * {@code true}, then the directory returned by
2557 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2558 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002559 *
2560 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2561 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2562 * the encryption key may not be fully secured. For maximum security, the administrator should
2563 * also require (and check for) a pattern, PIN, or password.
2564 *
2565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2566 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002567 * @return the new request status (for all active admins) - will be one of
2568 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2569 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2570 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002571 */
Robin Lee25e26452015-06-02 09:56:29 -07002572 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002573 if (mService != null) {
2574 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002575 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002576 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002577 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002578 }
2579 }
2580 return ENCRYPTION_STATUS_UNSUPPORTED;
2581 }
2582
2583 /**
2584 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002585 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002586 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002587 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2588 * this will return the requested encryption setting as an aggregate of all active
2589 * administrators.
2590 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002591 */
Robin Lee25e26452015-06-02 09:56:29 -07002592 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002593 if (mService != null) {
2594 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002595 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002596 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002597 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002598 }
2599 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002600 return false;
2601 }
2602
2603 /**
2604 * Called by an application that is administering the device to
2605 * determine the current encryption status of the device.
2606 *
2607 * Depending on the returned status code, the caller may proceed in different
2608 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2609 * storage system does not support encryption. If the
2610 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2611 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002612 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2613 * storage system has enabled encryption but no password is set so further action
2614 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002615 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2616 *
Robin Lee7e678712014-07-24 16:41:31 +01002617 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002618 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002619 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2620 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002621 */
2622 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002623 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002624 }
2625
2626 /** @hide per-user version */
2627 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002628 if (mService != null) {
2629 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002630 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002631 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002632 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002633 }
2634 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002635 return ENCRYPTION_STATUS_UNSUPPORTED;
2636 }
2637
2638 /**
Robin Lee7e678712014-07-24 16:41:31 +01002639 * Installs the given certificate as a user CA.
2640 *
Robin Lee25e26452015-06-02 09:56:29 -07002641 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2642 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002643 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002644 *
2645 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002646 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002647 */
Robin Lee25e26452015-06-02 09:56:29 -07002648 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002649 if (mService != null) {
2650 try {
Robin Lee7e678712014-07-24 16:41:31 +01002651 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002652 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002653 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002654 }
2655 }
2656 return false;
2657 }
2658
2659 /**
Robin Lee7e678712014-07-24 16:41:31 +01002660 * Uninstalls the given certificate from trusted user CAs, if present.
2661 *
Robin Lee25e26452015-06-02 09:56:29 -07002662 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2663 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002664 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002665 */
Robin Lee25e26452015-06-02 09:56:29 -07002666 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002667 if (mService != null) {
2668 try {
Robin Lee306fe082014-06-19 14:04:24 +00002669 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002670 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002671 } catch (CertificateException e) {
2672 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002673 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002674 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002675 }
2676 }
2677 }
2678
2679 /**
Robin Lee7e678712014-07-24 16:41:31 +01002680 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2681 * If a user has installed any certificates by other means than device policy these will be
2682 * included too.
2683 *
Robin Lee25e26452015-06-02 09:56:29 -07002684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2685 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002686 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002687 */
Robin Lee25e26452015-06-02 09:56:29 -07002688 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002689 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002690 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002691 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002692 mService.enforceCanManageCaCerts(admin);
2693 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2694 for (String alias : certStore.userAliases()) {
2695 try {
2696 certs.add(certStore.getCertificate(alias).getEncoded());
2697 } catch (CertificateException ce) {
2698 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2699 }
2700 }
2701 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002702 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002703 }
2704 }
2705 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002706 }
2707
2708 /**
Robin Lee7e678712014-07-24 16:41:31 +01002709 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2710 * means other than device policy will also be removed, except for system CA certificates.
2711 *
Robin Lee25e26452015-06-02 09:56:29 -07002712 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2713 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002714 */
Robin Lee25e26452015-06-02 09:56:29 -07002715 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002716 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002717 try {
2718 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2719 .toArray(new String[0]));
2720 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002721 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002722 }
2723 }
2724 }
2725
2726 /**
2727 * Returns whether this certificate is installed as a trusted CA.
2728 *
Robin Lee25e26452015-06-02 09:56:29 -07002729 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2730 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002731 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002732 */
Robin Lee25e26452015-06-02 09:56:29 -07002733 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002734 if (mService != null) {
2735 try {
2736 mService.enforceCanManageCaCerts(admin);
2737 return getCaCertAlias(certBuffer) != null;
2738 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002739 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002740 } catch (CertificateException ce) {
2741 Log.w(TAG, "Could not parse certificate", ce);
2742 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002743 }
2744 return false;
2745 }
2746
2747 /**
Robin Leece3399f2016-02-24 12:08:32 +00002748 * Called by a device or profile owner, or delegated certificate installer, to install a
2749 * certificate and corresponding private key. All apps within the profile will be able to access
2750 * the certificate and use the private key, given direct user approval.
2751 *
2752 * <p>Access to the installed credentials will not be granted to the caller of this API without
2753 * direct user approval. This is for security - should a certificate installer become
2754 * compromised, certificates it had already installed will be protected.
2755 *
2756 * <p>If the installer must have access to the credentials, call
2757 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002758 *
Robin Lee25e26452015-06-02 09:56:29 -07002759 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2760 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002761 * @param privKey The private key to install.
2762 * @param cert The certificate to install.
2763 * @param alias The private key alias under which to install the certificate. If a certificate
2764 * with that alias already exists, it will be overwritten.
2765 * @return {@code true} if the keys were installed, {@code false} otherwise.
2766 */
Robin Leefbc65642015-08-03 16:21:22 +01002767 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2768 @NonNull Certificate cert, @NonNull String alias) {
Robin Leece3399f2016-02-24 12:08:32 +00002769 return installKeyPair(admin, privKey, cert, alias, false);
2770 }
2771
2772 /**
2773 * Called by a device or profile owner, or delegated certificate installer, to install a
2774 * certificate and corresponding private key. All apps within the profile will be able to access
2775 * the certificate and use the private key, given direct user approval.
2776 *
Robin Leea1b290e2016-03-09 14:38:36 +00002777 * <p>The caller of this API may grant itself access to the certificate and private key
2778 * immediately, without user approval. It is a best practice not to request this unless strictly
2779 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00002780 *
2781 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002782 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00002783 * @param privKey The private key to install.
2784 * @param cert The certificate to install.
2785 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00002786 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00002787 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00002788 * credentials immediately. Otherwise, access to the credentials will be gated by user
2789 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00002790 * @return {@code true} if the keys were installed, {@code false} otherwise.
2791 */
2792 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2793 @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002794 try {
2795 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002796 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2797 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Leece3399f2016-02-24 12:08:32 +00002798 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002799 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002800 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01002801 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2802 Log.w(TAG, "Failed to obtain private key material", e);
2803 } catch (CertificateException | IOException e) {
2804 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002805 }
2806 return false;
2807 }
2808
2809 /**
Robin Leea1b290e2016-03-09 14:38:36 +00002810 * Called by a device or profile owner, or delegated certificate installer, to remove a
2811 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002812 *
2813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002814 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01002815 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00002816 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Robin Leefbc65642015-08-03 16:21:22 +01002817 */
2818 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2819 try {
2820 return mService.removeKeyPair(admin, alias);
2821 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002822 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01002823 }
Robin Leefbc65642015-08-03 16:21:22 +01002824 }
2825
2826 /**
Robin Lee25e26452015-06-02 09:56:29 -07002827 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002828 * doesn't exist.
2829 */
2830 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2831 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2832 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2833 new ByteArrayInputStream(certBuffer));
2834 return new TrustedCertificateStore().getCertificateAlias(cert);
2835 }
2836
2837 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002838 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002839 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002840 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002841 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002842 * <p>
2843 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2844 * it is later cleared by calling this method with a null value or uninstallling the certificate
2845 * installer.
Rubin Xuf03d0a62016-02-10 14:54:15 +00002846 *<p>
2847 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2848 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
2849 * supplied certificate installer package must be installed when calling this API,
2850 * otherwise an {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002851 *
Robin Lee25e26452015-06-02 09:56:29 -07002852 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002853 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002854 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002855 */
Robin Lee25e26452015-06-02 09:56:29 -07002856 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2857 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002858 if (mService != null) {
2859 try {
Robin Lee25e26452015-06-02 09:56:29 -07002860 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002861 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002862 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002863 }
2864 }
2865 }
2866
2867 /**
2868 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002869 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002870 *
Robin Lee25e26452015-06-02 09:56:29 -07002871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2872 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002873 * if none is set.
2874 */
Robin Lee25e26452015-06-02 09:56:29 -07002875 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002876 if (mService != null) {
2877 try {
Robin Lee25e26452015-06-02 09:56:29 -07002878 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002879 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002880 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002881 }
2882 }
2883 return null;
2884 }
2885
2886 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002887 * Called by a device or profile owner to configure an always-on VPN connection through a
2888 * specific application for the current user.
2889 * This connection is automatically granted and persisted after a reboot.
2890 *
2891 * <p>The designated package should declare a {@link android.net.VpnService} in its
2892 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2893 * otherwise the call will fail.
2894 *
2895 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2896 * to remove an existing always-on VPN configuration.
2897 *
2898 * @return {@code true} if the package is set as always-on VPN controller;
2899 * {@code false} otherwise.
2900 */
2901 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2902 @Nullable String vpnPackage) {
2903 if (mService != null) {
2904 try {
2905 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2906 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002907 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002908 }
2909 }
2910 return false;
2911 }
2912
2913 /**
2914 * Called by a device or profile owner to read the name of the package administering an
2915 * always-on VPN connection for the current user.
2916 * If there is no such package, or the always-on VPN is provided by the system instead
2917 * of by an application, {@code null} will be returned.
2918 *
2919 * @return Package name of VPN controller responsible for always-on VPN,
2920 * or {@code null} if none is set.
2921 */
2922 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2923 if (mService != null) {
2924 try {
2925 return mService.getAlwaysOnVpnPackage(admin);
2926 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002927 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002928 }
2929 }
2930 return null;
2931 }
2932
2933 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002934 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002935 * on the device, for this user. After setting this, no applications running as this user
2936 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002937 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002938 * <p>If the caller is device owner, then the restriction will be applied to all users.
2939 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002940 * <p>The calling device admin must have requested
2941 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2942 * this method; if it has not, a security exception will be thrown.
2943 *
2944 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2945 * @param disabled Whether or not the camera should be disabled.
2946 */
Robin Lee25e26452015-06-02 09:56:29 -07002947 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002948 if (mService != null) {
2949 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002950 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002951 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002952 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07002953 }
2954 }
2955 }
2956
2957 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002958 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002959 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002960 * @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 -07002961 * have disabled the camera
2962 */
Robin Lee25e26452015-06-02 09:56:29 -07002963 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002964 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002965 }
2966
2967 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002968 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002969 if (mService != null) {
2970 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002971 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002972 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002973 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07002974 }
2975 }
2976 return false;
2977 }
2978
2979 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002980 * Called by a device owner to request a bugreport.
2981 *
2982 * <p>There must be only one user on the device, managed by the device owner.
Michal Karpinskib58e4962016-03-01 14:55:10 +00002983 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002984 *
2985 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2986 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2987 * if it wasn't triggered because a previous bugreport operation is still active
2988 * (either the bugreport is still running or waiting for the user to share or decline)
2989 */
2990 public boolean requestBugreport(@NonNull ComponentName admin) {
2991 if (mService != null) {
2992 try {
2993 return mService.requestBugreport(admin);
2994 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002995 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002996 }
2997 }
2998 return false;
2999 }
3000
3001 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003002 * Determine whether or not creating a guest user has been disabled for the device
3003 *
3004 * @hide
3005 */
3006 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3007 // Currently guest users can always be created if multi-user is enabled
3008 // TODO introduce a policy for guest user creation
3009 return false;
3010 }
3011
3012 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003013 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3014 * screen capture also prevents the content from being shown on display devices that do not have
3015 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3016 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003017 *
3018 * <p>The calling device admin must be a device or profile owner. If it is not, a
3019 * security exception will be thrown.
3020 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003021 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01003022 * blocks assist requests for all activities of the relevant user.
3023 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003025 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003026 */
Robin Lee25e26452015-06-02 09:56:29 -07003027 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003028 if (mService != null) {
3029 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003030 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003031 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003032 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003033 }
3034 }
3035 }
3036
3037 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003038 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003039 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003040 * @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 +01003041 * have disabled screen capture.
3042 */
Robin Lee25e26452015-06-02 09:56:29 -07003043 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003044 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003045 }
3046
3047 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003048 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003049 if (mService != null) {
3050 try {
3051 return mService.getScreenCaptureDisabled(admin, userHandle);
3052 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003053 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003054 }
3055 }
3056 return false;
3057 }
3058
3059 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003060 * Called by a device owner to set whether auto time is required. If auto time is
3061 * required the user cannot set the date and time, but has to use network date and time.
3062 *
3063 * <p>Note: if auto time is required the user can still manually set the time zone.
3064 *
3065 * <p>The calling device admin must be a device owner. If it is not, a security exception will
3066 * be thrown.
3067 *
3068 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3069 * @param required Whether auto time is set required or not.
3070 */
Robin Lee25e26452015-06-02 09:56:29 -07003071 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003072 if (mService != null) {
3073 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003074 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003075 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003076 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003077 }
3078 }
3079 }
3080
3081 /**
3082 * @return true if auto time is required.
3083 */
3084 public boolean getAutoTimeRequired() {
3085 if (mService != null) {
3086 try {
3087 return mService.getAutoTimeRequired();
3088 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003089 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003090 }
3091 }
3092 return false;
3093 }
3094
3095 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003096 * Called by a device owner to set whether all users created on the device should be ephemeral.
3097 *
3098 * <p>The system user is exempt from this policy - it is never ephemeral.
3099 *
3100 * <p>The calling device admin must be the device owner. If it is not, a security exception will
3101 * be thrown.
3102 *
3103 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3104 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
3105 * subsequently created users will be ephemeral.
3106 * @hide
3107 */
3108 public void setForceEphemeralUsers(
3109 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3110 if (mService != null) {
3111 try {
3112 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003114 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003115 }
3116 }
3117 }
3118
3119 /**
3120 * @return true if all users are created ephemeral.
3121 * @hide
3122 */
3123 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3124 if (mService != null) {
3125 try {
3126 return mService.getForceEphemeralUsers(admin);
3127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003128 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003129 }
3130 }
3131 return false;
3132 }
3133
3134 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003135 * Called by an application that is administering the device to disable keyguard customizations,
3136 * such as widgets. After setting this, keyguard features will be disabled according to the
3137 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003138 *
3139 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07003140 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07003141 * this method; if it has not, a security exception will be thrown.
3142 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003143 * <p>Calling this from a managed profile before version
Esteban Talaverac1c83592016-02-17 17:56:15 +00003144 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version
3145 * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003146 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003147 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
3148 * is no separate challenge set on the managed profile.
3149 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
3150 * there is one, or the parent user otherwise.
3151 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications
3152 * generated by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003153 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003154 *
3155 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3156 * set on the {@link DevicePolicyManager} instance returned by
3157 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the
3158 * parent profile.
3159 *
3160 * <p>Requests to disable other features on a managed profile will be ignored.
3161 *
3162 * <p>The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003163 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003164 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003166 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
3167 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07003168 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003169 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
3170 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07003171 */
Robin Lee25e26452015-06-02 09:56:29 -07003172 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003173 if (mService != null) {
3174 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003175 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003176 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003177 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003178 }
3179 }
3180 }
3181
3182 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003183 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003184 * admin, if specified, or all admins that set retrictions on this user and its participating
3185 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3186 *
3187 * <p>This method can be called on the {@link DevicePolicyManager} instance
3188 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3189 * restrictions on the parent profile.
3190 *
Esteban Talavera62399912016-01-11 15:37:55 +00003191 * @param admin The name of the admin component to check, or {@code null} to check whether any
3192 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003193 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3194 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003195 */
Robin Lee25e26452015-06-02 09:56:29 -07003196 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003197 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003198 }
3199
3200 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003201 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003202 if (mService != null) {
3203 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003204 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003205 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003206 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003207 }
3208 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003209 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003210 }
3211
3212 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003213 * @hide
3214 */
Robin Lee25e26452015-06-02 09:56:29 -07003215 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3216 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003217 if (mService != null) {
3218 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003219 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003220 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003221 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003222 }
3223 }
3224 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003225
Dianne Hackbornd6847842010-01-12 18:14:19 -08003226 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003227 * @hide
3228 */
Robin Lee25e26452015-06-02 09:56:29 -07003229 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003230 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003231 }
3232
3233 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003234 * @hide
3235 */
Robin Lee25e26452015-06-02 09:56:29 -07003236 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003237 if (mService != null) {
3238 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003239 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003240 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003241 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003242 }
3243 }
3244 }
3245
3246 /**
3247 * @hide
3248 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003249 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003250 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003251 if (mService != null) {
3252 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003253 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003254 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003255 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003256 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003257 }
3258 }
3259 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003260
Dianne Hackbornd6847842010-01-12 18:14:19 -08003261 /**
3262 * @hide
3263 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003264 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003265 if (mService != null) {
3266 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003267 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003268 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003269 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003270 }
3271 }
3272 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003273
Dianne Hackbornd6847842010-01-12 18:14:19 -08003274 /**
3275 * @hide
3276 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003277 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003278 if (mService != null) {
3279 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003280 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003281 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003282 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003283 }
3284 }
3285 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003286
3287 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003288 * @hide
3289 */
3290 public void reportFailedFingerprintAttempt(int userHandle) {
3291 if (mService != null) {
3292 try {
3293 mService.reportFailedFingerprintAttempt(userHandle);
3294 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003295 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003296 }
3297 }
3298 }
3299
3300 /**
3301 * @hide
3302 */
3303 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3304 if (mService != null) {
3305 try {
3306 mService.reportSuccessfulFingerprintAttempt(userHandle);
3307 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003308 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003309 }
3310 }
3311 }
3312
3313 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003314 * Should be called when keyguard has been dismissed.
3315 * @hide
3316 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003317 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003318 if (mService != null) {
3319 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003320 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003322 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003323 }
3324 }
3325 }
3326
3327 /**
3328 * Should be called when keyguard view has been shown to the user.
3329 * @hide
3330 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003331 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003332 if (mService != null) {
3333 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003334 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003335 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003336 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003337 }
3338 }
3339 }
3340
3341 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003342 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003343 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003344 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3345 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003346 * @return whether the package was successfully registered as the device owner.
3347 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003348 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003349 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003350 public boolean setDeviceOwner(ComponentName who) {
3351 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003352 }
3353
3354 /**
3355 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003356 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003357 public boolean setDeviceOwner(ComponentName who, int userId) {
3358 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003359 }
3360
3361 /**
3362 * @hide
3363 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003364 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3365 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003366 }
3367
3368 /**
3369 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003370 * Sets the given package as the device owner. The package must already be installed. There
3371 * must not already be a device owner.
3372 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3373 * this method.
3374 * Calling this after the setup phase of the primary user has completed is allowed only if
3375 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003376 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003377 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003378 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003379 * @return whether the package was successfully registered as the device owner.
3380 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003381 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003382 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003383 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003384 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003385 if (mService != null) {
3386 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003387 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003388 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003389 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003390 }
3391 }
3392 return false;
3393 }
3394
3395 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003396 * Used to determine if a particular package has been registered as a Device Owner app.
3397 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003398 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003399 * package is currently registered as the device owner app, pass in the package name from
3400 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003401 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003402 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3403 * the setup process.
3404 * @param packageName the package name of the app, to compare with the registered device owner
3405 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003406 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003407 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003408 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003409 return isDeviceOwnerAppOnCallingUser(packageName);
3410 }
3411
3412 /**
3413 * @return true if a package is registered as device owner, only when it's running on the
3414 * calling user.
3415 *
3416 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3417 * @hide
3418 */
3419 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3420 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3421 }
3422
3423 /**
3424 * @return true if a package is registered as device owner, even if it's running on a different
3425 * user.
3426 *
3427 * <p>Requires the MANAGE_USERS permission.
3428 *
3429 * @hide
3430 */
3431 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3432 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3433 }
3434
3435 /**
3436 * @return device owner component name, only when it's running on the calling user.
3437 *
3438 * @hide
3439 */
3440 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3441 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3442 }
3443
3444 /**
3445 * @return device owner component name, even if it's running on a different user.
3446 *
3447 * <p>Requires the MANAGE_USERS permission.
3448 *
3449 * @hide
3450 */
3451 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3452 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3453 }
3454
3455 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003456 if (packageName == null) {
3457 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003458 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003459 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003460 if (deviceOwner == null) {
3461 return false;
3462 }
3463 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003464 }
3465
Makoto Onukic8a5a552015-11-19 14:29:12 -08003466 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3467 if (mService != null) {
3468 try {
3469 return mService.getDeviceOwnerComponent(callingUserOnly);
3470 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003471 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003472 }
3473 }
3474 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003475 }
3476
Jason Monkb0dced82014-06-06 14:36:20 -04003477 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003478 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3479 * no device owner.
3480 *
3481 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003482 *
3483 * @hide
3484 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003485 public int getDeviceOwnerUserId() {
3486 if (mService != null) {
3487 try {
3488 return mService.getDeviceOwnerUserId();
3489 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003490 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003491 }
3492 }
3493 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003494 }
3495
3496 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003497 * Clears the current device owner. The caller must be the device owner.
3498 *
3499 * This function should be used cautiously as once it is called it cannot
3500 * be undone. The device owner can only be set as a part of device setup
3501 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003502 *
3503 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003504 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003505 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003506 if (mService != null) {
3507 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003508 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003509 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003510 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003511 }
3512 }
3513 }
3514
Makoto Onukia52562c2015-10-01 16:12:31 -07003515 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003516 * Returns the device owner package name, only if it's running on the calling user.
3517 *
3518 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003519 *
3520 * @hide
3521 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003522 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003523 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003524 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3525 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003526 }
3527
3528 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003529 * @return true if the device is managed by any device owner.
3530 *
3531 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003532 *
3533 * @hide
3534 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003535 public boolean isDeviceManaged() {
3536 return getDeviceOwnerComponentOnAnyUser() != null;
3537 }
3538
3539 /**
3540 * Returns the device owner name. Note this method *will* return the device owner
3541 * name when it's running on a different user.
3542 *
3543 * <p>Requires the MANAGE_USERS permission.
3544 *
3545 * @hide
3546 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003547 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003548 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003549 if (mService != null) {
3550 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003551 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003552 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003553 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003554 }
3555 }
3556 return null;
3557 }
Adam Connors776c5552014-01-09 10:42:56 +00003558
3559 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003560 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003561 * @deprecated Do not use
3562 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003563 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003564 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003565 @SystemApi
3566 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003567 return null;
3568 }
3569
3570 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003571 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003572 * @deprecated Do not use
3573 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003574 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003575 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003576 @SystemApi
3577 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003578 return null;
3579 }
3580
Julia Reynolds20118f12015-02-11 12:34:08 -05003581 /**
Adam Connors776c5552014-01-09 10:42:56 +00003582 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003583 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303584 * Sets the given component as an active admin and registers the package as the profile
3585 * owner for this user. The package must already be installed and there shouldn't be
3586 * an existing profile owner registered for this user. Also, this method must be called
3587 * before the user setup has been completed.
3588 * <p>
3589 * This method can only be called by system apps that hold MANAGE_USERS permission and
3590 * MANAGE_DEVICE_ADMINS permission.
3591 * @param admin The component to register as an active admin and profile owner.
3592 * @param ownerName The user-visible name of the entity that is managing this user.
3593 * @return whether the admin was successfully registered as the profile owner.
3594 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3595 * the user has already been set up.
3596 */
Justin Morey80440cc2014-07-24 09:16:35 -05003597 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003598 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303599 throws IllegalArgumentException {
3600 if (mService != null) {
3601 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003602 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303603 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003604 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303605 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003606 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303607 }
3608 }
3609 return false;
3610 }
3611
3612 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003613 * Clears the active profile owner and removes all user restrictions. The caller must
3614 * be from the same package as the active profile owner for this user, otherwise a
3615 * SecurityException will be thrown.
3616 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003617 * <p>This doesn't work for managed profile owners.
3618 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003619 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003620 */
Robin Lee25e26452015-06-02 09:56:29 -07003621 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003622 if (mService != null) {
3623 try {
3624 mService.clearProfileOwner(admin);
3625 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003626 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003627 }
3628 }
3629 }
3630
3631 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003632 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003633 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003634 */
3635 public boolean hasUserSetupCompleted() {
3636 if (mService != null) {
3637 try {
3638 return mService.hasUserSetupCompleted();
3639 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003640 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003641 }
3642 }
3643 return true;
3644 }
3645
3646 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003647 * @hide
3648 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003649 * already be installed. There must not already be a profile owner for this user.
3650 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3651 * this method.
3652 * Calling this after the setup phase of the specified user has completed is allowed only if:
3653 * - the caller is SYSTEM_UID.
3654 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003655 * @param admin the component name to be registered as profile owner.
3656 * @param ownerName the human readable name of the organisation associated with this DPM.
3657 * @param userHandle the userId to set the profile owner for.
3658 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003659 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3660 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003661 */
Robin Lee25e26452015-06-02 09:56:29 -07003662 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003663 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003664 if (mService != null) {
3665 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003666 if (ownerName == null) {
3667 ownerName = "";
3668 }
3669 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003670 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003671 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003672 }
3673 }
3674 return false;
3675 }
3676
3677 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003678 * Sets the device owner information to be shown on the lock screen.
3679 *
3680 * <p>If the device owner information is {@code null} or empty then the device owner info is
3681 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003682 * <p>If the device owner information contains only whitespaces then the message on the lock
3683 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003684 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003685 * <p>If the device owner information needs to be localized, it is the responsibility of the
3686 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3687 * and set a new version of this string accordingly.
3688 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003689 * @param admin The name of the admin component to check.
3690 * @param info Device owner information which will be displayed instead of the user
3691 * owner info.
3692 * @return Whether the device owner information has been set.
3693 */
3694 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3695 if (mService != null) {
3696 try {
3697 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3698 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003699 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003700 }
3701 }
3702 return false;
3703 }
3704
3705 /**
3706 * @return The device owner information. If it is not set returns {@code null}.
3707 */
3708 public String getDeviceOwnerLockScreenInfo() {
3709 if (mService != null) {
3710 try {
3711 return mService.getDeviceOwnerLockScreenInfo();
3712 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003713 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003714 }
3715 }
3716 return null;
3717 }
3718
3719 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003720 * Called by device or profile owners to suspend packages for this user.
3721 *
3722 * <p>A suspended package will not be able to start activities. Its notifications will
3723 * be hidden, it will not show up in recents, will not be able to show toasts or dialogs
3724 * or ring the device.
3725 *
Kenny Guy871f3eb2016-03-09 20:06:16 +00003726 * <p>The package must already be installed. If the package is uninstalled while suspended
3727 * the package will no longer be suspended. The admin can block this by using
3728 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003729 *
3730 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003731 * @param packageNames The package names to suspend or unsuspend.
3732 * @param suspended If set to {@code true} than the packages will be suspended, if set to
3733 * {@code false} the packages will be unsuspended.
3734 * @return an array of package names for which the suspended status is not set as requested in
3735 * this method.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003736 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003737 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003738 boolean suspended) {
3739 if (mService != null) {
3740 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003741 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003742 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003743 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003744 }
3745 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003746 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003747 }
3748
3749 /**
3750 * Called by device or profile owners to determine if a package is suspended.
3751 *
3752 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3753 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003754 * @return {@code true} if the package is suspended or {@code false} if the package is not
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003755 * suspended, could not be found or an error occurred.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003756 */
3757 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3758 if (mService != null) {
3759 try {
3760 return mService.getPackageSuspended(admin, packageName);
3761 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003762 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003763 }
3764 }
3765 return false;
3766 }
3767
3768 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003769 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3770 * be used. Only the profile owner can call this.
3771 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003772 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003773 *
3774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3775 */
Robin Lee25e26452015-06-02 09:56:29 -07003776 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003777 if (mService != null) {
3778 try {
3779 mService.setProfileEnabled(admin);
3780 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003781 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003782 }
3783 }
3784 }
3785
3786 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003787 * Sets the name of the profile. In the device owner case it sets the name of the user
3788 * 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 +01003789 * never called by the profile or device owner, the name will be set to default values.
3790 *
3791 * @see #isProfileOwnerApp
3792 * @see #isDeviceOwnerApp
3793 *
Robin Lee25e26452015-06-02 09:56:29 -07003794 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003795 * @param profileName The name of the profile.
3796 */
Robin Lee25e26452015-06-02 09:56:29 -07003797 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003798 if (mService != null) {
3799 try {
Robin Lee25e26452015-06-02 09:56:29 -07003800 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003801 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003802 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003803 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003804 }
3805 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003806
3807 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003808 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003809 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003810 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003811 *
3812 * @param packageName The package name of the app to compare with the registered profile owner.
3813 * @return Whether or not the package is registered as the profile owner.
3814 */
3815 public boolean isProfileOwnerApp(String packageName) {
3816 if (mService != null) {
3817 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003818 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003819 return profileOwner != null
3820 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003821 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003822 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003823 }
3824 }
3825 return false;
3826 }
3827
3828 /**
3829 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003830 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003831 * owner has been set for that user.
3832 * @throws IllegalArgumentException if the userId is invalid.
3833 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003834 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003835 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003836 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3837 }
3838
3839 /**
3840 * @see #getProfileOwner()
3841 * @hide
3842 */
3843 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003844 if (mService != null) {
3845 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003846 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003847 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003848 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003849 }
3850 }
3851 return null;
3852 }
3853
3854 /**
3855 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003856 * @return the human readable name of the organisation associated with this DPM or {@code null}
3857 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003858 * @throws IllegalArgumentException if the userId is invalid.
3859 */
3860 public String getProfileOwnerName() throws IllegalArgumentException {
3861 if (mService != null) {
3862 try {
3863 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3864 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003865 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003866 }
3867 }
3868 return null;
3869 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003870
3871 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003872 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003873 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003874 * @return the human readable name of the organisation associated with this profile owner or
3875 * null if one is not set.
3876 * @throws IllegalArgumentException if the userId is invalid.
3877 */
3878 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003879 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003880 if (mService != null) {
3881 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003882 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003883 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003884 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07003885 }
3886 }
3887 return null;
3888 }
3889
3890 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003891 * Called by a profile owner or device owner to add a default intent handler activity for
3892 * intents that match a certain intent filter. This activity will remain the default intent
3893 * handler even if the set of potential event handlers for the intent filter changes and if
3894 * the intent preferences are reset.
3895 *
3896 * <p>The default disambiguation mechanism takes over if the activity is not installed
3897 * (anymore). When the activity is (re)installed, it is automatically reset as default
3898 * intent handler for the filter.
3899 *
3900 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3901 * security exception will be thrown.
3902 *
3903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3904 * @param filter The IntentFilter for which a default handler is added.
3905 * @param activity The Activity that is added as default intent handler.
3906 */
Robin Lee25e26452015-06-02 09:56:29 -07003907 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3908 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003909 if (mService != null) {
3910 try {
3911 mService.addPersistentPreferredActivity(admin, filter, activity);
3912 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003913 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003914 }
3915 }
3916 }
3917
3918 /**
3919 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003920 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003921 *
3922 * <p>The calling device admin must be a profile owner. If it is not, a security
3923 * exception will be thrown.
3924 *
3925 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3926 * @param packageName The name of the package for which preferences are removed.
3927 */
Robin Lee25e26452015-06-02 09:56:29 -07003928 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003929 String packageName) {
3930 if (mService != null) {
3931 try {
3932 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3933 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003934 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003935 }
3936 }
3937 }
Robin Lee66e5d962014-04-09 16:44:21 +01003938
3939 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003940 * Called by a profile owner or device owner to grant permission to a package to manage
3941 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3942 * {@link #getApplicationRestrictions}.
3943 * <p>
3944 * This permission is persistent until it is later cleared by calling this method with a
3945 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00003946 * <p>
3947 * The supplied application restriction managing package must be installed when calling this
3948 * API, otherwise an {@link IllegalArgumentException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00003949 *
3950 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3951 * @param packageName The package name which will be given access to application restrictions
3952 * APIs. If {@code null} is given the current package will be cleared.
3953 */
3954 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3955 @Nullable String packageName) {
3956 if (mService != null) {
3957 try {
3958 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3959 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003960 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003961 }
3962 }
3963 }
3964
3965 /**
3966 * Called by a profile owner or device owner to retrieve the application restrictions managing
3967 * package for the current user, or {@code null} if none is set.
3968 *
3969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3970 * @return The package name allowed to manage application restrictions on the current user, or
3971 * {@code null} if none is set.
3972 */
3973 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3974 if (mService != null) {
3975 try {
3976 return mService.getApplicationRestrictionsManagingPackage(admin);
3977 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003978 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003979 }
3980 }
3981 return null;
3982 }
3983
3984 /**
3985 * Returns {@code true} if the calling package has been granted permission via
3986 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3987 * restrictions for the calling user.
3988 */
3989 public boolean isCallerApplicationRestrictionsManagingPackage() {
3990 if (mService != null) {
3991 try {
3992 return mService.isCallerApplicationRestrictionsManagingPackage();
3993 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003994 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003995 }
3996 }
3997 return false;
3998 }
3999
4000 /**
4001 * Sets the application restrictions for a given target application running in the calling user.
4002 *
4003 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4004 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4005 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004006 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004007 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
4008 * <ul>
4009 * <li>{@code boolean}
4010 * <li>{@code int}
4011 * <li>{@code String} or {@code String[]}
4012 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4013 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01004014 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004015 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00004016 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004017 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
4018 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004019 * <p>The application restrictions are only made visible to the target application via
4020 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
4021 * device owner, and the application restrictions managing package via
4022 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004023 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4025 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004026 * @param packageName The name of the package to update restricted settings for.
4027 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
4028 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004029 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004030 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004031 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004032 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004033 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004034 Bundle settings) {
4035 if (mService != null) {
4036 try {
4037 mService.setApplicationRestrictions(admin, packageName, settings);
4038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004039 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004040 }
4041 }
4042 }
4043
4044 /**
Jim Millere303bf42014-08-26 17:12:29 -07004045 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
4046 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
4047 * trust agents but those enabled by this function call. If flag
4048 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07004049 *
4050 * <p>The calling device admin must have requested
4051 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07004052 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07004053 *
4054 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004055 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08004056 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07004057 * will be strictly disabled according to the state of the
4058 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4059 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
4060 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
4061 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07004062 */
Robin Lee25e26452015-06-02 09:56:29 -07004063 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4064 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004065 if (mService != null) {
4066 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004067 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004068 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004069 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004070 }
4071 }
4072 }
4073
4074 /**
Jim Millere303bf42014-08-26 17:12:29 -07004075 * Gets configuration for the given trust agent based on aggregating all calls to
4076 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4077 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004078 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4080 * this function returns a list of configurations for all admins that declare
4081 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4082 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4083 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4084 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004085 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004086 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004087 */
Robin Lee25e26452015-06-02 09:56:29 -07004088 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4089 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004090 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004091 }
4092
4093 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004094 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4095 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004096 if (mService != null) {
4097 try {
Jim Millere303bf42014-08-26 17:12:29 -07004098 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004100 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004101 }
4102 }
Jim Millere303bf42014-08-26 17:12:29 -07004103 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004104 }
4105
4106 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004107 * Called by a profile owner of a managed profile to set whether caller-Id information from
4108 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01004109 *
4110 * <p>The calling device admin must be a profile owner. If it is not, a
4111 * security exception will be thrown.
4112 *
Robin Lee25e26452015-06-02 09:56:29 -07004113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004114 * @param disabled If true caller-Id information in the managed profile is not displayed.
4115 */
Robin Lee25e26452015-06-02 09:56:29 -07004116 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004117 if (mService != null) {
4118 try {
Robin Lee25e26452015-06-02 09:56:29 -07004119 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004120 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004121 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004122 }
4123 }
4124 }
4125
4126 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004127 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4128 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01004129 *
4130 * <p>The calling device admin must be a profile owner. If it is not, a
4131 * security exception will be thrown.
4132 *
Robin Lee25e26452015-06-02 09:56:29 -07004133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004134 */
Robin Lee25e26452015-06-02 09:56:29 -07004135 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004136 if (mService != null) {
4137 try {
Robin Lee25e26452015-06-02 09:56:29 -07004138 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004139 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004140 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004141 }
4142 }
4143 return false;
4144 }
4145
4146 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004147 * Determine whether or not caller-Id information has been disabled.
4148 *
4149 * @param userHandle The user for whom to check the caller-id permission
4150 * @hide
4151 */
4152 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4153 if (mService != null) {
4154 try {
4155 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4156 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004157 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004158 }
4159 }
4160 return false;
4161 }
4162
4163 /**
Victor Chang1060c6182016-01-04 20:16:23 +00004164 * Called by a profile owner of a managed profile to set whether contacts search from
4165 * the managed profile will be shown in the parent profile, for incoming calls.
4166 *
4167 * <p>The calling device admin must be a profile owner. If it is not, a
4168 * security exception will be thrown.
4169 *
4170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4171 * @param disabled If true contacts search in the managed profile is not displayed.
4172 */
4173 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4174 boolean disabled) {
4175 if (mService != null) {
4176 try {
4177 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4178 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004179 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004180 }
4181 }
4182 }
4183
4184 /**
4185 * Called by a profile owner of a managed profile to determine whether or not contacts search
4186 * has been disabled.
4187 *
4188 * <p>The calling device admin must be a profile owner. If it is not, a
4189 * security exception will be thrown.
4190 *
4191 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4192 */
4193 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4194 if (mService != null) {
4195 try {
4196 return mService.getCrossProfileContactsSearchDisabled(admin);
4197 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004198 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004199 }
4200 }
4201 return false;
4202 }
4203
4204
4205 /**
4206 * Determine whether or not contacts search has been disabled.
4207 *
4208 * @param userHandle The user for whom to check the contacts search permission
4209 * @hide
4210 */
4211 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4212 if (mService != null) {
4213 try {
4214 return mService
4215 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4216 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004217 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004218 }
4219 }
4220 return false;
4221 }
4222
4223 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004224 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004225 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004226 * @hide
4227 */
4228 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004229 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004230 if (mService != null) {
4231 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004232 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4233 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004235 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004236 }
4237 }
4238 }
4239
4240 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004241 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004242 * @hide
4243 */
4244 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4245 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004246 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004247 originalIntent);
4248 }
4249
4250 /**
Ricky Wai778ba132015-03-31 14:21:22 +01004251 * Called by a profile owner of a managed profile to set whether bluetooth
4252 * devices can access enterprise contacts.
4253 * <p>
4254 * The calling device admin must be a profile owner. If it is not, a
4255 * security exception will be thrown.
4256 * <p>
4257 * This API works on managed profile only.
4258 *
Robin Lee25e26452015-06-02 09:56:29 -07004259 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004260 * with.
4261 * @param disabled If true, bluetooth devices cannot access enterprise
4262 * contacts.
4263 */
Robin Lee25e26452015-06-02 09:56:29 -07004264 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004265 if (mService != null) {
4266 try {
Robin Lee25e26452015-06-02 09:56:29 -07004267 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004268 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004269 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004270 }
4271 }
4272 }
4273
4274 /**
4275 * Called by a profile owner of a managed profile to determine whether or
4276 * not Bluetooth devices cannot access enterprise contacts.
4277 * <p>
4278 * The calling device admin must be a profile owner. If it is not, a
4279 * security exception will be thrown.
4280 * <p>
4281 * This API works on managed profile only.
4282 *
Robin Lee25e26452015-06-02 09:56:29 -07004283 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004284 * with.
4285 */
Robin Lee25e26452015-06-02 09:56:29 -07004286 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004287 if (mService != null) {
4288 try {
Robin Lee25e26452015-06-02 09:56:29 -07004289 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004291 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004292 }
4293 }
4294 return true;
4295 }
4296
4297 /**
4298 * Determine whether or not Bluetooth devices cannot access contacts.
4299 * <p>
4300 * This API works on managed profile UserHandle only.
4301 *
4302 * @param userHandle The user for whom to check the caller-id permission
4303 * @hide
4304 */
4305 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4306 if (mService != null) {
4307 try {
4308 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4309 .getIdentifier());
4310 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004311 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004312 }
4313 }
4314 return true;
4315 }
4316
4317 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004318 * Called by the profile owner of a managed profile so that some intents sent in the managed
4319 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004320 * Only activity intents are supported.
4321 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004323 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4324 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004325 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4326 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004327 */
Robin Lee25e26452015-06-02 09:56:29 -07004328 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004329 if (mService != null) {
4330 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004331 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004332 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004333 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004334 }
4335 }
4336 }
4337
4338 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004339 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4340 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004341 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004342 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4343 */
Robin Lee25e26452015-06-02 09:56:29 -07004344 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004345 if (mService != null) {
4346 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004347 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004349 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004350 }
4351 }
4352 }
4353
4354 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004355 * Called by a profile or device owner to set the permitted accessibility services. When
4356 * set by a device owner or profile owner the restriction applies to all profiles of the
4357 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004358 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004359 * By default the user can use any accessiblity service. When zero or more packages have
4360 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004361 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004362 *
4363 * <p> Calling with a null value for the list disables the restriction so that all services
4364 * can be used, calling with an empty list only allows the builtin system's services.
4365 *
4366 * <p> System accesibility services are always available to the user the list can't modify
4367 * this.
4368 *
4369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4370 * @param packageNames List of accessibility service package names.
4371 *
4372 * @return true if setting the restriction succeeded. It fail if there is
4373 * one or more non-system accessibility services enabled, that are not in the list.
4374 */
Robin Lee25e26452015-06-02 09:56:29 -07004375 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004376 List<String> packageNames) {
4377 if (mService != null) {
4378 try {
4379 return mService.setPermittedAccessibilityServices(admin, packageNames);
4380 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004381 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004382 }
4383 }
4384 return false;
4385 }
4386
4387 /**
4388 * Returns the list of permitted accessibility services set by this device or profile owner.
4389 *
4390 * <p>An empty list means no accessibility services except system services are allowed.
4391 * Null means all accessibility services are allowed.
4392 *
4393 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4394 * @return List of accessiblity service package names.
4395 */
Robin Lee25e26452015-06-02 09:56:29 -07004396 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004397 if (mService != null) {
4398 try {
4399 return mService.getPermittedAccessibilityServices(admin);
4400 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004401 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004402 }
4403 }
4404 return null;
4405 }
4406
4407 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004408 * Called by the system to check if a specific accessibility service is disabled by admin.
4409 *
4410 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4411 * @param packageName Accessibility service package name that needs to be checked.
4412 * @param userHandle user id the admin is running as.
4413 * @return true if the accessibility service is permitted, otherwise false.
4414 *
4415 * @hide
4416 */
4417 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4418 @NonNull String packageName, int userHandle) {
4419 if (mService != null) {
4420 try {
4421 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4422 userHandle);
4423 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004424 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004425 }
4426 }
4427 return false;
4428 }
4429
4430 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004431 * Returns the list of accessibility services permitted by the device or profiles
4432 * owners of this user.
4433 *
4434 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4435 * it will contain the intersection of the permitted lists for any device or profile
4436 * owners that apply to this user. It will also include any system accessibility services.
4437 *
4438 * @param userId which user to check for.
4439 * @return List of accessiblity service package names.
4440 * @hide
4441 */
4442 @SystemApi
4443 public List<String> getPermittedAccessibilityServices(int userId) {
4444 if (mService != null) {
4445 try {
4446 return mService.getPermittedAccessibilityServicesForUser(userId);
4447 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004448 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004449 }
4450 }
4451 return null;
4452 }
4453
4454 /**
4455 * Called by a profile or device owner to set the permitted input methods services. When
4456 * set by a device owner or profile owner the restriction applies to all profiles of the
4457 * user the device owner or profile owner is an admin for.
4458 *
4459 * By default the user can use any input method. When zero or more packages have
4460 * been added, input method that are not in the list and not part of the system
4461 * can not be enabled by the user.
4462 *
4463 * This method will fail if it is called for a admin that is not for the foreground user
4464 * or a profile of the foreground user.
4465 *
4466 * <p> Calling with a null value for the list disables the restriction so that all input methods
4467 * can be used, calling with an empty list disables all but the system's own input methods.
4468 *
4469 * <p> System input methods are always available to the user this method can't modify this.
4470 *
4471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4472 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004473 * @return true if setting the restriction succeeded. It will fail if there are
4474 * one or more non-system input methods currently enabled that are not in
4475 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004476 */
Robin Lee25e26452015-06-02 09:56:29 -07004477 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004478 if (mService != null) {
4479 try {
4480 return mService.setPermittedInputMethods(admin, packageNames);
4481 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004482 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004483 }
4484 }
4485 return false;
4486 }
4487
4488
4489 /**
4490 * Returns the list of permitted input methods set by this device or profile owner.
4491 *
4492 * <p>An empty list means no input methods except system input methods are allowed.
4493 * Null means all input methods are allowed.
4494 *
4495 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4496 * @return List of input method package names.
4497 */
Robin Lee25e26452015-06-02 09:56:29 -07004498 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004499 if (mService != null) {
4500 try {
4501 return mService.getPermittedInputMethods(admin);
4502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004503 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004504 }
4505 }
4506 return null;
4507 }
4508
4509 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004510 * Called by the system to check if a specific input method is disabled by admin.
4511 *
4512 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4513 * @param packageName Input method package name that needs to be checked.
4514 * @param userHandle user id the admin is running as.
4515 * @return true if the input method is permitted, otherwise false.
4516 *
4517 * @hide
4518 */
4519 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4520 @NonNull String packageName, int userHandle) {
4521 if (mService != null) {
4522 try {
4523 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004525 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004526 }
4527 }
4528 return false;
4529 }
4530
4531 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004532 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004533 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004534 *
4535 * <p>Null means all input methods are allowed, if a non-null list is returned
4536 * it will contain the intersection of the permitted lists for any device or profile
4537 * owners that apply to this user. It will also include any system input methods.
4538 *
4539 * @return List of input method package names.
4540 * @hide
4541 */
4542 @SystemApi
4543 public List<String> getPermittedInputMethodsForCurrentUser() {
4544 if (mService != null) {
4545 try {
4546 return mService.getPermittedInputMethodsForCurrentUser();
4547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004548 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004549 }
4550 }
4551 return null;
4552 }
4553
4554 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004555 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4556 * currently installed it.
4557 *
4558 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4559 *
4560 * @return List of package names to keep cached.
4561 * @hide
4562 */
4563 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4564 if (mService != null) {
4565 try {
4566 return mService.getKeepUninstalledPackages(admin);
4567 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004568 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004569 }
4570 }
4571 return null;
4572 }
4573
4574 /**
4575 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4576 * currently installed it.
4577 *
4578 * <p>Please note that setting this policy does not imply that specified apps will be
4579 * automatically pre-cached.</p>
4580 *
4581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4582 * @param packageNames List of package names to keep cached.
4583 * @hide
4584 */
4585 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4586 @NonNull List<String> packageNames) {
4587 if (mService != null) {
4588 try {
4589 mService.setKeepUninstalledPackages(admin, packageNames);
4590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004591 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004592 }
4593 }
4594 }
4595
4596 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004597 * Called by a device owner to create a user with the specified name. The UserHandle returned
4598 * by this method should not be persisted as user handles are recycled as users are removed and
4599 * created. If you need to persist an identifier for this user, use
4600 * {@link UserManager#getSerialNumberForUser}.
4601 *
4602 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4603 * @param name the user's name
4604 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004605 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4606 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004607 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004608 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004609 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004610 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004611 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004612 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004613 return null;
4614 }
4615
4616 /**
Jason Monk03978a42014-06-10 15:05:30 -04004617 * Called by a device owner to create a user with the specified name. The UserHandle returned
4618 * by this method should not be persisted as user handles are recycled as users are removed and
4619 * created. If you need to persist an identifier for this user, use
4620 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4621 * immediately.
4622 *
4623 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4624 * as registered as an active admin on the new user. The profile owner package will be
4625 * installed on the new user if it already is installed on the device.
4626 *
4627 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4628 * profileOwnerComponent when onEnable is called.
4629 *
4630 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4631 * @param name the user's name
4632 * @param ownerName the human readable name of the organisation associated with this DPM.
4633 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4634 * the user.
4635 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4636 * on the new user.
4637 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004638 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4639 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004640 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004641 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004642 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004643 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004644 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004645 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4646 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004647 return null;
4648 }
4649
4650 /**
phweissa92e1212016-01-25 17:14:10 +01004651 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004652 */
4653 public static final int SKIP_SETUP_WIZARD = 0x0001;
4654
4655 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004656 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4657 * ephemeral.
4658 * @hide
4659 */
4660 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4661
4662 /**
phweissa92e1212016-01-25 17:14:10 +01004663 * Called by a device owner to create a user with the specified name and a given component of
4664 * the calling package as profile owner. The UserHandle returned by this method should not be
4665 * persisted as user handles are recycled as users are removed and created. If you need to
4666 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4667 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004668 *
phweissa92e1212016-01-25 17:14:10 +01004669 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4670 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4671 * will be registered as an active admin on the new user. The profile owner package will be
4672 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004673 *
4674 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4675 * started for the first time. Then the extras will be passed to the admin when
4676 * onEnable is called.
4677 *
4678 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4679 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004680 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4681 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4682 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004683 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4684 * user.
phweissa92e1212016-01-25 17:14:10 +01004685 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004686 * @see UserHandle
4687 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4688 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004689 */
4690 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004691 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4692 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004693 try {
phweissa92e1212016-01-25 17:14:10 +01004694 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004695 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004696 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01004697 }
phweiss343fb332016-01-25 14:48:59 +01004698 }
4699
4700 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004701 * Called by a device owner to remove a user and all associated data. The primary user can
4702 * not be removed.
4703 *
4704 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4705 * @param userHandle the user to remove.
4706 * @return {@code true} if the user was removed, {@code false} otherwise.
4707 */
Robin Lee25e26452015-06-02 09:56:29 -07004708 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004709 try {
4710 return mService.removeUser(admin, userHandle);
4711 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004712 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04004713 }
4714 }
4715
4716 /**
Jason Monk582d9112014-07-09 19:57:08 -04004717 * Called by a device owner to switch the specified user to the foreground.
4718 *
4719 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4720 * @param userHandle the user to switch to; null will switch to primary.
4721 * @return {@code true} if the switch was successful, {@code false} otherwise.
4722 *
4723 * @see Intent#ACTION_USER_FOREGROUND
4724 */
Robin Lee25e26452015-06-02 09:56:29 -07004725 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004726 try {
4727 return mService.switchUser(admin, userHandle);
4728 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004729 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04004730 }
4731 }
4732
4733 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004734 * Retrieves the application restrictions for a given target application running in the calling
4735 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004736 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004737 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4738 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4739 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004740 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004741 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4742 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004743 * @param packageName The name of the package to fetch restricted settings of.
4744 * @return {@link Bundle} of settings corresponding to what was set last time
4745 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4746 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004747 *
4748 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004749 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004750 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004751 if (mService != null) {
4752 try {
4753 return mService.getApplicationRestrictions(admin, packageName);
4754 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004755 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004756 }
4757 }
4758 return null;
4759 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004760
4761 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004762 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004763 * <p>
4764 * The calling device admin must be a profile or device owner; if it is not,
4765 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004766 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004767 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4768 * with.
4769 * @param key The key of the restriction. See the constants in
4770 * {@link android.os.UserManager} for the list of keys.
4771 */
Robin Lee25e26452015-06-02 09:56:29 -07004772 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004773 if (mService != null) {
4774 try {
4775 mService.setUserRestriction(admin, key, true);
4776 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004777 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004778 }
4779 }
4780 }
4781
4782 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004783 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004784 * <p>
4785 * The calling device admin must be a profile or device owner; if it is not,
4786 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004787 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004788 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4789 * with.
4790 * @param key The key of the restriction. See the constants in
4791 * {@link android.os.UserManager} for the list of keys.
4792 */
Robin Lee25e26452015-06-02 09:56:29 -07004793 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004794 if (mService != null) {
4795 try {
4796 mService.setUserRestriction(admin, key, false);
4797 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004798 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004799 }
4800 }
4801 }
Adam Connors010cfd42014-04-16 12:48:13 +01004802
4803 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004804 * Called by a profile or device owner to get user restrictions set with
4805 * {@link #addUserRestriction(ComponentName, String)}.
4806 * <p>
4807 * The target user may have more restrictions set by the system or other device owner / profile
4808 * owner. To get all the user restrictions currently set, use
4809 * {@link UserManager#getUserRestrictions()}.
4810 *
4811 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004812 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004813 */
4814 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004815 return getUserRestrictions(admin, myUserId());
4816 }
4817
4818 /** @hide per-user version */
4819 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004820 Bundle ret = null;
4821 if (mService != null) {
4822 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004823 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004824 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004825 throw e.rethrowFromSystemServer();
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004826 }
4827 }
4828 return ret == null ? new Bundle() : ret;
4829 }
4830
4831 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004832 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004833 * is unavailable for use, but the data and actual package file remain.
4834 *
4835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004836 * @param packageName The name of the package to hide or unhide.
4837 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4838 * unhidden.
4839 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004840 */
Robin Lee25e26452015-06-02 09:56:29 -07004841 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004842 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004843 if (mService != null) {
4844 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004845 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004846 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004847 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004848 }
4849 }
4850 return false;
4851 }
4852
4853 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004854 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004855 *
4856 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004857 * @param packageName The name of the package to retrieve the hidden status of.
4858 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004859 */
Robin Lee25e26452015-06-02 09:56:29 -07004860 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004861 if (mService != null) {
4862 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004863 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004864 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004865 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004866 }
4867 }
4868 return false;
4869 }
4870
4871 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004872 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004873 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004874 *
4875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004876 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004877 */
Robin Lee25e26452015-06-02 09:56:29 -07004878 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004879 if (mService != null) {
4880 try {
4881 mService.enableSystemApp(admin, packageName);
4882 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004883 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004884 }
4885 }
4886 }
4887
4888 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004889 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004890 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004891 *
4892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4893 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004894 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004895 * @return int The number of activities that matched the intent and were installed.
4896 */
Robin Lee25e26452015-06-02 09:56:29 -07004897 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004898 if (mService != null) {
4899 try {
4900 return mService.enableSystemAppWithIntent(admin, intent);
4901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004902 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004903 }
4904 }
4905 return 0;
4906 }
4907
4908 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004909 * Called by a device owner or profile owner to disable account management for a specific type
4910 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004911 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004912 * <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 +01004913 * security exception will be thrown.
4914 *
4915 * <p>When account management is disabled for an account type, adding or removing an account
4916 * of that type will not be possible.
4917 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004918 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4919 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4920 * management for a specific type is disabled.
4921 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004922 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4923 * @param accountType For which account management is disabled or enabled.
4924 * @param disabled The boolean indicating that account management will be disabled (true) or
4925 * enabled (false).
4926 */
Robin Lee25e26452015-06-02 09:56:29 -07004927 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004928 boolean disabled) {
4929 if (mService != null) {
4930 try {
4931 mService.setAccountManagementDisabled(admin, accountType, disabled);
4932 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004933 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01004934 }
4935 }
4936 }
4937
4938 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004939 * Gets the array of accounts for which account management is disabled by the profile owner.
4940 *
4941 * <p> Account management can be disabled/enabled by calling
4942 * {@link #setAccountManagementDisabled}.
4943 *
4944 * @return a list of account types for which account management has been disabled.
4945 *
4946 * @see #setAccountManagementDisabled
4947 */
4948 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004949 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004950 }
4951
4952 /**
4953 * @see #getAccountTypesWithManagementDisabled()
4954 * @hide
4955 */
4956 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004957 if (mService != null) {
4958 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004959 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004960 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004961 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004962 }
4963 }
4964
4965 return null;
4966 }
justinzhang511e0d82014-03-24 16:09:24 -04004967
4968 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004969 * Sets which packages may enter lock task mode.
4970 *
4971 * <p>Any packages that shares uid with an allowed package will also be allowed
4972 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004973 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004974 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004975 * package list results in locked tasks belonging to those packages to be finished.
4976 *
Jason Monkc5185f22014-06-24 11:12:42 -04004977 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004978 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004980 *
4981 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004982 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4983 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004984 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004985 */
Robin Lee25e26452015-06-02 09:56:29 -07004986 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004987 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004988 if (mService != null) {
4989 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004990 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004991 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004992 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04004993 }
4994 }
4995 }
4996
4997 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004998 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004999 *
5000 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005001 * @hide
5002 */
Robin Lee25e26452015-06-02 09:56:29 -07005003 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04005004 if (mService != null) {
5005 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005006 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005007 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005008 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005009 }
5010 }
5011 return null;
5012 }
5013
5014 /**
5015 * This function lets the caller know whether the given component is allowed to start the
5016 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005017 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005018 */
Jason Monkd7b86212014-06-16 13:15:38 -04005019 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04005020 if (mService != null) {
5021 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005022 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005023 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005024 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005025 }
5026 }
5027 return false;
5028 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005029
5030 /**
5031 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5032 * 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 -04005033 * <p>The settings that can be updated with this method are:
5034 * <ul>
5035 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5036 * <li>{@link Settings.Global#AUTO_TIME}</li>
5037 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005038 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005039 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005040 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00005041 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005042 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005043 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01005044 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005045 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01005046 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005047 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005048 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005049 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005050 * <ul>
5051 * <li>{@link Settings.Global#BLUETOOTH_ON}.
5052 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
5053 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
5054 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
5055 * <li>{@link Settings.Global#MODE_RINGER}.
5056 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
5057 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
5058 * <li>{@link Settings.Global#WIFI_ON}.
5059 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
5060 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005061 *
5062 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5063 * @param setting The name of the setting to update.
5064 * @param value The value to update the setting to.
5065 */
Robin Lee25e26452015-06-02 09:56:29 -07005066 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005067 if (mService != null) {
5068 try {
5069 mService.setGlobalSetting(admin, setting, value);
5070 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005071 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005072 }
5073 }
5074 }
5075
5076 /**
5077 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5078 * that the value of the setting is in the correct form for the setting type should be performed
5079 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04005080 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005081 * <ul>
5082 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005083 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005084 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5085 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04005086 * <p>A device owner can additionally update the following settings:
5087 * <ul>
5088 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5089 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5091 * @param setting The name of the setting to update.
5092 * @param value The value to update the setting to.
5093 */
Robin Lee25e26452015-06-02 09:56:29 -07005094 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005095 if (mService != null) {
5096 try {
5097 mService.setSecureSetting(admin, setting, value);
5098 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005099 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005100 }
5101 }
5102 }
5103
Amith Yamasanif20d6402014-05-24 15:34:37 -07005104 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005105 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07005106 * making permission requests of a local or remote administrator of the user.
5107 * <p/>
5108 * Only a profile owner can designate the restrictions provider.
5109 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005110 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07005111 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07005112 * it removes the restrictions provider previously assigned.
5113 */
Robin Lee25e26452015-06-02 09:56:29 -07005114 public void setRestrictionsProvider(@NonNull ComponentName admin,
5115 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005116 if (mService != null) {
5117 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005118 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005119 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005120 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005121 }
5122 }
5123 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005124
5125 /**
5126 * Called by profile or device owners to set the master volume mute on or off.
5127 *
5128 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5129 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
5130 */
Robin Lee25e26452015-06-02 09:56:29 -07005131 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005132 if (mService != null) {
5133 try {
5134 mService.setMasterVolumeMuted(admin, on);
5135 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005136 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005137 }
5138 }
5139 }
5140
5141 /**
5142 * Called by profile or device owners to check whether the master volume mute is on or off.
5143 *
5144 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5145 * @return {@code true} if master volume is muted, {@code false} if it's not.
5146 */
Robin Lee25e26452015-06-02 09:56:29 -07005147 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005148 if (mService != null) {
5149 try {
5150 return mService.isMasterVolumeMuted(admin);
5151 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005152 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005153 }
5154 }
5155 return false;
5156 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005157
5158 /**
5159 * Called by profile or device owners to change whether a user can uninstall
5160 * a package.
5161 *
5162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5163 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005164 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005165 */
Robin Lee25e26452015-06-02 09:56:29 -07005166 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005167 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005168 if (mService != null) {
5169 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005170 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005171 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005172 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005173 }
5174 }
5175 }
5176
5177 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005178 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005179 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005180 * <p>
5181 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07005182 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00005183 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07005184 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005185 *
Robin Lee25e26452015-06-02 09:56:29 -07005186 * @param admin The name of the admin component whose blocking policy will be checked, or
5187 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005188 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005189 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01005190 */
Robin Lee25e26452015-06-02 09:56:29 -07005191 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005192 if (mService != null) {
5193 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005194 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005195 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005196 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005197 }
5198 }
5199 return false;
5200 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005201
5202 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005203 * Called by the profile owner of a managed profile to enable widget providers from a
5204 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07005205 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005206 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07005207 * a package may have zero or more provider components, where each component
5208 * provides a different widget type.
5209 * <p>
5210 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005211 *
5212 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5213 * @param packageName The package from which widget providers are white-listed.
5214 * @return Whether the package was added.
5215 *
5216 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5217 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5218 */
Robin Lee25e26452015-06-02 09:56:29 -07005219 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005220 if (mService != null) {
5221 try {
5222 return mService.addCrossProfileWidgetProvider(admin, packageName);
5223 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005224 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005225 }
5226 }
5227 return false;
5228 }
5229
5230 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005231 * Called by the profile owner of a managed profile to disable widget providers from a given
5232 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07005233 * package should have been added via {@link #addCrossProfileWidgetProvider(
5234 * android.content.ComponentName, String)}.
5235 * <p>
5236 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005237 *
5238 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5239 * @param packageName The package from which widget providers are no longer
5240 * white-listed.
5241 * @return Whether the package was removed.
5242 *
5243 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5244 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5245 */
Esteban Talavera62399912016-01-11 15:37:55 +00005246 public boolean removeCrossProfileWidgetProvider(
5247 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005248 if (mService != null) {
5249 try {
5250 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5251 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005252 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005253 }
5254 }
5255 return false;
5256 }
5257
5258 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005259 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005260 * available in the parent profile.
5261 *
5262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5263 * @return The white-listed package list.
5264 *
5265 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5266 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5267 */
Robin Lee25e26452015-06-02 09:56:29 -07005268 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005269 if (mService != null) {
5270 try {
5271 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5272 if (providers != null) {
5273 return providers;
5274 }
5275 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005276 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005277 }
5278 }
5279 return Collections.emptyList();
5280 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005281
5282 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005283 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005284 *
5285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5286 * @param icon the bitmap to set as the photo.
5287 */
Robin Lee25e26452015-06-02 09:56:29 -07005288 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005289 try {
5290 mService.setUserIcon(admin, icon);
5291 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005292 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005293 }
5294 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005295
5296 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005297 * Called by device owners to set a local system update policy. When a new policy is set,
5298 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005299 *
Robin Lee25e26452015-06-02 09:56:29 -07005300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5301 * components in the device owner package can set system update policies and the
5302 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005303 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005304 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005305 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005306 */
Robin Lee25e26452015-06-02 09:56:29 -07005307 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005308 if (mService != null) {
5309 try {
Robin Lee25e26452015-06-02 09:56:29 -07005310 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005311 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005312 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005313 }
5314 }
5315 }
5316
5317 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005318 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005319 *
Robin Lee25e26452015-06-02 09:56:29 -07005320 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005321 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005322 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005323 if (mService != null) {
5324 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005325 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005326 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005327 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005328 }
5329 }
5330 return null;
5331 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005332
5333 /**
5334 * Called by a device owner to disable the keyguard altogether.
5335 *
5336 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5337 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5338 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5339 * being disabled.
5340 *
5341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005342 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005343 *
5344 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005345 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005346 */
Robin Lee25e26452015-06-02 09:56:29 -07005347 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005348 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005349 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005350 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005351 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005352 }
5353 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005354
5355 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005356 * Called by device owner to disable the status bar. Disabling the status bar blocks
5357 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005358 * a single use device.
5359 *
5360 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005361 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5362 *
5363 * @return {@code false} if attempting to disable the status bar failed.
5364 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005365 */
Robin Lee25e26452015-06-02 09:56:29 -07005366 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005367 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005368 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005369 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005370 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005371 }
5372 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005373
5374 /**
5375 * Callable by the system update service to notify device owners about pending updates.
5376 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5377 * permission.
5378 *
5379 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5380 * when the current pending update was first available. -1 if no update is available.
5381 * @hide
5382 */
5383 @SystemApi
5384 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5385 if (mService != null) {
5386 try {
5387 mService.notifyPendingSystemUpdate(updateReceivedTime);
5388 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005389 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005390 }
5391 }
5392 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005393
5394 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005395 * Called by profile or device owners to set the default response for future runtime permission
5396 * requests by applications. The policy can allow for normal operation which prompts the
5397 * user to grant a permission, or can allow automatic granting or denying of runtime
5398 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005399 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5400 * the permission grant state via {@link #setPermissionGrantState}.
5401 *
5402 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005403 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005404 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005405 * @param admin Which profile or device owner this request is associated with.
5406 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5407 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005408 *
5409 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005410 */
Robin Lee25e26452015-06-02 09:56:29 -07005411 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005412 try {
5413 mService.setPermissionPolicy(admin, policy);
5414 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005415 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005416 }
5417 }
5418
5419 /**
5420 * Returns the current runtime permission policy set by the device or profile owner. The
5421 * default is {@link #PERMISSION_POLICY_PROMPT}.
5422 * @param admin Which profile or device owner this request is associated with.
5423 * @return the current policy for future permission requests.
5424 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005425 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005426 try {
5427 return mService.getPermissionPolicy(admin);
5428 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005429 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005430 }
5431 }
5432
5433 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005434 * Sets the grant state of a runtime permission for a specific application. The state
5435 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5436 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5437 * is denied and the user cannot manage it through the UI, and {@link
5438 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5439 * user cannot manage it through the UI. This might affect all permissions in a
5440 * group that the runtime permission belongs to. This method can only be called
5441 * by a profile or device owner.
5442 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005443 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5444 * revoke the permission. It retains the previous grant, if any.
5445 *
5446 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005447 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005448 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005449 * @param admin Which profile or device owner this request is associated with.
5450 * @param packageName The application to grant or revoke a permission to.
5451 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005452 * @param grantState The permission grant state which is one of {@link
5453 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5454 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5455 * @return whether the permission was successfully granted or revoked.
5456 *
5457 * @see #PERMISSION_GRANT_STATE_DENIED
5458 * @see #PERMISSION_GRANT_STATE_DEFAULT
5459 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005460 */
Robin Lee25e26452015-06-02 09:56:29 -07005461 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005462 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005463 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005464 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005465 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005466 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005467 }
5468 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005469
5470 /**
5471 * Returns the current grant state of a runtime permission for a specific application.
5472 *
5473 * @param admin Which profile or device owner this request is associated with.
5474 * @param packageName The application to check the grant state for.
5475 * @param permission The permission to check for.
5476 * @return the current grant state specified by device policy. If the profile or device owner
5477 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5478 * This does not indicate whether or not the permission is currently granted for the package.
5479 *
5480 * <p/>If a grant state was set by the profile or device owner, then the return value will
5481 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5482 * which indicates if the permission is currently denied or granted.
5483 *
5484 * @see #setPermissionGrantState(ComponentName, String, String, int)
5485 * @see PackageManager#checkPermission(String, String)
5486 */
Robin Lee25e26452015-06-02 09:56:29 -07005487 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005488 String permission) {
5489 try {
5490 return mService.getPermissionGrantState(admin, packageName, permission);
5491 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005492 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005493 }
5494 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005495
5496 /**
5497 * Returns if provisioning a managed profile or device is possible or not.
5498 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5499 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5500 * Note that even if this method returns true, there is a slight possibility that the
5501 * provisioning will not be allowed when it is actually initiated because some event has
5502 * happened in between.
5503 * @return if provisioning a managed profile or device is possible or not.
5504 * @throws IllegalArgumentException if the supplied action is not valid.
5505 */
5506 public boolean isProvisioningAllowed(String action) {
5507 try {
5508 return mService.isProvisioningAllowed(action);
5509 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005510 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005511 }
5512 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005513
5514 /**
5515 * @hide
5516 * Return if this user is a managed profile of another user. An admin can become the profile
5517 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5518 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5519 * @param admin Which profile owner this request is associated with.
5520 * @return if this user is a managed profile of another user.
5521 */
5522 public boolean isManagedProfile(@NonNull ComponentName admin) {
5523 try {
5524 return mService.isManagedProfile(admin);
5525 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005526 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005527 }
5528 }
5529
5530 /**
5531 * @hide
5532 * Return if this user is a system-only user. An admin can manage a device from a system only
5533 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5534 * @param admin Which device owner this request is associated with.
5535 * @return if this user is a system-only user.
5536 */
5537 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5538 try {
5539 return mService.isSystemOnlyUser(admin);
5540 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005541 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005542 }
5543 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005544
5545 /**
5546 * Called by device owner to get the MAC address of the Wi-Fi device.
5547 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005548 * @param admin Which device owner this request is associated with.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005549 * @return the MAC address of the Wi-Fi device, or null when the information is not
5550 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5551 *
5552 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5553 */
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005554 public String getWifiMacAddress(@NonNull ComponentName admin) {
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005555 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005556 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005557 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005558 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005559 }
5560 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005561
5562 /**
5563 * Called by device owner to reboot the device.
5564 */
5565 public void reboot(@NonNull ComponentName admin) {
5566 try {
5567 mService.reboot(admin);
5568 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005569 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005570 }
5571 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005572
5573 /**
5574 * Called by a device admin to set the short support message. This will
5575 * be displayed to the user in settings screens where funtionality has
5576 * been disabled by the admin.
5577 *
5578 * The message should be limited to a short statement such as
5579 * "This setting is disabled by your administrator. Contact someone@example.com
5580 * for support."
5581 * If the message is longer than 200 characters it may be truncated.
5582 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005583 * <p>If the short support message needs to be localized, it is the responsibility of the
5584 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5585 * and set a new version of this string accordingly.
5586 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005587 * @see #setLongSupportMessage
5588 *
5589 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5590 * @param message Short message to be displayed to the user in settings or null to
5591 * clear the existing message.
5592 */
5593 public void setShortSupportMessage(@NonNull ComponentName admin,
5594 @Nullable String message) {
5595 if (mService != null) {
5596 try {
5597 mService.setShortSupportMessage(admin, message);
5598 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005599 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005600 }
5601 }
5602 }
5603
5604 /**
5605 * Called by a device admin to get the short support message.
5606 *
5607 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5608 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5609 * or null if no message has been set.
5610 */
5611 public String getShortSupportMessage(@NonNull ComponentName admin) {
5612 if (mService != null) {
5613 try {
5614 return mService.getShortSupportMessage(admin);
5615 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005616 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005617 }
5618 }
5619 return null;
5620 }
5621
5622 /**
5623 * Called by a device admin to set the long support message. This will
5624 * be displayed to the user in the device administators settings screen.
5625 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005626 * <p>If the long support message needs to be localized, it is the responsibility of the
5627 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5628 * and set a new version of this string accordingly.
5629 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005630 * @see #setShortSupportMessage
5631 *
5632 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5633 * @param message Long message to be displayed to the user in settings or null to
5634 * clear the existing message.
5635 */
5636 public void setLongSupportMessage(@NonNull ComponentName admin,
5637 @Nullable String message) {
5638 if (mService != null) {
5639 try {
5640 mService.setLongSupportMessage(admin, message);
5641 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005642 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005643 }
5644 }
5645 }
5646
5647 /**
5648 * Called by a device admin to get the long support message.
5649 *
5650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5651 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5652 * or null if no message has been set.
5653 */
5654 public String getLongSupportMessage(@NonNull ComponentName admin) {
5655 if (mService != null) {
5656 try {
5657 return mService.getLongSupportMessage(admin);
5658 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005659 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005660 }
5661 }
5662 return null;
5663 }
5664
5665 /**
5666 * Called by the system to get the short support message.
5667 *
5668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5669 * @param userHandle user id the admin is running as.
5670 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5671 *
5672 * @hide
5673 */
5674 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5675 if (mService != null) {
5676 try {
5677 return mService.getShortSupportMessageForUser(admin, userHandle);
5678 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005679 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005680 }
5681 }
5682 return null;
5683 }
5684
5685
5686 /**
5687 * Called by the system to get the long support message.
5688 *
5689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5690 * @param userHandle user id the admin is running as.
5691 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5692 *
5693 * @hide
5694 */
5695 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5696 if (mService != null) {
5697 try {
5698 return mService.getLongSupportMessageForUser(admin, userHandle);
5699 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005700 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005701 }
5702 }
5703 return null;
5704 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005705
5706 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005707 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5708 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005709 *
5710 * <p> Note only some methods will work on the parent Manager.
5711 *
5712 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5713 */
5714 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5715 try {
5716 if (!mService.isManagedProfile(admin)) {
5717 throw new SecurityException("The current user does not have a parent profile.");
5718 }
5719 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005720 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005721 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005722 }
5723 }
5724
5725 /**
5726 * Called by device owner to control the device logging feature. Logging can only be
5727 * enabled on single user devices where the sole user is managed by the device owner.
5728 *
5729 * <p> Device logs contain various information intended for security auditing purposes.
5730 * See {@link SecurityEvent} for details.
5731 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005732 * <p>There must be only one user on the device, managed by the device owner.
5733 * Otherwise a {@link SecurityException} will be thrown.
5734 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005735 * @param admin Which device owner this request is associated with.
5736 * @param enabled whether device logging should be enabled or not.
5737 * @see #retrieveDeviceLogs
5738 */
5739 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5740 try {
5741 mService.setDeviceLoggingEnabled(admin, enabled);
5742 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005743 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005744 }
5745 }
5746
5747 /**
5748 * Return whether device logging is enabled or not by the device owner.
5749 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005750 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
5751 * thrown.
5752 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005753 * @param admin Which device owner this request is associated with.
5754 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5755 */
5756 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5757 try {
5758 return mService.getDeviceLoggingEnabled(admin);
5759 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005760 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005761 }
5762 }
5763
5764 /**
5765 * Called by device owner to retrieve all new device logging entries since the last call to
5766 * this API after device boots.
5767 *
5768 * <p> Access to the logs is rate limited and it will only return new logs after the device
5769 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5770 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005771 * <p>There must be only one user on the device, managed by the device owner.
5772 * Otherwise a {@link SecurityException} will be thrown.
5773 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005774 * @param admin Which device owner this request is associated with.
5775 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5776 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5777 */
5778 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5779 try {
5780 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5781 if (list != null) {
5782 return list.getList();
5783 } else {
5784 // Rate limit exceeded.
5785 return null;
5786 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005787 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005788 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005789 }
5790 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005791
5792 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005793 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5794 * profile.
5795 *
5796 * @hide
5797 */
5798 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5799 mContext.checkSelfPermission(
5800 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5801 if (!uInfo.isManagedProfile()) {
5802 throw new SecurityException("The user " + uInfo.id
5803 + " does not have a parent profile.");
5804 }
5805 return new DevicePolicyManager(mContext, true);
5806 }
5807
5808 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005809 * Called by device owners to retrieve device logs from before the device's last reboot.
5810 *
5811 * <p>
5812 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5813 * corruption-free during power cycles, due to hardware variations and limitations. As a
5814 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5815 * </strong>
5816 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005817 * <p>There must be only one user on the device, managed by the device owner.
5818 * Otherwise a {@link SecurityException} will be thrown.
5819 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005820 * @param admin Which device owner this request is associated with.
5821 * @return Device logs from before the latest reboot of the system.
5822 */
5823 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5824 try {
5825 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5826 return list.getList();
5827 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005828 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005829 }
5830 }
5831
5832 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005833 * Called by a profile owner of a managed profile to set the color used for customization.
5834 * This color is used as background color of the confirm credentials screen for that user.
5835 * The default color is {@link android.graphics.Color#GRAY}.
5836 *
5837 * <p>The confirm credentials screen can be created using
5838 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5839 *
5840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5841 * @param color The 32bit representation of the color to be used.
5842 */
5843 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5844 try {
5845 mService.setOrganizationColor(admin, color);
5846 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005847 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005848 }
5849 }
5850
5851 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005852 * @hide
5853 *
5854 * Sets the color used for customization.
5855 *
5856 * @param color The 32bit representation of the color to be used.
5857 * @param userId which user to set the color to.
5858 * @RequiresPermission(allOf = {
5859 * Manifest.permission.MANAGE_USERS,
5860 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5861 */
5862 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5863 try {
5864 mService.setOrganizationColorForUser(color, userId);
5865 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005866 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005867 }
5868 }
5869
5870 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005871 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5872 * This color is used as background color of the confirm credentials screen for that user.
5873 *
5874 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5875 * @return The 32bit representation of the color to be used.
5876 */
5877 public int getOrganizationColor(@NonNull ComponentName admin) {
5878 try {
5879 return mService.getOrganizationColor(admin);
5880 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005881 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005882 }
5883 }
5884
5885 /**
5886 * @hide
5887 * Retrieve the customization color for a given user.
5888 *
5889 * @param userHandle The user id of the user we're interested in.
5890 * @return The 32bit representation of the color to be used.
5891 */
5892 public int getOrganizationColorForUser(int userHandle) {
5893 try {
5894 return mService.getOrganizationColorForUser(userHandle);
5895 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005896 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005897 }
5898 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005899
5900 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005901 * Called by a profile owner of a managed profile to set the name of the organization under
5902 * management.
5903 *
5904 * <p>If the organization name needs to be localized, it is the responsibility of the
5905 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5906 * and set a new version of this string accordingly.
5907 *
5908 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5909 * @param title The organization name or {@code null} to clear a previously set name.
5910 */
5911 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5912 try {
5913 mService.setOrganizationName(admin, title);
5914 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005915 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005916 }
5917 }
5918
5919 /**
5920 * Called by a profile owner of a managed profile to retrieve the name of the organization
5921 * under management.
5922 *
5923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5924 * @return The organization name or {@code null} if none is set.
5925 */
5926 public String getOrganizationName(@NonNull ComponentName admin) {
5927 try {
5928 return mService.getOrganizationName(admin);
5929 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005930 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005931 }
5932 }
5933
5934 /**
5935 * Retrieve the default title message used in the confirm credentials screen for a given user.
5936 *
5937 * @param userHandle The user id of the user we're interested in.
5938 * @return The organization name or {@code null} if none is set.
5939 *
5940 * @hide
5941 */
5942 public String getOrganizationNameForUser(int userHandle) {
5943 try {
5944 return mService.getOrganizationNameForUser(userHandle);
5945 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005946 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005947 }
5948 }
5949
5950 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005951 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5952 * return {@link #STATE_USER_UNMANAGED}
5953 * @hide
5954 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00005955 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00005956 @UserProvisioningState
5957 public int getUserProvisioningState() {
5958 if (mService != null) {
5959 try {
5960 return mService.getUserProvisioningState();
5961 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005962 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00005963 }
5964 }
5965 return STATE_USER_UNMANAGED;
5966 }
5967
5968 /**
5969 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5970 *
5971 * @param state to store
5972 * @param userHandle for user
5973 * @hide
5974 */
5975 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5976 if (mService != null) {
5977 try {
5978 mService.setUserProvisioningState(state, userHandle);
5979 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005980 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00005981 }
5982 }
5983 }
5984
5985 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005986 * @hide
5987 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5988 * affiliated if it is managed by the same entity as the device.
5989 *
5990 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5991 * user/profile is considered affiliated if the following conditions are both met:
5992 * <ul>
5993 * <li>The device owner and the user's/profile's profile owner have called this method,
5994 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5995 * and a profile owner intersect, they must have come from the same source, which means that
5996 * the device owner and profile owner are controlled by the same entity.</li>
5997 * <li>The device owner's and profile owner's package names are the same.</li>
5998 * </ul>
5999 *
6000 * @param admin Which profile or device owner this request is associated with.
6001 * @param ids A set of opaque affiliation ids.
6002 */
6003 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
6004 try {
6005 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
6006 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006007 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006008 }
6009 }
6010
6011 /**
6012 * @hide
6013 * Returns whether this user/profile is affiliated with the device. See
6014 * {@link #setAffiliationIds} for the definition of affiliation.
6015 *
6016 * @return whether this user/profile is affiliated with the device.
6017 */
6018 public boolean isAffiliatedUser() {
6019 try {
6020 return mService != null && mService.isAffiliatedUser();
6021 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006022 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006023 }
6024 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006025
6026 /**
6027 * @hide
6028 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6029 * to be started
6030 * @param packageName the package to check for
6031 * @return whether the uninstall intent for {@code packageName} is pending
6032 */
6033 public boolean isUninstallInQueue(String packageName) {
6034 try {
6035 return mService.isUninstallInQueue(packageName);
6036 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006037 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006038 }
6039 }
6040
6041 /**
6042 * @hide
6043 * @param packageName the package containing active DAs to be uninstalled
6044 */
6045 public void uninstallPackageWithActiveAdmins(String packageName) {
6046 try {
6047 mService.uninstallPackageWithActiveAdmins(packageName);
6048 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006049 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006050 }
6051 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006052}