blob: 08b7d62963a465b6c3012e6b5b528c70a030dbcf [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
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000034import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010035import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040043import android.provider.Settings;
Ricky Wai494b95d2015-11-20 16:07:15 +000044import android.provider.ContactsContract.Directory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010045import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070046import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080047import android.util.Log;
48
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070049import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040050import com.android.org.conscrypt.TrustedCertificateStore;
51
Jessica Hummel91da58d2014-04-10 17:39:43 +010052import org.xmlpull.v1.XmlPullParserException;
53
Maggie Benthallda51e682013-08-08 22:35:44 -040054import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080055import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070056import java.net.InetSocketAddress;
57import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010058import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010059import java.security.PrivateKey;
60import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040061import java.security.cert.CertificateException;
62import java.security.cert.CertificateFactory;
63import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010064import java.security.spec.PKCS8EncodedKeySpec;
65import java.security.spec.InvalidKeySpecException;
66import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070067import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070068import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080069import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080070
71/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000072 * Public interface for managing policies enforced on a device. Most clients of this class must be
73 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000074 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000075 * a device administrator may be registered as either a profile or device owner. A given method is
76 * accessible to all device administrators unless the documentation for that method specifies that
77 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 *
79 * <div class="special reference">
80 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000081 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070083 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080084 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 */
86public class DevicePolicyManager {
87 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080088
89 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070091
Makoto Onukic8a5a552015-11-19 14:29:12 -080092 private static final String REMOTE_EXCEPTION_MESSAGE =
93 "Failed to talk with device policy manager service";
94
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070095 private DevicePolicyManager(Context context) {
96 this(context, IDevicePolicyManager.Stub.asInterface(
97 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 }
99
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800100 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700101 @VisibleForTesting
102 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
103 mContext = context;
104 mService = service;
105 }
106
107 /** @hide */
108 public static DevicePolicyManager create(Context context) {
109 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800110 return me.mService != null ? me : null;
111 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700112
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700113 /** @hide test will override it. */
114 @VisibleForTesting
115 protected int myUserId() {
116 return UserHandle.myUserId();
117 }
118
Dianne Hackbornd6847842010-01-12 18:14:19 -0800119 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000120 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000121 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100122 * <p>A managed profile allows data separation for example for the usage of a
123 * device as a personal and corporate device. The user which provisioning is started from and
124 * the managed profile share a launcher.
125 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800126 * <p>This intent will typically be sent by a mobile device management application (MDM).
127 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
128 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100129 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000130 * <p>It is possible to check if provisioning is allowed or not by querying the method
131 * {@link #isProvisioningAllowed(String)}.
132 *
133 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000134 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700135 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000136 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
137 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000138 *
139 * <p> The intent may also contain the following extras:
140 * <ul>
141 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
142 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
143 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000144 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000145 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
146 * in the provisioning intent. The
147 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
148 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
149 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100150 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100151 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
152 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100153 *
154 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
155 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
156 * the provisioning flow was successful, although this doesn't guarantee the full flow will
157 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
158 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000159 */
160 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
161 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100162 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000163
164 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000165 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000166 * Activity action: Starts the provisioning flow which sets up a managed user.
167 *
168 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800169 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000170 * owner who has full control over the user. Provisioning can only happen before user setup has
171 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
172 * allowed.
173 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000174 * <p>This intent should contain the extra
175 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000176 *
177 * <p> If provisioning fails, the device returns to its previous state.
178 *
179 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
180 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
181 * the provisioning flow was successful, although this doesn't guarantee the full flow will
182 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
183 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000184 */
185 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
186 public static final String ACTION_PROVISION_MANAGED_USER
187 = "android.app.action.PROVISION_MANAGED_USER";
188
189 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100190 * Activity action: Starts the provisioning flow which sets up a managed device.
191 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
192 *
193 * <p> During device owner provisioning a device admin app is set as the owner of the device.
194 * A device owner has full control over the device. The device owner can not be modified by the
195 * user.
196 *
197 * <p> A typical use case would be a device that is owned by a company, but used by either an
198 * employee or client.
199 *
200 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000201 * It is possible to check if provisioning is allowed or not by querying the method
202 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100203 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000204 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 * <ul>
206 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
207 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
208 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100209 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000210 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000211 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100212 * </ul>
213 *
214 * <p> When device owner provisioning has completed, an intent of the type
215 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
216 * device owner.
217 *
218 * <p> If provisioning fails, the device is factory reset.
219 *
Alan Treadway4582f812015-07-28 11:49:35 +0100220 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
221 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
222 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
223 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100224 */
225 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
226 public static final String ACTION_PROVISION_MANAGED_DEVICE
227 = "android.app.action.PROVISION_MANAGED_DEVICE";
228
229 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000230 * Activity action: Starts the provisioning flow which sets up a managed device.
231 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
232 *
233 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
234 * management state that is distinct from that reached by
235 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
236 * user, and only has control over device-wide policies, not individual users and their data.
237 * The primary benefit is that multiple non-system users are supported when provisioning using
238 * this form of device management.
239 *
240 * <p> During device owner provisioning a device admin app is set as the owner of the device.
241 * A device owner has full control over the device. The device owner can not be modified by the
242 * user.
243 *
244 * <p> A typical use case would be a device that is owned by a company, but used by either an
245 * employee or client.
246 *
247 * <p> An intent with this action can be sent only on an unprovisioned device.
248 * It is possible to check if provisioning is allowed or not by querying the method
249 * {@link #isProvisioningAllowed(String)}.
250 *
251 * <p>The intent contains the following extras:
252 * <ul>
253 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
254 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
255 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
256 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
257 * </ul>
258 *
259 * <p> When device owner provisioning has completed, an intent of the type
260 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
261 * device owner.
262 *
263 * <p> If provisioning fails, the device is factory reset.
264 *
265 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
266 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
267 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
268 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
269 *
270 * @hide
271 */
272 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
273 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
274 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
275
276 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100277 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100278 * allows a mobile device management application or NFC programmer application which starts
279 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100280 * <p>
281 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
282 * sends the intent to pass data to itself on the newly created profile.
283 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
284 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100285 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
286 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
287 * message should contain a stringified {@link java.util.Properties} instance, whose string
288 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
289 * management application after provisioning.
290 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100291 * <p>
292 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700293 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
294 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100295 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100296 */
297 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100298 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100299
300 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100301 * A String extra holding the package name of the mobile device management application that
302 * will be set as the profile owner or device owner.
303 *
304 * <p>If an application starts provisioning directly via an intent with action
305 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
306 * application that started provisioning. The package will be set as profile owner in that case.
307 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000308 * <p>This package is set as device owner when device owner provisioning is started by an NFC
309 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000310 *
311 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700312 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000313
314 * @see DeviceAdminReceiver
315 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100316 * supported, but only if there is only one device admin receiver in the package that requires
317 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000318 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000319 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000320 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100321 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000322
323 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000324 * A ComponentName extra indicating the device admin receiver of the mobile device management
325 * application that will be set as the profile owner or device owner and active admin.
326 *
327 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100328 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
329 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
330 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000331 *
332 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100333 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
334 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400335 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000336 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000337 *
338 * @see DeviceAdminReceiver
339 */
340 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
341 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
342
343 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000344 * An {@link android.accounts.Account} extra holding the account to migrate during managed
345 * profile provisioning. If the account supplied is present in the primary user, it will be
346 * copied, along with its credentials to the managed profile and removed from the primary user.
347 *
348 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
349 */
350
351 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
352 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
353
354 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100355 * A String extra that, holds the email address of the account which a managed profile is
356 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
357 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100358 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100359 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
360 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100361 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
362 * contains this extra, it is forwarded in the
363 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
364 * device management application that was set as the profile owner during provisioning.
365 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100366 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100367 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
368 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100369
370 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000371 * A integer extra indicating the predominant color to show during the provisioning.
372 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000373 *
374 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
375 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
376 */
377 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
378 "android.app.extra.PROVISIONING_MAIN_COLOR";
379
380 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000381 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700382 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000383 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100384 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
385 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000386 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000387 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
388 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000389
390 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100391 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
392 * will be set to.
393 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000394 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
395 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100396 */
397 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100398 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100399
400 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100401 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
402 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100403 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000404 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
405 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100406 */
407 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100408 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100409
410 /**
411 * A String extra holding the {@link java.util.Locale} that the device will be set to.
412 * Format: xx_yy, where xx is the language code, and yy the country code.
413 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000414 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
415 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100416 */
417 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100418 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100419
420 /**
421 * A String extra holding the ssid of the wifi network that should be used during nfc device
422 * owner provisioning for downloading the mobile device management application.
423 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000424 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
425 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100426 */
427 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100428 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100429
430 /**
431 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
432 * is hidden or not.
433 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000434 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
435 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100436 */
437 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100438 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100439
440 /**
441 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100442 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
443 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100444 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000445 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
446 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100447 */
448 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100449 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100450
451 /**
452 * A String extra holding the password of the wifi network in
453 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
454 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000455 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
456 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100457 */
458 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100459 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100460
461 /**
462 * A String extra holding the proxy host for the wifi network in
463 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
464 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000465 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
466 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100467 */
468 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100469 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100470
471 /**
472 * An int extra holding the proxy port for the wifi network in
473 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
474 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000475 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
476 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100477 */
478 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100479 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100480
481 /**
482 * A String extra holding the proxy bypass for the wifi network in
483 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
484 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000485 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
486 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100487 */
488 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100489 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100490
491 /**
492 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
493 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
494 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000495 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
496 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100497 */
498 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100499 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100500
501 /**
502 * A String extra holding a url that specifies the download location of the device admin
503 * package. When not provided it is assumed that the device admin package is already installed.
504 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000505 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
506 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100507 */
508 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100509 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100510
511 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400512 * An int extra holding a minimum required version code for the device admin package. If the
513 * device admin is already installed on the device, it will only be re-downloaded from
514 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
515 * installed package is less than this version code.
516 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400517 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400518 * provisioning via an NFC bump.
519 */
520 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
521 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
522
523 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100524 * A String extra holding a http cookie header which should be used in the http request to the
525 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
526 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
528 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100529 */
530 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100531 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100532
533 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100534 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
535 * the file at download location specified in
536 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100537 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100538 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100539 * present. The provided checksum should match the checksum of the file at the download
540 * location. If the checksum doesn't match an error will be shown to the user and the user will
541 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000543 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
544 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100545 *
546 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
547 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700548 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100549 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100550 */
551 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100552 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100553
554 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100555 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100556 * android package archive at the download location specified in {@link
557 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
558 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100559 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100560 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
561 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
562 *
563 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100564 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100565 * the download location. If the checksum does not match an error will be shown to the user and
566 * the user will be asked to factory reset the device.
567 *
568 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
569 * provisioning via an NFC bump.
570 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100571 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
572 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100573
574 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000575 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
576 * has completed successfully.
577 *
578 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700579 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000580 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800581 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000582 * corresponds to the account requested to be migrated at provisioning time, if any.
583 */
584 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
585 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
586 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
587
588 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400589 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500590 * provisioning.
591 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400592 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100593 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500594 */
595 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
596 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
597
598 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000599 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
600 * provisioning. If this extra is not passed, a default image will be shown.
601 * <h5>The following URI schemes are accepted:</h5>
602 * <ul>
603 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
604 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
605 * </ul>
606 *
607 * <p> It is the responsability of the caller to provide an image with a reasonable
608 * pixed density for the device.
609 *
610 * <p> If a content: URI is passed, the intent should have the flag
611 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
612 * {@link android.content.ClipData} of the intent too.
613 *
614 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
615 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
616 */
617 public static final String EXTRA_PROVISIONING_LOGO_URI =
618 "android.app.extra.PROVISIONING_LOGO_URI";
619
620 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400621 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400623 * <p>During device owner provisioning a device admin app is set as the owner of the device.
624 * A device owner has full control over the device. The device owner can not be modified by the
625 * user and the only way of resetting the device is if the device owner app calls a factory
626 * reset.
627 *
628 * <p> A typical use case would be a device that is owned by a company, but used by either an
629 * employee or client.
630 *
631 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000633 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100634 * contains the following properties:
635 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400636 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
637 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100638 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400639 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100640 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
641 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
642 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
643 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
644 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
645 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
646 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
647 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
648 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
649 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100650 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
651 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
652 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000654 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700655 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400656 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
657 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
658 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400659 */
660 public static final String MIME_TYPE_PROVISIONING_NFC
661 = "application/com.android.managedprovisioning";
662
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100663 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800664 * Activity action: ask the user to add a new device administrator to the system.
665 * The desired policy is the ComponentName of the policy in the
666 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
667 * bring the user through adding the device administrator to the system (or
668 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700669 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800670 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
671 * field to provide the user with additional explanation (in addition
672 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800673 *
674 * <p>If your administrator is already active, this will ordinarily return immediately (without
675 * user intervention). However, if your administrator has been updated and is requesting
676 * additional uses-policy flags, the user will be presented with the new list. New policies
677 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 */
679 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
680 public static final String ACTION_ADD_DEVICE_ADMIN
681 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700682
Dianne Hackbornd6847842010-01-12 18:14:19 -0800683 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700684 * @hide
685 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700686 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700687 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700688 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
689 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700690 * to remotely control restrictions on the user.
691 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800692 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700693 * result of whether or not the user approved the action. If approved, the result will
694 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
695 * as a profile owner.
696 *
697 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
698 * field to provide the user with additional explanation (in addition
699 * to your component's description) about what is being added.
700 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700701 * <p>If there is already a profile owner active or the caller is not a system app, the
702 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700703 */
704 @SystemApi
705 public static final String ACTION_SET_PROFILE_OWNER
706 = "android.app.action.SET_PROFILE_OWNER";
707
708 /**
709 * @hide
710 * Name of the profile owner admin that controls the user.
711 */
712 @SystemApi
713 public static final String EXTRA_PROFILE_OWNER_NAME
714 = "android.app.extra.PROFILE_OWNER_NAME";
715
716 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100717 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700718 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700719 *
Jim Miller284b62e2010-06-08 14:27:42 -0700720 * @hide
721 */
722 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
723 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
724
725 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100726 * Broadcast action: sent when the device owner is set or changed.
727 *
728 * This broadcast is sent only to the primary user.
729 * @see #ACTION_PROVISION_MANAGED_DEVICE
730 */
731 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
732 public static final String ACTION_DEVICE_OWNER_CHANGED
733 = "android.app.action.DEVICE_OWNER_CHANGED";
734
735 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800736 * The ComponentName of the administrator component.
737 *
738 * @see #ACTION_ADD_DEVICE_ADMIN
739 */
740 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700741
Dianne Hackbornd6847842010-01-12 18:14:19 -0800742 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800743 * An optional CharSequence providing additional explanation for why the
744 * admin is being added.
745 *
746 * @see #ACTION_ADD_DEVICE_ADMIN
747 */
748 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700749
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800750 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700751 * Activity action: have the user enter a new password. This activity should
752 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
753 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
754 * enter a new password that meets the current requirements. You can use
755 * {@link #isActivePasswordSufficient()} to determine whether you need to
756 * have the user select a new password in order to meet the current
757 * constraints. Upon being resumed from this activity, you can check the new
758 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800759 */
760 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
761 public static final String ACTION_SET_NEW_PASSWORD
762 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700763
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000764 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000765 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
766 * the parent profile to access intents sent from the managed profile.
767 * That is, when an app in the managed profile calls
768 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
769 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000770 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100771 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000772
773 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000774 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
775 * the managed profile to access intents sent from the parent profile.
776 * That is, when an app in the parent profile calls
777 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
778 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000779 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100780 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700781
Dianne Hackbornd6847842010-01-12 18:14:19 -0800782 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100783 * Broadcast action: notify that a new local system update policy has been set by the device
784 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000785 */
786 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100787 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
788 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000789
Amith Yamasanid49489b2015-04-28 14:00:26 -0700790 /**
791 * Permission policy to prompt user for new permission requests for runtime permissions.
792 * Already granted or denied permissions are not affected by this.
793 */
794 public static final int PERMISSION_POLICY_PROMPT = 0;
795
796 /**
797 * Permission policy to always grant new permission requests for runtime permissions.
798 * Already granted or denied permissions are not affected by this.
799 */
800 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
801
802 /**
803 * Permission policy to always deny new permission requests for runtime permissions.
804 * Already granted or denied permissions are not affected by this.
805 */
806 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
807
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700808 /**
809 * Runtime permission state: The user can manage the permission
810 * through the UI.
811 */
812 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
813
814 /**
815 * Runtime permission state: The permission is granted to the app
816 * and the user cannot manage the permission through the UI.
817 */
818 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
819
820 /**
821 * Runtime permission state: The permission is denied to the app
822 * and the user cannot manage the permission through the UI.
823 */
824 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000825
826 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 * Return true if the given administrator component is currently
828 * active (enabled) in the system.
829 */
Robin Lee25e26452015-06-02 09:56:29 -0700830 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700831 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100832 }
833
834 /**
835 * @see #isAdminActive(ComponentName)
836 * @hide
837 */
Robin Lee25e26452015-06-02 09:56:29 -0700838 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800839 if (mService != null) {
840 try {
Robin Lee25e26452015-06-02 09:56:29 -0700841 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800842 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800843 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800844 }
845 }
846 return false;
847 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800848 /**
849 * Return true if the given administrator component is currently being removed
850 * for the user.
851 * @hide
852 */
Robin Lee25e26452015-06-02 09:56:29 -0700853 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800854 if (mService != null) {
855 try {
Robin Lee25e26452015-06-02 09:56:29 -0700856 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800857 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800858 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800859 }
860 }
861 return false;
862 }
863
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700864
Dianne Hackbornd6847842010-01-12 18:14:19 -0800865 /**
Robin Lee25e26452015-06-02 09:56:29 -0700866 * Return a list of all currently active device administrators' component
867 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800868 * returned.
869 */
870 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700871 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100872 }
873
874 /**
875 * @see #getActiveAdmins()
876 * @hide
877 */
878 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800879 if (mService != null) {
880 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100881 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800882 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800883 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800884 }
885 }
886 return null;
887 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700888
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800889 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700890 * Used by package administration code to determine if a package can be stopped
891 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800892 * @hide
893 */
894 public boolean packageHasActiveAdmins(String packageName) {
895 if (mService != null) {
896 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700897 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800898 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800899 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800900 }
901 }
902 return false;
903 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800905 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800906 * Remove a current administration component. This can only be called
907 * by the application that owns the administration component; if you
908 * try to remove someone else's component, a security exception will be
909 * thrown.
910 */
Robin Lee25e26452015-06-02 09:56:29 -0700911 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800912 if (mService != null) {
913 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700914 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800915 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800916 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800917 }
918 }
919 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700920
Dianne Hackbornd6847842010-01-12 18:14:19 -0800921 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800922 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700923 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800924 * but requires additional policies after an upgrade.
925 *
926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
927 * an active administrator, or an exception will be thrown.
928 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
929 */
Robin Lee25e26452015-06-02 09:56:29 -0700930 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800931 if (mService != null) {
932 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700933 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800934 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800935 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800936 }
937 }
938 return false;
939 }
940
941 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800942 * Constant for {@link #setPasswordQuality}: the policy has no requirements
943 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800944 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800946 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700947
Dianne Hackbornd6847842010-01-12 18:14:19 -0800948 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700949 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
950 * recognition technology. This implies technologies that can recognize the identity of
951 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
952 * Note that quality constants are ordered so that higher values are more restrictive.
953 */
954 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
955
956 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800957 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100958 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800959 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800960 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800961 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700962
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800963 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800964 * Constant for {@link #setPasswordQuality}: the user must have entered a
965 * password containing at least numeric characters. Note that quality
966 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800967 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800968 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700969
Dianne Hackbornd6847842010-01-12 18:14:19 -0800970 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800971 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800972 * password containing at least numeric characters with no repeating (4444)
973 * or ordered (1234, 4321, 2468) sequences. Note that quality
974 * constants are ordered so that higher values are more restrictive.
975 */
976 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
977
978 /**
979 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700980 * password containing at least alphabetic (or other symbol) characters.
981 * Note that quality constants are ordered so that higher values are more
982 * restrictive.
983 */
984 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700986 /**
987 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800988 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700989 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800990 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800991 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700992 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700993
Dianne Hackbornd6847842010-01-12 18:14:19 -0800994 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700995 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700996 * password containing at least a letter, a numerical digit and a special
997 * symbol, by default. With this password quality, passwords can be
998 * restricted to contain various sets of characters, like at least an
999 * uppercase letter, etc. These are specified using various methods,
1000 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1001 * that quality constants are ordered so that higher values are more
1002 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001003 */
1004 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1005
1006 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 * Called by an application that is administering the device to set the
1008 * password restrictions it is imposing. After setting this, the user
1009 * will not be able to enter a new password that is not at least as
1010 * restrictive as what has been set. Note that the current password
1011 * will remain until the user has set a new one, so the change does not
1012 * take place immediately. To prompt the user for a new password, use
1013 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001014 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001015 * <p>Quality constants are ordered so that higher values are more restrictive;
1016 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001017 * the user's preference, and any other considerations) is the one that
1018 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001019 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001020 * <p>The calling device admin must have requested
1021 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1022 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001023 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001024 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001025 * @param quality The new desired quality. One of
1026 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001027 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1028 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1029 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001030 */
Robin Lee25e26452015-06-02 09:56:29 -07001031 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001032 if (mService != null) {
1033 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001034 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001035 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001036 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001037 }
1038 }
1039 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001040
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001042 * Retrieve the current minimum password quality for all admins of this user
1043 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001044 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001045 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001046 */
Robin Lee25e26452015-06-02 09:56:29 -07001047 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001048 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001049 }
1050
1051 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001052 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001053 if (mService != null) {
1054 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001055 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001057 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 }
1059 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001060 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001062
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001064 * Called by an application that is administering the device to set the
1065 * minimum allowed password length. After setting this, the user
1066 * will not be able to enter a new password that is not at least as
1067 * restrictive as what has been set. Note that the current password
1068 * will remain until the user has set a new one, so the change does not
1069 * take place immediately. To prompt the user for a new password, use
1070 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1071 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001072 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1073 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1074 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001075 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001076 * <p>The calling device admin must have requested
1077 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1078 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001079 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001080 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001081 * @param length The new desired minimum password length. A value of 0
1082 * means there is no restriction.
1083 */
Robin Lee25e26452015-06-02 09:56:29 -07001084 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001085 if (mService != null) {
1086 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001087 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001088 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001089 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001090 }
1091 }
1092 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001093
Dianne Hackbornd6847842010-01-12 18:14:19 -08001094 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001095 * Retrieve the current minimum password length for all admins of this
1096 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001097 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001098 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001099 */
Robin Lee25e26452015-06-02 09:56:29 -07001100 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001101 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001102 }
1103
1104 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001105 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 if (mService != null) {
1107 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001108 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001109 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001110 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001111 }
1112 }
1113 return 0;
1114 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001115
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001116 /**
1117 * Called by an application that is administering the device to set the
1118 * minimum number of upper case letters required in the password. After
1119 * setting this, the user will not be able to enter a new password that is
1120 * not at least as restrictive as what has been set. Note that the current
1121 * password will remain until the user has set a new one, so the change does
1122 * not take place immediately. To prompt the user for a new password, use
1123 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1124 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001125 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1126 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001127 * <p>
1128 * The calling device admin must have requested
1129 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1130 * this method; if it has not, a security exception will be thrown.
1131 *
1132 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1133 * with.
1134 * @param length The new desired minimum number of upper case letters
1135 * required in the password. A value of 0 means there is no
1136 * restriction.
1137 */
Robin Lee25e26452015-06-02 09:56:29 -07001138 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001139 if (mService != null) {
1140 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001141 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001142 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001143 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001144 }
1145 }
1146 }
1147
1148 /**
1149 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001150 * password for all admins of this user and its profiles or a particular one.
1151 * This is the same value as set by
1152 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001153 * and only applies when the password quality is
1154 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001155 *
Robin Lee25e26452015-06-02 09:56:29 -07001156 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001157 * aggregate all admins.
1158 * @return The minimum number of upper case letters required in the
1159 * password.
1160 */
Robin Lee25e26452015-06-02 09:56:29 -07001161 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001162 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001163 }
1164
1165 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001166 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001167 if (mService != null) {
1168 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001169 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001170 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001171 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001172 }
1173 }
1174 return 0;
1175 }
1176
1177 /**
1178 * Called by an application that is administering the device to set the
1179 * minimum number of lower case letters required in the password. After
1180 * setting this, the user will not be able to enter a new password that is
1181 * not at least as restrictive as what has been set. Note that the current
1182 * password will remain until the user has set a new one, so the change does
1183 * not take place immediately. To prompt the user for a new password, use
1184 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1185 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001186 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1187 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001188 * <p>
1189 * The calling device admin must have requested
1190 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1191 * this method; if it has not, a security exception will be thrown.
1192 *
1193 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1194 * with.
1195 * @param length The new desired minimum number of lower case letters
1196 * required in the password. A value of 0 means there is no
1197 * restriction.
1198 */
Robin Lee25e26452015-06-02 09:56:29 -07001199 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 if (mService != null) {
1201 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001202 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001203 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001204 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001205 }
1206 }
1207 }
1208
1209 /**
1210 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001211 * password for all admins of this user and its profiles or a particular one.
1212 * This is the same value as set by
1213 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001214 * and only applies when the password quality is
1215 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001216 *
Robin Lee25e26452015-06-02 09:56:29 -07001217 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001218 * aggregate all admins.
1219 * @return The minimum number of lower case letters required in the
1220 * password.
1221 */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001223 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001224 }
1225
1226 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001227 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001228 if (mService != null) {
1229 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001230 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001231 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001232 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001233 }
1234 }
1235 return 0;
1236 }
1237
1238 /**
1239 * Called by an application that is administering the device to set the
1240 * minimum number of letters required in the password. After setting this,
1241 * the user will not be able to enter a new password that is not at least as
1242 * restrictive as what has been set. Note that the current password will
1243 * remain until the user has set a new one, so the change does not take
1244 * place immediately. To prompt the user for a new password, use
1245 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1246 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001247 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1248 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001249 * <p>
1250 * The calling device admin must have requested
1251 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1252 * this method; if it has not, a security exception will be thrown.
1253 *
1254 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1255 * with.
1256 * @param length The new desired minimum number of letters required in the
1257 * password. A value of 0 means there is no restriction.
1258 */
Robin Lee25e26452015-06-02 09:56:29 -07001259 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 if (mService != null) {
1261 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001262 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001263 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001264 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001265 }
1266 }
1267 }
1268
1269 /**
1270 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001271 * admins or a particular one. This is the same value as
1272 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1273 * and only applies when the password quality is
1274 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001275 *
Robin Lee25e26452015-06-02 09:56:29 -07001276 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001277 * aggregate all admins.
1278 * @return The minimum number of letters required in the password.
1279 */
Robin Lee25e26452015-06-02 09:56:29 -07001280 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001281 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001282 }
1283
1284 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001285 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001286 if (mService != null) {
1287 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001288 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001289 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001290 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001291 }
1292 }
1293 return 0;
1294 }
1295
1296 /**
1297 * Called by an application that is administering the device to set the
1298 * minimum number of numerical digits required in the password. After
1299 * setting this, the user will not be able to enter a new password that is
1300 * not at least as restrictive as what has been set. Note that the current
1301 * password will remain until the user has set a new one, so the change does
1302 * not take place immediately. To prompt the user for a new password, use
1303 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1304 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001305 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1306 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001307 * <p>
1308 * The calling device admin must have requested
1309 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1310 * this method; if it has not, a security exception will be thrown.
1311 *
1312 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1313 * with.
1314 * @param length The new desired minimum number of numerical digits required
1315 * in the password. A value of 0 means there is no restriction.
1316 */
Robin Lee25e26452015-06-02 09:56:29 -07001317 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001318 if (mService != null) {
1319 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001320 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001321 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001322 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001323 }
1324 }
1325 }
1326
1327 /**
1328 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001329 * for all admins of this user and its profiles or a particular one.
1330 * This is the same value as set by
1331 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001332 * and only applies when the password quality is
1333 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001334 *
Robin Lee25e26452015-06-02 09:56:29 -07001335 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001336 * aggregate all admins.
1337 * @return The minimum number of numerical digits required in the password.
1338 */
Robin Lee25e26452015-06-02 09:56:29 -07001339 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001340 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001341 }
1342
1343 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001344 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001345 if (mService != null) {
1346 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001347 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001348 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001349 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001350 }
1351 }
1352 return 0;
1353 }
1354
1355 /**
1356 * Called by an application that is administering the device to set the
1357 * minimum number of symbols required in the password. After setting this,
1358 * the user will not be able to enter a new password that is not at least as
1359 * restrictive as what has been set. Note that the current password will
1360 * remain until the user has set a new one, so the change does not take
1361 * place immediately. To prompt the user for a new password, use
1362 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1363 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001364 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1365 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001366 * <p>
1367 * The calling device admin must have requested
1368 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1369 * this method; if it has not, a security exception will be thrown.
1370 *
1371 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1372 * with.
1373 * @param length The new desired minimum number of symbols required in the
1374 * password. A value of 0 means there is no restriction.
1375 */
Robin Lee25e26452015-06-02 09:56:29 -07001376 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001377 if (mService != null) {
1378 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001379 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001380 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001381 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001382 }
1383 }
1384 }
1385
1386 /**
1387 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001388 * admins or a particular one. This is the same value as
1389 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1390 * and only applies when the password quality is
1391 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001392 *
Robin Lee25e26452015-06-02 09:56:29 -07001393 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001394 * aggregate all admins.
1395 * @return The minimum number of symbols required in the password.
1396 */
Robin Lee25e26452015-06-02 09:56:29 -07001397 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001398 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001399 }
1400
1401 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001402 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001403 if (mService != null) {
1404 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001405 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001406 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001407 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001408 }
1409 }
1410 return 0;
1411 }
1412
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001413 /**
1414 * Called by an application that is administering the device to set the
1415 * minimum number of non-letter characters (numerical digits or symbols)
1416 * required in the password. After setting this, the user will not be able
1417 * to enter a new password that is not at least as restrictive as what has
1418 * been set. Note that the current password will remain until the user has
1419 * set a new one, so the change does not take place immediately. To prompt
1420 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1421 * setting this value. This constraint is only imposed if the administrator
1422 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1423 * {@link #setPasswordQuality}. The default value is 0.
1424 * <p>
1425 * The calling device admin must have requested
1426 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1427 * this method; if it has not, a security exception will be thrown.
1428 *
1429 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1430 * with.
1431 * @param length The new desired minimum number of letters required in the
1432 * password. A value of 0 means there is no restriction.
1433 */
Robin Lee25e26452015-06-02 09:56:29 -07001434 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001435 if (mService != null) {
1436 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001437 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001438 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001439 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001440 }
1441 }
1442 }
1443
1444 /**
1445 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001446 * password for all admins of this user and its profiles or a particular one.
1447 * This is the same value as set by
1448 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001449 * and only applies when the password quality is
1450 * {@link #PASSWORD_QUALITY_COMPLEX}.
1451 *
Robin Lee25e26452015-06-02 09:56:29 -07001452 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001453 * aggregate all admins.
1454 * @return The minimum number of letters required in the password.
1455 */
Robin Lee25e26452015-06-02 09:56:29 -07001456 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001457 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001458 }
1459
1460 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001461 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001462 if (mService != null) {
1463 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001464 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001465 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001466 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001467 }
1468 }
1469 return 0;
1470 }
1471
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001472 /**
1473 * Called by an application that is administering the device to set the length
1474 * of the password history. After setting this, the user will not be able to
1475 * enter a new password that is the same as any password in the history. Note
1476 * that the current password will remain until the user has set a new one, so
1477 * the change does not take place immediately. To prompt the user for a new
1478 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1479 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001480 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1481 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1482 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001483 *
1484 * <p>
1485 * The calling device admin must have requested
1486 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1487 * method; if it has not, a security exception will be thrown.
1488 *
1489 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1490 * with.
1491 * @param length The new desired length of password history. A value of 0
1492 * means there is no restriction.
1493 */
Robin Lee25e26452015-06-02 09:56:29 -07001494 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001495 if (mService != null) {
1496 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001497 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001498 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001499 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001500 }
1501 }
1502 }
1503
1504 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001505 * Called by a device admin to set the password expiration timeout. Calling this method
1506 * will restart the countdown for password expiration for the given admin, as will changing
1507 * the device password (for all admins).
1508 *
1509 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1510 * For example, to have the password expire 5 days from now, timeout would be
1511 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1512 *
1513 * <p>To disable password expiration, a value of 0 may be used for timeout.
1514 *
Jim Millera4e28d12010-11-08 16:15:47 -08001515 * <p>The calling device admin must have requested
1516 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1517 * method; if it has not, a security exception will be thrown.
1518 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001519 * <p> Note that setting the password will automatically reset the expiration time for all
1520 * active admins. Active admins do not need to explicitly call this method in that case.
1521 *
Jim Millera4e28d12010-11-08 16:15:47 -08001522 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1523 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1524 * means there is no restriction (unlimited).
1525 */
Robin Lee25e26452015-06-02 09:56:29 -07001526 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001527 if (mService != null) {
1528 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001529 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001530 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001531 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001532 }
1533 }
1534 }
1535
1536 /**
Jim Miller6b857682011-02-16 16:27:41 -08001537 * Get the password expiration timeout for the given admin. The expiration timeout is the
1538 * recurring expiration timeout provided in the call to
1539 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001540 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001541 *
Robin Lee25e26452015-06-02 09:56:29 -07001542 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001543 * @return The timeout for the given admin or the minimum of all timeouts
1544 */
Robin Lee25e26452015-06-02 09:56:29 -07001545 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001546 if (mService != null) {
1547 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001548 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001549 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001550 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001551 }
1552 }
1553 return 0;
1554 }
1555
1556 /**
1557 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001558 * all admins of this user and its profiles if admin is null. If the password is
1559 * expired, this will return the time since the password expired as a negative number.
1560 * If admin is null, then a composite of all expiration timeouts is returned
1561 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001562 *
Robin Lee25e26452015-06-02 09:56:29 -07001563 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001564 * @return The password expiration time, in ms.
1565 */
Robin Lee25e26452015-06-02 09:56:29 -07001566 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001567 if (mService != null) {
1568 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001569 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001570 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001571 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001572 }
1573 }
1574 return 0;
1575 }
1576
1577 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001578 * Retrieve the current password history length for all admins of this
1579 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001580 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001581 * all admins.
1582 * @return The length of the password history
1583 */
Robin Lee25e26452015-06-02 09:56:29 -07001584 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001585 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001586 }
1587
1588 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001589 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001590 if (mService != null) {
1591 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001592 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001593 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001594 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595 }
1596 }
1597 return 0;
1598 }
1599
Dianne Hackbornd6847842010-01-12 18:14:19 -08001600 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001601 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001602 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001603 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001604 * @return Returns the maximum length that the user can enter.
1605 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001606 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001607 // Kind-of arbitrary.
1608 return 16;
1609 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001610
Dianne Hackborn254cb442010-01-27 19:23:59 -08001611 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001612 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001613 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001614 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001615 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001616 * <p>The calling device admin must have requested
1617 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1618 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001619 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001620 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001621 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001622 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 if (mService != null) {
1624 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001625 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001626 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001627 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 }
1629 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001630 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001631 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001632
Dianne Hackbornd6847842010-01-12 18:14:19 -08001633 /**
1634 * Retrieve the number of times the user has failed at entering a
1635 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001636 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001637 * <p>The calling device admin must have requested
1638 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1639 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001640 */
1641 public int getCurrentFailedPasswordAttempts() {
1642 if (mService != null) {
1643 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001644 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001645 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001646 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001647 }
1648 }
1649 return -1;
1650 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001651
1652 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001653 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001654 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001655 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001656 * @hide
1657 */
1658 public boolean getDoNotAskCredentialsOnBoot() {
1659 if (mService != null) {
1660 try {
1661 return mService.getDoNotAskCredentialsOnBoot();
1662 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001663 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001664 }
1665 }
1666 return false;
1667 }
1668
1669 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001670 * Setting this to a value greater than zero enables a built-in policy
1671 * that will perform a device wipe after too many incorrect
1672 * device-unlock passwords have been entered. This built-in policy combines
1673 * watching for failed passwords and wiping the device, and requires
1674 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001675 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001676 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001677 * <p>To implement any other policy (e.g. wiping data for a particular
1678 * application only, erasing or revoking credentials, or reporting the
1679 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001680 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001681 * instead. Do not use this API, because if the maximum count is reached,
1682 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001683 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001685 * @param num The number of failed password attempts at which point the
1686 * device will wipe its data.
1687 */
Robin Lee25e26452015-06-02 09:56:29 -07001688 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001689 if (mService != null) {
1690 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001691 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001692 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001693 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001694 }
1695 }
1696 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001697
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001698 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001699 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001700 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001701 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001702 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001703 * all admins.
1704 */
Robin Lee25e26452015-06-02 09:56:29 -07001705 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001706 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001707 }
1708
1709 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001710 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001711 if (mService != null) {
1712 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001713 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001714 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001715 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001716 }
1717 }
1718 return 0;
1719 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001720
Dianne Hackborn254cb442010-01-27 19:23:59 -08001721 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001722 * Returns the profile with the smallest maximum failed passwords for wipe,
1723 * for the given user. So for primary user, it might return the primary or
1724 * a managed profile. For a secondary user, it would be the same as the
1725 * user passed in.
1726 * @hide Used only by Keyguard
1727 */
1728 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1729 if (mService != null) {
1730 try {
1731 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1732 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001733 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001734 }
1735 }
1736 return UserHandle.USER_NULL;
1737 }
1738
1739 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001740 * Flag for {@link #resetPassword}: don't allow other admins to change
1741 * the password again until the user has entered it.
1742 */
1743 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001744
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001745 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001746 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1747 * If the flag is set, the device can be booted without asking for user password.
1748 * The absence of this flag does not change the current boot requirements. This flag
1749 * can be set by the device owner only. If the app is not the device owner, the flag
1750 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1751 * device to factory defaults.
1752 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001753 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001754
1755 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001756 * Force a new device unlock password (the password needed to access the
1757 * entire device, not for individual accounts) on the user. This takes
1758 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001759 *
1760 * <p>Calling this from a managed profile that shares the password with the owner profile
1761 * will throw a security exception.
1762 *
1763 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1764 * device admins that are not device owner and not profile owner.
1765 * The password can now only be changed if there is currently no password set. Device owner
1766 * and profile owner can still do this.</em>
1767 *
1768 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001769 * current password quality and length constraints as returned by
1770 * {@link #getPasswordQuality(ComponentName)} and
1771 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1772 * these constraints, then it will be rejected and false returned. Note
1773 * that the password may be a stronger quality (containing alphanumeric
1774 * characters when the requested quality is only numeric), in which case
1775 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001776 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001777 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001778 * pattern or password if the current password constraints allow it. <em>Note: This will not
1779 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1780 * device owner and not profile owner. Once set, the password cannot be changed to null or
1781 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001782 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001783 * <p>The calling device admin must have requested
1784 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1785 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001786 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001787 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001788 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001789 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001790 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001791 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001792 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001793 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001794 if (mService != null) {
1795 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001796 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001797 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001798 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001799 }
1800 }
1801 return false;
1802 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001803
Dianne Hackbornd6847842010-01-12 18:14:19 -08001804 /**
1805 * Called by an application that is administering the device to set the
1806 * maximum time for user activity until the device will lock. This limits
1807 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001808 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001809 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001810 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001811 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001812 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001813 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001814 * @param timeMs The new desired maximum time to lock in milliseconds.
1815 * A value of 0 means there is no restriction.
1816 */
Robin Lee25e26452015-06-02 09:56:29 -07001817 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001818 if (mService != null) {
1819 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001820 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001822 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001823 }
1824 }
1825 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001826
Dianne Hackbornd6847842010-01-12 18:14:19 -08001827 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001828 * Retrieve the current maximum time to unlock for all admins of this user
1829 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001830 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001831 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001832 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001833 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001834 */
Robin Lee25e26452015-06-02 09:56:29 -07001835 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001836 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001837 }
1838
1839 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001840 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001841 if (mService != null) {
1842 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001843 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001844 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001845 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001846 }
1847 }
1848 return 0;
1849 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001850
Dianne Hackbornd6847842010-01-12 18:14:19 -08001851 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001852 * Make the device lock immediately, as if the lock screen timeout has
1853 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001854 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001855 * <p>The calling device admin must have requested
1856 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1857 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001858 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001859 public void lockNow() {
1860 if (mService != null) {
1861 try {
1862 mService.lockNow();
1863 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001864 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001865 }
1866 }
1867 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001868
Dianne Hackbornd6847842010-01-12 18:14:19 -08001869 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001870 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001871 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001872 */
1873 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1874
1875 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001876 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1877 * data.
1878 *
Paul Crowley2934b262014-12-02 11:21:13 +00001879 * <p>This flag may only be set by device owner admins; if it is set by
1880 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001881 */
1882 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1883
1884 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001885 * Ask the user data be wiped. Wiping the primary user will cause the
1886 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001887 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001888 * <p>The calling device admin must have requested
1889 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1890 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001891 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001892 * @param flags Bit mask of additional options: currently supported flags
1893 * are {@link #WIPE_EXTERNAL_STORAGE} and
1894 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001895 */
1896 public void wipeData(int flags) {
1897 if (mService != null) {
1898 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001899 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001900 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001901 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001902 }
1903 }
1904 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001905
Dianne Hackbornd6847842010-01-12 18:14:19 -08001906 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001907 * Called by an application that is administering the device to set the
1908 * global proxy and exclusion list.
1909 * <p>
1910 * The calling device admin must have requested
1911 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1912 * this method; if it has not, a security exception will be thrown.
1913 * Only the first device admin can set the proxy. If a second admin attempts
1914 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001915 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001916 * be returned.
1917 * The method can be called repeatedly by the device admin alrady setting the
1918 * proxy to update the proxy and exclusion list.
1919 *
Robin Lee25e26452015-06-02 09:56:29 -07001920 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001921 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1922 * Pass Proxy.NO_PROXY to reset the proxy.
1923 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001924 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1925 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001926 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001927 */
Robin Lee25e26452015-06-02 09:56:29 -07001928 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001929 List<String> exclusionList ) {
1930 if (proxySpec == null) {
1931 throw new NullPointerException();
1932 }
1933 if (mService != null) {
1934 try {
1935 String hostSpec;
1936 String exclSpec;
1937 if (proxySpec.equals(Proxy.NO_PROXY)) {
1938 hostSpec = null;
1939 exclSpec = null;
1940 } else {
1941 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1942 throw new IllegalArgumentException();
1943 }
1944 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1945 String hostName = sa.getHostName();
1946 int port = sa.getPort();
1947 StringBuilder hostBuilder = new StringBuilder();
1948 hostSpec = hostBuilder.append(hostName)
1949 .append(":").append(Integer.toString(port)).toString();
1950 if (exclusionList == null) {
1951 exclSpec = "";
1952 } else {
1953 StringBuilder listBuilder = new StringBuilder();
1954 boolean firstDomain = true;
1955 for (String exclDomain : exclusionList) {
1956 if (!firstDomain) {
1957 listBuilder = listBuilder.append(",");
1958 } else {
1959 firstDomain = false;
1960 }
1961 listBuilder = listBuilder.append(exclDomain.trim());
1962 }
1963 exclSpec = listBuilder.toString();
1964 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001965 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1966 != android.net.Proxy.PROXY_VALID)
1967 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001968 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001969 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001970 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001971 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001972 }
1973 }
1974 return null;
1975 }
1976
1977 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001978 * Set a network-independent global HTTP proxy. This is not normally what you want
1979 * for typical HTTP proxies - they are generally network dependent. However if you're
1980 * doing something unusual like general internal filtering this may be useful. On
1981 * a private network where the proxy is not accessible, you may break HTTP using this.
1982 *
1983 * <p>This method requires the caller to be the device owner.
1984 *
1985 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1986 * @see ProxyInfo
1987 *
1988 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1989 * with.
1990 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1991 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1992 */
Robin Lee25e26452015-06-02 09:56:29 -07001993 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1994 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001995 if (mService != null) {
1996 try {
1997 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1998 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001999 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002000 }
2001 }
2002 }
2003
2004 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002005 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002006 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2007 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002008 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002009 */
2010 public ComponentName getGlobalProxyAdmin() {
2011 if (mService != null) {
2012 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002013 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002014 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002015 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002016 }
2017 }
2018 return null;
2019 }
2020
2021 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002022 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002023 * indicating that encryption is not supported.
2024 */
2025 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2026
2027 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002028 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002029 * indicating that encryption is supported, but is not currently active.
2030 */
2031 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2032
2033 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002034 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002035 * indicating that encryption is not currently active, but is currently
2036 * being activated. This is only reported by devices that support
2037 * encryption of data and only when the storage is currently
2038 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2039 * to become encrypted will never return this value.
2040 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002041 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002042
2043 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002044 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002045 * indicating that encryption is active.
2046 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002047 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002048
2049 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002050 * Result code for {@link #getStorageEncryptionStatus}:
2051 * indicating that encryption is active, but an encryption key has not
2052 * been set by the user.
2053 */
2054 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2055
2056 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002057 * Activity action: begin the process of encrypting data on the device. This activity should
2058 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2059 * After resuming from this activity, use {@link #getStorageEncryption}
2060 * to check encryption status. However, on some devices this activity may never return, as
2061 * it may trigger a reboot and in some cases a complete data wipe of the device.
2062 */
2063 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2064 public static final String ACTION_START_ENCRYPTION
2065 = "android.app.action.START_ENCRYPTION";
2066
2067 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002068 * Widgets are enabled in keyguard
2069 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002070 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002071
2072 /**
Jim Miller50e62182014-04-23 17:25:00 -07002073 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002074 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002075 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2076
2077 /**
2078 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2079 */
2080 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2081
2082 /**
Jim Miller50e62182014-04-23 17:25:00 -07002083 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2084 */
2085 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2086
2087 /**
2088 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2089 */
2090 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2091
2092 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002093 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002094 * (e.g. PIN/Pattern/Password).
2095 */
2096 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2097
2098 /**
Jim Miller06e34502014-07-17 14:46:05 -07002099 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2100 */
2101 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2102
2103 /**
Jim Miller35207742012-11-02 15:33:20 -07002104 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002105 */
2106 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002107
2108 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002109 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002110 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002111 *
2112 * <p>When multiple device administrators attempt to control device
2113 * encryption, the most secure, supported setting will always be
2114 * used. If any device administrator requests device encryption,
2115 * it will be enabled; Conversely, if a device administrator
2116 * attempts to disable device encryption while another
2117 * device administrator has enabled it, the call to disable will
2118 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2119 *
2120 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002121 * written to other storage areas may or may not be encrypted, and this policy does not require
2122 * or control the encryption of any other storage areas.
2123 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2124 * {@code true}, then the directory returned by
2125 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2126 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002127 *
2128 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2129 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2130 * the encryption key may not be fully secured. For maximum security, the administrator should
2131 * also require (and check for) a pattern, PIN, or password.
2132 *
2133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2134 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002135 * @return the new request status (for all active admins) - will be one of
2136 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2137 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2138 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002139 */
Robin Lee25e26452015-06-02 09:56:29 -07002140 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002141 if (mService != null) {
2142 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002143 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002144 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002145 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002146 }
2147 }
2148 return ENCRYPTION_STATUS_UNSUPPORTED;
2149 }
2150
2151 /**
2152 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002153 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002154 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2156 * this will return the requested encryption setting as an aggregate of all active
2157 * administrators.
2158 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002159 */
Robin Lee25e26452015-06-02 09:56:29 -07002160 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002161 if (mService != null) {
2162 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002163 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002164 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002165 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002166 }
2167 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002168 return false;
2169 }
2170
2171 /**
2172 * Called by an application that is administering the device to
2173 * determine the current encryption status of the device.
2174 *
2175 * Depending on the returned status code, the caller may proceed in different
2176 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2177 * storage system does not support encryption. If the
2178 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2179 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002180 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2181 * storage system has enabled encryption but no password is set so further action
2182 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002183 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2184 *
Robin Lee7e678712014-07-24 16:41:31 +01002185 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002186 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002187 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2188 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002189 */
2190 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002191 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002192 }
2193
2194 /** @hide per-user version */
2195 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002196 if (mService != null) {
2197 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002198 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002199 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002200 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002201 }
2202 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002203 return ENCRYPTION_STATUS_UNSUPPORTED;
2204 }
2205
2206 /**
Robin Lee7e678712014-07-24 16:41:31 +01002207 * Installs the given certificate as a user CA.
2208 *
Robin Lee25e26452015-06-02 09:56:29 -07002209 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2210 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002211 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002212 *
2213 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002214 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002215 */
Robin Lee25e26452015-06-02 09:56:29 -07002216 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002217 if (mService != null) {
2218 try {
Robin Lee7e678712014-07-24 16:41:31 +01002219 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002220 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002221 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002222 }
2223 }
2224 return false;
2225 }
2226
2227 /**
Robin Lee7e678712014-07-24 16:41:31 +01002228 * Uninstalls the given certificate from trusted user CAs, if present.
2229 *
Robin Lee25e26452015-06-02 09:56:29 -07002230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2231 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002232 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002233 */
Robin Lee25e26452015-06-02 09:56:29 -07002234 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002235 if (mService != null) {
2236 try {
Robin Lee306fe082014-06-19 14:04:24 +00002237 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002238 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002239 } catch (CertificateException e) {
2240 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002241 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002242 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002243 }
2244 }
2245 }
2246
2247 /**
Robin Lee7e678712014-07-24 16:41:31 +01002248 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2249 * If a user has installed any certificates by other means than device policy these will be
2250 * included too.
2251 *
Robin Lee25e26452015-06-02 09:56:29 -07002252 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2253 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002254 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002255 */
Robin Lee25e26452015-06-02 09:56:29 -07002256 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002257 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002258 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002259 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002260 mService.enforceCanManageCaCerts(admin);
2261 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2262 for (String alias : certStore.userAliases()) {
2263 try {
2264 certs.add(certStore.getCertificate(alias).getEncoded());
2265 } catch (CertificateException ce) {
2266 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2267 }
2268 }
2269 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002270 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002271 }
2272 }
2273 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002274 }
2275
2276 /**
Robin Lee7e678712014-07-24 16:41:31 +01002277 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2278 * means other than device policy will also be removed, except for system CA certificates.
2279 *
Robin Lee25e26452015-06-02 09:56:29 -07002280 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2281 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002282 */
Robin Lee25e26452015-06-02 09:56:29 -07002283 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002284 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002285 try {
2286 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2287 .toArray(new String[0]));
2288 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002289 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002290 }
2291 }
2292 }
2293
2294 /**
2295 * Returns whether this certificate is installed as a trusted CA.
2296 *
Robin Lee25e26452015-06-02 09:56:29 -07002297 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2298 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002299 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002300 */
Robin Lee25e26452015-06-02 09:56:29 -07002301 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002302 if (mService != null) {
2303 try {
2304 mService.enforceCanManageCaCerts(admin);
2305 return getCaCertAlias(certBuffer) != null;
2306 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002307 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002308 } catch (CertificateException ce) {
2309 Log.w(TAG, "Could not parse certificate", ce);
2310 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002311 }
2312 return false;
2313 }
2314
2315 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002316 * Called by a device or profile owner to install a certificate and private key pair. The
2317 * keypair will be visible to all apps within the profile.
2318 *
Robin Lee25e26452015-06-02 09:56:29 -07002319 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2320 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002321 * @param privKey The private key to install.
2322 * @param cert The certificate to install.
2323 * @param alias The private key alias under which to install the certificate. If a certificate
2324 * with that alias already exists, it will be overwritten.
2325 * @return {@code true} if the keys were installed, {@code false} otherwise.
2326 */
Robin Leefbc65642015-08-03 16:21:22 +01002327 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2328 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002329 try {
2330 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002331 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2332 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002333 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002334 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002335 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002336 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2337 Log.w(TAG, "Failed to obtain private key material", e);
2338 } catch (CertificateException | IOException e) {
2339 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002340 }
2341 return false;
2342 }
2343
2344 /**
Robin Leefbc65642015-08-03 16:21:22 +01002345 * Called by a device or profile owner to remove all user credentials installed under a given
2346 * alias.
2347 *
2348 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2349 * {@code null} if calling from a delegated certificate installer.
2350 * @param alias The private key alias under which the certificate is installed.
2351 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2352 */
2353 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2354 try {
2355 return mService.removeKeyPair(admin, alias);
2356 } catch (RemoteException e) {
2357 Log.w(TAG, "Failed talking with device policy service", e);
2358 }
2359 return false;
2360 }
2361
2362 /**
Robin Lee25e26452015-06-02 09:56:29 -07002363 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002364 * doesn't exist.
2365 */
2366 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2367 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2368 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2369 new ByteArrayInputStream(certBuffer));
2370 return new TrustedCertificateStore().getCertificateAlias(cert);
2371 }
2372
2373 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002374 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002375 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002376 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002377 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002378 * <p>
2379 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2380 * it is later cleared by calling this method with a null value or uninstallling the certificate
2381 * installer.
2382 *
Robin Lee25e26452015-06-02 09:56:29 -07002383 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002384 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002385 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002386 */
Robin Lee25e26452015-06-02 09:56:29 -07002387 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2388 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002389 if (mService != null) {
2390 try {
Robin Lee25e26452015-06-02 09:56:29 -07002391 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002392 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002393 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002394 }
2395 }
2396 }
2397
2398 /**
2399 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002400 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002401 *
Robin Lee25e26452015-06-02 09:56:29 -07002402 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2403 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002404 * if none is set.
2405 */
Robin Lee25e26452015-06-02 09:56:29 -07002406 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002407 if (mService != null) {
2408 try {
Robin Lee25e26452015-06-02 09:56:29 -07002409 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002410 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002411 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002412 }
2413 }
2414 return null;
2415 }
2416
2417 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002418 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002419 * on the device, for this user. After setting this, no applications running as this user
2420 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002421 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002422 * <p>If the caller is device owner, then the restriction will be applied to all users.
2423 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002424 * <p>The calling device admin must have requested
2425 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2426 * this method; if it has not, a security exception will be thrown.
2427 *
2428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2429 * @param disabled Whether or not the camera should be disabled.
2430 */
Robin Lee25e26452015-06-02 09:56:29 -07002431 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002432 if (mService != null) {
2433 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002434 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002435 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002436 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002437 }
2438 }
2439 }
2440
2441 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002442 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002443 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002444 * @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 -07002445 * have disabled the camera
2446 */
Robin Lee25e26452015-06-02 09:56:29 -07002447 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002448 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002449 }
2450
2451 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002452 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002453 if (mService != null) {
2454 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002455 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002456 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002457 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002458 }
2459 }
2460 return false;
2461 }
2462
2463 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002464 * Determine whether or not creating a guest user has been disabled for the device
2465 *
2466 * @hide
2467 */
2468 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2469 // Currently guest users can always be created if multi-user is enabled
2470 // TODO introduce a policy for guest user creation
2471 return false;
2472 }
2473
2474 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002475 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2476 * screen capture also prevents the content from being shown on display devices that do not have
2477 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2478 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002479 *
2480 * <p>The calling device admin must be a device or profile owner. If it is not, a
2481 * security exception will be thrown.
2482 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002483 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002484 * blocks assist requests for all activities of the relevant user.
2485 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002487 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002488 */
Robin Lee25e26452015-06-02 09:56:29 -07002489 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002490 if (mService != null) {
2491 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002492 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002493 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002494 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002495 }
2496 }
2497 }
2498
2499 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002500 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002501 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002502 * @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 +01002503 * have disabled screen capture.
2504 */
Robin Lee25e26452015-06-02 09:56:29 -07002505 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002506 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002507 }
2508
2509 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002510 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002511 if (mService != null) {
2512 try {
2513 return mService.getScreenCaptureDisabled(admin, userHandle);
2514 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002515 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002516 }
2517 }
2518 return false;
2519 }
2520
2521 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002522 * Called by a device owner to set whether auto time is required. If auto time is
2523 * required the user cannot set the date and time, but has to use network date and time.
2524 *
2525 * <p>Note: if auto time is required the user can still manually set the time zone.
2526 *
2527 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2528 * be thrown.
2529 *
2530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2531 * @param required Whether auto time is set required or not.
2532 */
Robin Lee25e26452015-06-02 09:56:29 -07002533 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002534 if (mService != null) {
2535 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002536 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002537 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002538 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002539 }
2540 }
2541 }
2542
2543 /**
2544 * @return true if auto time is required.
2545 */
2546 public boolean getAutoTimeRequired() {
2547 if (mService != null) {
2548 try {
2549 return mService.getAutoTimeRequired();
2550 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002551 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002552 }
2553 }
2554 return false;
2555 }
2556
2557 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002558 * Called by an application that is administering the device to disable keyguard customizations,
2559 * such as widgets. After setting this, keyguard features will be disabled according to the
2560 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002561 *
2562 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002563 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002564 * this method; if it has not, a security exception will be thrown.
2565 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002566 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002567 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002568 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002569 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002570 * <ul>
2571 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2572 * these will affect the profile's parent user.
2573 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2574 * generated by applications in the managed profile.
2575 * </ul>
2576 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2577 * can check which features have been disabled by calling
2578 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002579 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002580 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002581 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2582 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002583 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002584 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2585 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002586 */
Robin Lee25e26452015-06-02 09:56:29 -07002587 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002588 if (mService != null) {
2589 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002590 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002591 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002592 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002593 }
2594 }
2595 }
2596
2597 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002598 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002599 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002600 * @param admin The name of the admin component to check, or {@code null} to check whether any admins
Jim Miller48b9b0d2012-09-19 23:16:50 -07002601 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002602 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2603 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002604 */
Robin Lee25e26452015-06-02 09:56:29 -07002605 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002606 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002607 }
2608
2609 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002610 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002611 if (mService != null) {
2612 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002613 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002614 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002615 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002616 }
2617 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002618 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002619 }
2620
2621 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002622 * @hide
2623 */
Robin Lee25e26452015-06-02 09:56:29 -07002624 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2625 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002626 if (mService != null) {
2627 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002628 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002629 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002630 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002631 }
2632 }
2633 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002634
Dianne Hackbornd6847842010-01-12 18:14:19 -08002635 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002636 * @hide
2637 */
Robin Lee25e26452015-06-02 09:56:29 -07002638 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002639 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002640 }
2641
2642 /**
Robin Lee25e26452015-06-02 09:56:29 -07002643 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002644 * @hide
2645 */
Robin Lee25e26452015-06-02 09:56:29 -07002646 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002647 ActivityInfo ai;
2648 try {
2649 ai = mContext.getPackageManager().getReceiverInfo(cn,
2650 PackageManager.GET_META_DATA);
2651 } catch (PackageManager.NameNotFoundException e) {
2652 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2653 return null;
2654 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002655
Dianne Hackbornd6847842010-01-12 18:14:19 -08002656 ResolveInfo ri = new ResolveInfo();
2657 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002658
Dianne Hackbornd6847842010-01-12 18:14:19 -08002659 try {
2660 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002661 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002662 Log.w(TAG, "Unable to parse device policy " + cn, e);
2663 return null;
2664 }
2665 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002666
Dianne Hackbornd6847842010-01-12 18:14:19 -08002667 /**
2668 * @hide
2669 */
Robin Lee25e26452015-06-02 09:56:29 -07002670 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002671 if (mService != null) {
2672 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002673 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002674 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002675 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002676 }
2677 }
2678 }
2679
2680 /**
2681 * @hide
2682 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002683 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002684 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002685 if (mService != null) {
2686 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002687 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002688 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002689 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002690 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002691 }
2692 }
2693 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002694
Dianne Hackbornd6847842010-01-12 18:14:19 -08002695 /**
2696 * @hide
2697 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002698 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002699 if (mService != null) {
2700 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002701 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002702 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002703 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002704 }
2705 }
2706 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002707
Dianne Hackbornd6847842010-01-12 18:14:19 -08002708 /**
2709 * @hide
2710 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002711 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002712 if (mService != null) {
2713 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002714 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002715 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002716 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002717 }
2718 }
2719 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002720
2721 /**
2722 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002723 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002724 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2725 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002726 * @return whether the package was successfully registered as the device owner.
2727 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002728 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002729 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002730 public boolean setDeviceOwner(ComponentName who) {
2731 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002732 }
2733
2734 /**
2735 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002736 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002737 public boolean setDeviceOwner(ComponentName who, int userId) {
2738 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002739 }
2740
2741 /**
2742 * @hide
2743 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002744 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2745 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002746 }
2747
2748 /**
2749 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002750 * Sets the given package as the device owner. The package must already be installed. There
2751 * must not already be a device owner.
2752 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2753 * this method.
2754 * Calling this after the setup phase of the primary user has completed is allowed only if
2755 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002756 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002757 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002758 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002759 * @return whether the package was successfully registered as the device owner.
2760 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002761 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002762 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002763 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002764 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002765 if (mService != null) {
2766 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002767 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002768 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002769 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002770 }
2771 }
2772 return false;
2773 }
2774
2775 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002776 * Used to determine if a particular package has been registered as a Device Owner app.
2777 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002778 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002779 * package is currently registered as the device owner app, pass in the package name from
2780 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002781 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002782 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2783 * the setup process.
2784 * @param packageName the package name of the app, to compare with the registered device owner
2785 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08002786 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002787 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002788 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002789 return isDeviceOwnerAppOnCallingUser(packageName);
2790 }
2791
2792 /**
2793 * @return true if a package is registered as device owner, only when it's running on the
2794 * calling user.
2795 *
2796 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
2797 * @hide
2798 */
2799 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
2800 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
2801 }
2802
2803 /**
2804 * @return true if a package is registered as device owner, even if it's running on a different
2805 * user.
2806 *
2807 * <p>Requires the MANAGE_USERS permission.
2808 *
2809 * @hide
2810 */
2811 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
2812 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
2813 }
2814
2815 /**
2816 * @return device owner component name, only when it's running on the calling user.
2817 *
2818 * @hide
2819 */
2820 public ComponentName getDeviceOwnerComponentOnCallingUser() {
2821 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
2822 }
2823
2824 /**
2825 * @return device owner component name, even if it's running on a different user.
2826 *
2827 * <p>Requires the MANAGE_USERS permission.
2828 *
2829 * @hide
2830 */
2831 public ComponentName getDeviceOwnerComponentOnAnyUser() {
2832 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
2833 }
2834
2835 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002836 if (packageName == null) {
2837 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002838 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08002839 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08002840 if (deviceOwner == null) {
2841 return false;
2842 }
2843 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002844 }
2845
Makoto Onukic8a5a552015-11-19 14:29:12 -08002846 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
2847 if (mService != null) {
2848 try {
2849 return mService.getDeviceOwnerComponent(callingUserOnly);
2850 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002851 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002852 }
2853 }
2854 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002855 }
2856
Jason Monkb0dced82014-06-06 14:36:20 -04002857 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002858 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
2859 * no device owner.
2860 *
2861 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002862 *
2863 * @hide
2864 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002865 public int getDeviceOwnerUserId() {
2866 if (mService != null) {
2867 try {
2868 return mService.getDeviceOwnerUserId();
2869 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002870 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08002871 }
2872 }
2873 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07002874 }
2875
2876 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002877 * Clears the current device owner. The caller must be the device owner.
2878 *
2879 * This function should be used cautiously as once it is called it cannot
2880 * be undone. The device owner can only be set as a part of device setup
2881 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002882 *
2883 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002884 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002885 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002886 if (mService != null) {
2887 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002888 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002889 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002890 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04002891 }
2892 }
2893 }
2894
Makoto Onukia52562c2015-10-01 16:12:31 -07002895 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002896 * Returns the device owner package name, only if it's running on the calling user.
2897 *
2898 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07002899 *
2900 * @hide
2901 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002902 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002903 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08002904 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
2905 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07002906 }
2907
2908 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08002909 * @return true if the device is managed by any device owner.
2910 *
2911 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07002912 *
2913 * @hide
2914 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08002915 public boolean isDeviceManaged() {
2916 return getDeviceOwnerComponentOnAnyUser() != null;
2917 }
2918
2919 /**
2920 * Returns the device owner name. Note this method *will* return the device owner
2921 * name when it's running on a different user.
2922 *
2923 * <p>Requires the MANAGE_USERS permission.
2924 *
2925 * @hide
2926 */
2927 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002928 if (mService != null) {
2929 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002930 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002931 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002932 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002933 }
2934 }
2935 return null;
2936 }
Adam Connors776c5552014-01-09 10:42:56 +00002937
2938 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002939 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002940 * @deprecated Do not use
2941 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002942 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002943 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002944 @SystemApi
2945 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002946 return null;
2947 }
2948
2949 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002950 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002951 * @deprecated Do not use
2952 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002953 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002954 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002955 @SystemApi
2956 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002957 return null;
2958 }
2959
Julia Reynolds20118f12015-02-11 12:34:08 -05002960 /**
Adam Connors776c5552014-01-09 10:42:56 +00002961 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002962 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302963 * Sets the given component as an active admin and registers the package as the profile
2964 * owner for this user. The package must already be installed and there shouldn't be
2965 * an existing profile owner registered for this user. Also, this method must be called
2966 * before the user setup has been completed.
2967 * <p>
2968 * This method can only be called by system apps that hold MANAGE_USERS permission and
2969 * MANAGE_DEVICE_ADMINS permission.
2970 * @param admin The component to register as an active admin and profile owner.
2971 * @param ownerName The user-visible name of the entity that is managing this user.
2972 * @return whether the admin was successfully registered as the profile owner.
2973 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2974 * the user has already been set up.
2975 */
Justin Morey80440cc2014-07-24 09:16:35 -05002976 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002977 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302978 throws IllegalArgumentException {
2979 if (mService != null) {
2980 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002981 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302982 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002983 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302984 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302985 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2986 }
2987 }
2988 return false;
2989 }
2990
2991 /**
2992 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002993 * Clears the active profile owner and removes all user restrictions. The caller must
2994 * be from the same package as the active profile owner for this user, otherwise a
2995 * SecurityException will be thrown.
2996 *
2997 * @param admin The component to remove as the profile owner.
2998 * @return
2999 */
3000 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003001 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003002 if (mService != null) {
3003 try {
3004 mService.clearProfileOwner(admin);
3005 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003006 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003007 }
3008 }
3009 }
3010
3011 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003012 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003013 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003014 */
3015 public boolean hasUserSetupCompleted() {
3016 if (mService != null) {
3017 try {
3018 return mService.hasUserSetupCompleted();
3019 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003020 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003021 }
3022 }
3023 return true;
3024 }
3025
3026 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003027 * @hide
3028 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003029 * already be installed. There must not already be a profile owner for this user.
3030 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3031 * this method.
3032 * Calling this after the setup phase of the specified user has completed is allowed only if:
3033 * - the caller is SYSTEM_UID.
3034 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003035 * @param admin the component name to be registered as profile owner.
3036 * @param ownerName the human readable name of the organisation associated with this DPM.
3037 * @param userHandle the userId to set the profile owner for.
3038 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003039 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3040 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003041 */
Robin Lee25e26452015-06-02 09:56:29 -07003042 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003043 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003044 if (mService != null) {
3045 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003046 if (ownerName == null) {
3047 ownerName = "";
3048 }
3049 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003050 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003052 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3053 }
3054 }
3055 return false;
3056 }
3057
3058 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003059 * Sets the device owner information to be shown on the lock screen.
3060 *
3061 * <p>If the device owner information is {@code null} or empty then the device owner info is
3062 * cleared and the user owner info is shown on the lock screen if it is set.
3063 *
3064 * @param admin The name of the admin component to check.
3065 * @param info Device owner information which will be displayed instead of the user
3066 * owner info.
3067 * @return Whether the device owner information has been set.
3068 */
3069 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3070 if (mService != null) {
3071 try {
3072 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3073 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003074 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003075 }
3076 }
3077 return false;
3078 }
3079
3080 /**
3081 * @return The device owner information. If it is not set returns {@code null}.
3082 */
3083 public String getDeviceOwnerLockScreenInfo() {
3084 if (mService != null) {
3085 try {
3086 return mService.getDeviceOwnerLockScreenInfo();
3087 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003088 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003089 }
3090 }
3091 return null;
3092 }
3093
3094 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003095 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3096 * be used. Only the profile owner can call this.
3097 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003098 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003099 *
3100 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3101 */
Robin Lee25e26452015-06-02 09:56:29 -07003102 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003103 if (mService != null) {
3104 try {
3105 mService.setProfileEnabled(admin);
3106 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003107 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003108 }
3109 }
3110 }
3111
3112 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003113 * Sets the name of the profile. In the device owner case it sets the name of the user
3114 * 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 +01003115 * never called by the profile or device owner, the name will be set to default values.
3116 *
3117 * @see #isProfileOwnerApp
3118 * @see #isDeviceOwnerApp
3119 *
Robin Lee25e26452015-06-02 09:56:29 -07003120 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003121 * @param profileName The name of the profile.
3122 */
Robin Lee25e26452015-06-02 09:56:29 -07003123 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003124 if (mService != null) {
3125 try {
Robin Lee25e26452015-06-02 09:56:29 -07003126 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003127 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003128 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003129 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003130 }
3131 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003132
3133 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003134 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003135 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003136 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003137 *
3138 * @param packageName The package name of the app to compare with the registered profile owner.
3139 * @return Whether or not the package is registered as the profile owner.
3140 */
3141 public boolean isProfileOwnerApp(String packageName) {
3142 if (mService != null) {
3143 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003144 ComponentName profileOwner = mService.getProfileOwner(
3145 Process.myUserHandle().getIdentifier());
3146 return profileOwner != null
3147 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003148 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003149 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003150 }
3151 }
3152 return false;
3153 }
3154
3155 /**
3156 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003157 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003158 * owner has been set for that user.
3159 * @throws IllegalArgumentException if the userId is invalid.
3160 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003161 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003162 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003163 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3164 }
3165
3166 /**
3167 * @see #getProfileOwner()
3168 * @hide
3169 */
3170 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003171 if (mService != null) {
3172 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003173 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003174 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003175 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003176 throw new IllegalArgumentException(
3177 "Requested profile owner for invalid userId", re);
3178 }
3179 }
3180 return null;
3181 }
3182
3183 /**
3184 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003185 * @return the human readable name of the organisation associated with this DPM or {@code null}
3186 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003187 * @throws IllegalArgumentException if the userId is invalid.
3188 */
3189 public String getProfileOwnerName() throws IllegalArgumentException {
3190 if (mService != null) {
3191 try {
3192 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3193 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003194 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003195 throw new IllegalArgumentException(
3196 "Requested profile owner for invalid userId", re);
3197 }
3198 }
3199 return null;
3200 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003201
3202 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003203 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003204 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003205 * @return the human readable name of the organisation associated with this profile owner or
3206 * null if one is not set.
3207 * @throws IllegalArgumentException if the userId is invalid.
3208 */
3209 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003210 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003211 if (mService != null) {
3212 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003213 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003214 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003215 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003216 throw new IllegalArgumentException(
3217 "Requested profile owner for invalid userId", re);
3218 }
3219 }
3220 return null;
3221 }
3222
3223 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003224 * Called by a profile owner or device owner to add a default intent handler activity for
3225 * intents that match a certain intent filter. This activity will remain the default intent
3226 * handler even if the set of potential event handlers for the intent filter changes and if
3227 * the intent preferences are reset.
3228 *
3229 * <p>The default disambiguation mechanism takes over if the activity is not installed
3230 * (anymore). When the activity is (re)installed, it is automatically reset as default
3231 * intent handler for the filter.
3232 *
3233 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3234 * security exception will be thrown.
3235 *
3236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3237 * @param filter The IntentFilter for which a default handler is added.
3238 * @param activity The Activity that is added as default intent handler.
3239 */
Robin Lee25e26452015-06-02 09:56:29 -07003240 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3241 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003242 if (mService != null) {
3243 try {
3244 mService.addPersistentPreferredActivity(admin, filter, activity);
3245 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003246 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003247 }
3248 }
3249 }
3250
3251 /**
3252 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003253 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003254 *
3255 * <p>The calling device admin must be a profile owner. If it is not, a security
3256 * exception will be thrown.
3257 *
3258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3259 * @param packageName The name of the package for which preferences are removed.
3260 */
Robin Lee25e26452015-06-02 09:56:29 -07003261 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003262 String packageName) {
3263 if (mService != null) {
3264 try {
3265 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3266 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003267 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003268 }
3269 }
3270 }
Robin Lee66e5d962014-04-09 16:44:21 +01003271
3272 /**
3273 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003274 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003275 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003276 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3277 * <ul>
3278 * <li>{@code boolean}
3279 * <li>{@code int}
3280 * <li>{@code String} or {@code String[]}
3281 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3282 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003283 *
3284 * <p>The application restrictions are only made visible to the target application and the
3285 * profile or device owner.
3286 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003287 * <p>If the restrictions are not available yet, but may be applied in the near future,
3288 * the admin can notify the target application of that by adding
3289 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3290 *
Robin Lee66e5d962014-04-09 16:44:21 +01003291 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3292 * exception will be thrown.
3293 *
3294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3295 * @param packageName The name of the package to update restricted settings for.
3296 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3297 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003298 *
3299 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003300 */
Robin Lee25e26452015-06-02 09:56:29 -07003301 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003302 Bundle settings) {
3303 if (mService != null) {
3304 try {
3305 mService.setApplicationRestrictions(admin, packageName, settings);
3306 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003307 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003308 }
3309 }
3310 }
3311
3312 /**
Jim Millere303bf42014-08-26 17:12:29 -07003313 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3314 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3315 * trust agents but those enabled by this function call. If flag
3316 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003317 *
3318 * <p>The calling device admin must have requested
3319 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003320 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003321 *
3322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003323 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003324 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003325 * will be strictly disabled according to the state of the
3326 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3327 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3328 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3329 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003330 */
Robin Lee25e26452015-06-02 09:56:29 -07003331 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3332 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003333 if (mService != null) {
3334 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003335 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003336 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003337 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003338 }
3339 }
3340 }
3341
3342 /**
Jim Millere303bf42014-08-26 17:12:29 -07003343 * Gets configuration for the given trust agent based on aggregating all calls to
3344 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3345 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003346 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3348 * this function returns a list of configurations for all admins that declare
3349 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3350 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3351 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3352 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003353 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003354 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003355 */
Robin Lee25e26452015-06-02 09:56:29 -07003356 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3357 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003358 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003359 }
3360
3361 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003362 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3363 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003364 if (mService != null) {
3365 try {
Jim Millere303bf42014-08-26 17:12:29 -07003366 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003367 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003368 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003369 }
3370 }
Jim Millere303bf42014-08-26 17:12:29 -07003371 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003372 }
3373
3374 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003375 * Called by a profile owner of a managed profile to set whether caller-Id information from
3376 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003377 *
3378 * <p>The calling device admin must be a profile owner. If it is not, a
3379 * security exception will be thrown.
3380 *
Robin Lee25e26452015-06-02 09:56:29 -07003381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003382 * @param disabled If true caller-Id information in the managed profile is not displayed.
3383 */
Robin Lee25e26452015-06-02 09:56:29 -07003384 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003385 if (mService != null) {
3386 try {
Robin Lee25e26452015-06-02 09:56:29 -07003387 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003388 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003389 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003390 }
3391 }
3392 }
3393
3394 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003395 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3396 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003397 *
3398 * <p>The calling device admin must be a profile owner. If it is not, a
3399 * security exception will be thrown.
3400 *
Robin Lee25e26452015-06-02 09:56:29 -07003401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003402 */
Robin Lee25e26452015-06-02 09:56:29 -07003403 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003404 if (mService != null) {
3405 try {
Robin Lee25e26452015-06-02 09:56:29 -07003406 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003407 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003408 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003409 }
3410 }
3411 return false;
3412 }
3413
3414 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003415 * Determine whether or not caller-Id information has been disabled.
3416 *
3417 * @param userHandle The user for whom to check the caller-id permission
3418 * @hide
3419 */
3420 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3421 if (mService != null) {
3422 try {
3423 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3424 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003425 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003426 }
3427 }
3428 return false;
3429 }
3430
3431 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003432 * Start Quick Contact on the managed profile for the user, if the policy allows.
Makoto Onuki1040da12015-03-19 11:24:00 -07003433 * @hide
3434 */
3435 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003436 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003437 if (mService != null) {
3438 try {
3439 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003440 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003441 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003442 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003443 }
3444 }
3445 }
3446
3447 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003448 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003449 * @hide
3450 */
3451 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3452 Intent originalIntent) {
3453 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3454 originalIntent);
3455 }
3456
3457 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003458 * Called by a profile owner of a managed profile to set whether bluetooth
3459 * devices can access enterprise contacts.
3460 * <p>
3461 * The calling device admin must be a profile owner. If it is not, a
3462 * security exception will be thrown.
3463 * <p>
3464 * This API works on managed profile only.
3465 *
Robin Lee25e26452015-06-02 09:56:29 -07003466 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003467 * with.
3468 * @param disabled If true, bluetooth devices cannot access enterprise
3469 * contacts.
3470 */
Robin Lee25e26452015-06-02 09:56:29 -07003471 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003472 if (mService != null) {
3473 try {
Robin Lee25e26452015-06-02 09:56:29 -07003474 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003475 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003476 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003477 }
3478 }
3479 }
3480
3481 /**
3482 * Called by a profile owner of a managed profile to determine whether or
3483 * not Bluetooth devices cannot access enterprise contacts.
3484 * <p>
3485 * The calling device admin must be a profile owner. If it is not, a
3486 * security exception will be thrown.
3487 * <p>
3488 * This API works on managed profile only.
3489 *
Robin Lee25e26452015-06-02 09:56:29 -07003490 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003491 * with.
3492 */
Robin Lee25e26452015-06-02 09:56:29 -07003493 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003494 if (mService != null) {
3495 try {
Robin Lee25e26452015-06-02 09:56:29 -07003496 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003497 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003498 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003499 }
3500 }
3501 return true;
3502 }
3503
3504 /**
3505 * Determine whether or not Bluetooth devices cannot access contacts.
3506 * <p>
3507 * This API works on managed profile UserHandle only.
3508 *
3509 * @param userHandle The user for whom to check the caller-id permission
3510 * @hide
3511 */
3512 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3513 if (mService != null) {
3514 try {
3515 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3516 .getIdentifier());
3517 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003518 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003519 }
3520 }
3521 return true;
3522 }
3523
3524 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003525 * Called by the profile owner of a managed profile so that some intents sent in the managed
3526 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003527 * Only activity intents are supported.
3528 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003530 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3531 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003532 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3533 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003534 */
Robin Lee25e26452015-06-02 09:56:29 -07003535 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003536 if (mService != null) {
3537 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003538 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003539 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003540 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003541 }
3542 }
3543 }
3544
3545 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003546 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3547 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003548 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003549 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3550 */
Robin Lee25e26452015-06-02 09:56:29 -07003551 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003552 if (mService != null) {
3553 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003554 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003555 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003556 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003557 }
3558 }
3559 }
3560
3561 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003562 * Called by a profile or device owner to set the permitted accessibility services. When
3563 * set by a device owner or profile owner the restriction applies to all profiles of the
3564 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003565 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003566 * By default the user can use any accessiblity service. When zero or more packages have
3567 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003568 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003569 *
3570 * <p> Calling with a null value for the list disables the restriction so that all services
3571 * can be used, calling with an empty list only allows the builtin system's services.
3572 *
3573 * <p> System accesibility services are always available to the user the list can't modify
3574 * this.
3575 *
3576 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3577 * @param packageNames List of accessibility service package names.
3578 *
3579 * @return true if setting the restriction succeeded. It fail if there is
3580 * one or more non-system accessibility services enabled, that are not in the list.
3581 */
Robin Lee25e26452015-06-02 09:56:29 -07003582 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003583 List<String> packageNames) {
3584 if (mService != null) {
3585 try {
3586 return mService.setPermittedAccessibilityServices(admin, packageNames);
3587 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003588 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003589 }
3590 }
3591 return false;
3592 }
3593
3594 /**
3595 * Returns the list of permitted accessibility services set by this device or profile owner.
3596 *
3597 * <p>An empty list means no accessibility services except system services are allowed.
3598 * Null means all accessibility services are allowed.
3599 *
3600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3601 * @return List of accessiblity service package names.
3602 */
Robin Lee25e26452015-06-02 09:56:29 -07003603 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003604 if (mService != null) {
3605 try {
3606 return mService.getPermittedAccessibilityServices(admin);
3607 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003608 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003609 }
3610 }
3611 return null;
3612 }
3613
3614 /**
3615 * Returns the list of accessibility services permitted by the device or profiles
3616 * owners of this user.
3617 *
3618 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3619 * it will contain the intersection of the permitted lists for any device or profile
3620 * owners that apply to this user. It will also include any system accessibility services.
3621 *
3622 * @param userId which user to check for.
3623 * @return List of accessiblity service package names.
3624 * @hide
3625 */
3626 @SystemApi
3627 public List<String> getPermittedAccessibilityServices(int userId) {
3628 if (mService != null) {
3629 try {
3630 return mService.getPermittedAccessibilityServicesForUser(userId);
3631 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003632 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003633 }
3634 }
3635 return null;
3636 }
3637
3638 /**
3639 * Called by a profile or device owner to set the permitted input methods services. When
3640 * set by a device owner or profile owner the restriction applies to all profiles of the
3641 * user the device owner or profile owner is an admin for.
3642 *
3643 * By default the user can use any input method. When zero or more packages have
3644 * been added, input method that are not in the list and not part of the system
3645 * can not be enabled by the user.
3646 *
3647 * This method will fail if it is called for a admin that is not for the foreground user
3648 * or a profile of the foreground user.
3649 *
3650 * <p> Calling with a null value for the list disables the restriction so that all input methods
3651 * can be used, calling with an empty list disables all but the system's own input methods.
3652 *
3653 * <p> System input methods are always available to the user this method can't modify this.
3654 *
3655 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3656 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003657 * @return true if setting the restriction succeeded. It will fail if there are
3658 * one or more non-system input methods currently enabled that are not in
3659 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003660 */
Robin Lee25e26452015-06-02 09:56:29 -07003661 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003662 if (mService != null) {
3663 try {
3664 return mService.setPermittedInputMethods(admin, packageNames);
3665 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003666 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003667 }
3668 }
3669 return false;
3670 }
3671
3672
3673 /**
3674 * Returns the list of permitted input methods set by this device or profile owner.
3675 *
3676 * <p>An empty list means no input methods except system input methods are allowed.
3677 * Null means all input methods are allowed.
3678 *
3679 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3680 * @return List of input method package names.
3681 */
Robin Lee25e26452015-06-02 09:56:29 -07003682 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003683 if (mService != null) {
3684 try {
3685 return mService.getPermittedInputMethods(admin);
3686 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003687 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003688 }
3689 }
3690 return null;
3691 }
3692
3693 /**
3694 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08003695 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003696 *
3697 * <p>Null means all input methods are allowed, if a non-null list is returned
3698 * it will contain the intersection of the permitted lists for any device or profile
3699 * owners that apply to this user. It will also include any system input methods.
3700 *
3701 * @return List of input method package names.
3702 * @hide
3703 */
3704 @SystemApi
3705 public List<String> getPermittedInputMethodsForCurrentUser() {
3706 if (mService != null) {
3707 try {
3708 return mService.getPermittedInputMethodsForCurrentUser();
3709 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003710 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003711 }
3712 }
3713 return null;
3714 }
3715
3716 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003717 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
3718 * currently installed it.
3719 *
3720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3721 *
3722 * @return List of package names to keep cached.
3723 * @hide
3724 */
3725 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
3726 if (mService != null) {
3727 try {
3728 return mService.getKeepUninstalledPackages(admin);
3729 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003730 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003731 }
3732 }
3733 return null;
3734 }
3735
3736 /**
3737 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
3738 * currently installed it.
3739 *
3740 * <p>Please note that setting this policy does not imply that specified apps will be
3741 * automatically pre-cached.</p>
3742 *
3743 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3744 * @param packageNames List of package names to keep cached.
3745 * @hide
3746 */
3747 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
3748 @NonNull List<String> packageNames) {
3749 if (mService != null) {
3750 try {
3751 mService.setKeepUninstalledPackages(admin, packageNames);
3752 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003753 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003754 }
3755 }
3756 }
3757
3758 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003759 * Called by a device owner to create a user with the specified name. The UserHandle returned
3760 * by this method should not be persisted as user handles are recycled as users are removed and
3761 * created. If you need to persist an identifier for this user, use
3762 * {@link UserManager#getSerialNumberForUser}.
3763 *
3764 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3765 * @param name the user's name
3766 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003767 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3768 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003769 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003770 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003771 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003772 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003773 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003774 try {
3775 return mService.createUser(admin, name);
3776 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003777 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04003778 }
3779 return null;
3780 }
3781
3782 /**
Jason Monk03978a42014-06-10 15:05:30 -04003783 * Called by a device owner to create a user with the specified name. The UserHandle returned
3784 * by this method should not be persisted as user handles are recycled as users are removed and
3785 * created. If you need to persist an identifier for this user, use
3786 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3787 * immediately.
3788 *
3789 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3790 * as registered as an active admin on the new user. The profile owner package will be
3791 * installed on the new user if it already is installed on the device.
3792 *
3793 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3794 * profileOwnerComponent when onEnable is called.
3795 *
3796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3797 * @param name the user's name
3798 * @param ownerName the human readable name of the organisation associated with this DPM.
3799 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3800 * the user.
3801 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3802 * on the new user.
3803 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003804 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3805 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003806 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003807 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003808 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003809 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003810 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3811 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003812 try {
3813 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3814 adminExtras);
3815 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003816 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04003817 }
3818 return null;
3819 }
3820
3821 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003822 * Called by a device owner to remove a user and all associated data. The primary user can
3823 * not be removed.
3824 *
3825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3826 * @param userHandle the user to remove.
3827 * @return {@code true} if the user was removed, {@code false} otherwise.
3828 */
Robin Lee25e26452015-06-02 09:56:29 -07003829 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003830 try {
3831 return mService.removeUser(admin, userHandle);
3832 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003833 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04003834 return false;
3835 }
3836 }
3837
3838 /**
Jason Monk582d9112014-07-09 19:57:08 -04003839 * Called by a device owner to switch the specified user to the foreground.
3840 *
3841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3842 * @param userHandle the user to switch to; null will switch to primary.
3843 * @return {@code true} if the switch was successful, {@code false} otherwise.
3844 *
3845 * @see Intent#ACTION_USER_FOREGROUND
3846 */
Robin Lee25e26452015-06-02 09:56:29 -07003847 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003848 try {
3849 return mService.switchUser(admin, userHandle);
3850 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003851 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04003852 return false;
3853 }
3854 }
3855
3856 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003857 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003858 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003859 *
3860 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3861 * exception will be thrown.
3862 *
3863 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3864 * @param packageName The name of the package to fetch restricted settings of.
3865 * @return {@link Bundle} of settings corresponding to what was set last time
3866 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3867 * if no restrictions have been set.
3868 */
Robin Lee25e26452015-06-02 09:56:29 -07003869 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003870 if (mService != null) {
3871 try {
3872 return mService.getApplicationRestrictions(admin, packageName);
3873 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003874 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003875 }
3876 }
3877 return null;
3878 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003879
3880 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003881 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003882 * <p>
3883 * The calling device admin must be a profile or device owner; if it is not,
3884 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003885 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003886 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3887 * with.
3888 * @param key The key of the restriction. See the constants in
3889 * {@link android.os.UserManager} for the list of keys.
3890 */
Robin Lee25e26452015-06-02 09:56:29 -07003891 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003892 if (mService != null) {
3893 try {
3894 mService.setUserRestriction(admin, key, true);
3895 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003896 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07003897 }
3898 }
3899 }
3900
3901 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003902 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003903 * <p>
3904 * The calling device admin must be a profile or device owner; if it is not,
3905 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003906 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003907 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3908 * with.
3909 * @param key The key of the restriction. See the constants in
3910 * {@link android.os.UserManager} for the list of keys.
3911 */
Robin Lee25e26452015-06-02 09:56:29 -07003912 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003913 if (mService != null) {
3914 try {
3915 mService.setUserRestriction(admin, key, false);
3916 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003917 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07003918 }
3919 }
3920 }
Adam Connors010cfd42014-04-16 12:48:13 +01003921
3922 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003923 * Called by a profile or device owner to get user restrictions set with
3924 * {@link #addUserRestriction(ComponentName, String)}.
3925 * <p>
3926 * The target user may have more restrictions set by the system or other device owner / profile
3927 * owner. To get all the user restrictions currently set, use
3928 * {@link UserManager#getUserRestrictions()}.
3929 *
3930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003931 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003932 */
3933 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003934 return getUserRestrictions(admin, myUserId());
3935 }
3936
3937 /** @hide per-user version */
3938 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003939 Bundle ret = null;
3940 if (mService != null) {
3941 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003942 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003943 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003944 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003945 }
3946 }
3947 return ret == null ? new Bundle() : ret;
3948 }
3949
3950 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003951 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003952 * is unavailable for use, but the data and actual package file remain.
3953 *
3954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003955 * @param packageName The name of the package to hide or unhide.
3956 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3957 * unhidden.
3958 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003959 */
Robin Lee25e26452015-06-02 09:56:29 -07003960 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003961 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003962 if (mService != null) {
3963 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003964 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003965 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003966 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04003967 }
3968 }
3969 return false;
3970 }
3971
3972 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003973 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003974 *
3975 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003976 * @param packageName The name of the package to retrieve the hidden status of.
3977 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003978 */
Robin Lee25e26452015-06-02 09:56:29 -07003979 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003980 if (mService != null) {
3981 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003982 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003983 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003984 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04003985 }
3986 }
3987 return false;
3988 }
3989
3990 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003991 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003992 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003993 *
3994 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08003995 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00003996 */
Robin Lee25e26452015-06-02 09:56:29 -07003997 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003998 if (mService != null) {
3999 try {
4000 mService.enableSystemApp(admin, packageName);
4001 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004002 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004003 }
4004 }
4005 }
4006
4007 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004008 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004009 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004010 *
4011 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4012 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004013 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004014 * @return int The number of activities that matched the intent and were installed.
4015 */
Robin Lee25e26452015-06-02 09:56:29 -07004016 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004017 if (mService != null) {
4018 try {
4019 return mService.enableSystemAppWithIntent(admin, intent);
4020 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004021 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004022 }
4023 }
4024 return 0;
4025 }
4026
4027 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004028 * Called by a device owner or profile owner to disable account management for a specific type
4029 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004030 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004031 * <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 +01004032 * security exception will be thrown.
4033 *
4034 * <p>When account management is disabled for an account type, adding or removing an account
4035 * of that type will not be possible.
4036 *
4037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4038 * @param accountType For which account management is disabled or enabled.
4039 * @param disabled The boolean indicating that account management will be disabled (true) or
4040 * enabled (false).
4041 */
Robin Lee25e26452015-06-02 09:56:29 -07004042 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004043 boolean disabled) {
4044 if (mService != null) {
4045 try {
4046 mService.setAccountManagementDisabled(admin, accountType, disabled);
4047 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004048 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004049 }
4050 }
4051 }
4052
4053 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004054 * Gets the array of accounts for which account management is disabled by the profile owner.
4055 *
4056 * <p> Account management can be disabled/enabled by calling
4057 * {@link #setAccountManagementDisabled}.
4058 *
4059 * @return a list of account types for which account management has been disabled.
4060 *
4061 * @see #setAccountManagementDisabled
4062 */
4063 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004064 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004065 }
4066
4067 /**
4068 * @see #getAccountTypesWithManagementDisabled()
4069 * @hide
4070 */
4071 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004072 if (mService != null) {
4073 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004074 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004075 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004076 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004077 }
4078 }
4079
4080 return null;
4081 }
justinzhang511e0d82014-03-24 16:09:24 -04004082
4083 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004084 * Sets which packages may enter lock task mode.
4085 *
4086 * <p>Any packages that shares uid with an allowed package will also be allowed
4087 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004088 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004089 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004090 * package list results in locked tasks belonging to those packages to be finished.
4091 *
Jason Monkc5185f22014-06-24 11:12:42 -04004092 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004093 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004095 *
4096 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004097 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4098 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004099 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004100 */
Robin Lee25e26452015-06-02 09:56:29 -07004101 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004102 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004103 if (mService != null) {
4104 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004105 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004106 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004107 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004108 }
4109 }
4110 }
4111
4112 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004113 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004114 *
4115 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004116 * @hide
4117 */
Robin Lee25e26452015-06-02 09:56:29 -07004118 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004119 if (mService != null) {
4120 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004121 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004122 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004123 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004124 }
4125 }
4126 return null;
4127 }
4128
4129 /**
4130 * This function lets the caller know whether the given component is allowed to start the
4131 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004132 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004133 */
Jason Monkd7b86212014-06-16 13:15:38 -04004134 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004135 if (mService != null) {
4136 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004137 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004138 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004139 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004140 }
4141 }
4142 return false;
4143 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004144
4145 /**
4146 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4147 * 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 -04004148 * <p>The settings that can be updated with this method are:
4149 * <ul>
4150 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4151 * <li>{@link Settings.Global#AUTO_TIME}</li>
4152 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004153 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004154 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004155 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004156 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004157 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004158 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004159 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004160 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004161 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004162 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004163 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004164 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004165 * <ul>
4166 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4167 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4168 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4169 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4170 * <li>{@link Settings.Global#MODE_RINGER}.
4171 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4172 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4173 * <li>{@link Settings.Global#WIFI_ON}.
4174 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4175 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004176 *
4177 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4178 * @param setting The name of the setting to update.
4179 * @param value The value to update the setting to.
4180 */
Robin Lee25e26452015-06-02 09:56:29 -07004181 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004182 if (mService != null) {
4183 try {
4184 mService.setGlobalSetting(admin, setting, value);
4185 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004186 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004187 }
4188 }
4189 }
4190
4191 /**
4192 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4193 * that the value of the setting is in the correct form for the setting type should be performed
4194 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004195 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004196 * <ul>
4197 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004198 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004199 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4200 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004201 * <p>A device owner can additionally update the following settings:
4202 * <ul>
4203 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4204 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4206 * @param setting The name of the setting to update.
4207 * @param value The value to update the setting to.
4208 */
Robin Lee25e26452015-06-02 09:56:29 -07004209 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004210 if (mService != null) {
4211 try {
4212 mService.setSecureSetting(admin, setting, value);
4213 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004214 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004215 }
4216 }
4217 }
4218
Amith Yamasanif20d6402014-05-24 15:34:37 -07004219 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004220 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004221 * making permission requests of a local or remote administrator of the user.
4222 * <p/>
4223 * Only a profile owner can designate the restrictions provider.
4224 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004225 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004226 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004227 * it removes the restrictions provider previously assigned.
4228 */
Robin Lee25e26452015-06-02 09:56:29 -07004229 public void setRestrictionsProvider(@NonNull ComponentName admin,
4230 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004231 if (mService != null) {
4232 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004233 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004234 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004235 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004236 }
4237 }
4238 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004239
4240 /**
4241 * Called by profile or device owners to set the master volume mute on or off.
4242 *
4243 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4244 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4245 */
Robin Lee25e26452015-06-02 09:56:29 -07004246 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004247 if (mService != null) {
4248 try {
4249 mService.setMasterVolumeMuted(admin, on);
4250 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004251 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004252 }
4253 }
4254 }
4255
4256 /**
4257 * Called by profile or device owners to check whether the master volume mute is on or off.
4258 *
4259 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4260 * @return {@code true} if master volume is muted, {@code false} if it's not.
4261 */
Robin Lee25e26452015-06-02 09:56:29 -07004262 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004263 if (mService != null) {
4264 try {
4265 return mService.isMasterVolumeMuted(admin);
4266 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004267 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004268 }
4269 }
4270 return false;
4271 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004272
4273 /**
4274 * Called by profile or device owners to change whether a user can uninstall
4275 * a package.
4276 *
4277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4278 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004279 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004280 */
Robin Lee25e26452015-06-02 09:56:29 -07004281 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004282 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004283 if (mService != null) {
4284 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004285 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004286 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004287 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004288 }
4289 }
4290 }
4291
4292 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004293 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004294 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004295 * <p>
4296 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004297 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004298 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004299 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004300 *
Robin Lee25e26452015-06-02 09:56:29 -07004301 * @param admin The name of the admin component whose blocking policy will be checked, or
4302 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004303 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004304 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004305 */
Robin Lee25e26452015-06-02 09:56:29 -07004306 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004307 if (mService != null) {
4308 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004309 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004310 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004312 }
4313 }
4314 return false;
4315 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004316
4317 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004318 * Called by the profile owner of a managed profile to enable widget providers from a
4319 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004320 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004321 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004322 * a package may have zero or more provider components, where each component
4323 * provides a different widget type.
4324 * <p>
4325 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004326 *
4327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4328 * @param packageName The package from which widget providers are white-listed.
4329 * @return Whether the package was added.
4330 *
4331 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4332 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4333 */
Robin Lee25e26452015-06-02 09:56:29 -07004334 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004335 if (mService != null) {
4336 try {
4337 return mService.addCrossProfileWidgetProvider(admin, packageName);
4338 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004340 }
4341 }
4342 return false;
4343 }
4344
4345 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004346 * Called by the profile owner of a managed profile to disable widget providers from a given
4347 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004348 * package should have been added via {@link #addCrossProfileWidgetProvider(
4349 * android.content.ComponentName, String)}.
4350 * <p>
4351 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004352 *
4353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4354 * @param packageName The package from which widget providers are no longer
4355 * white-listed.
4356 * @return Whether the package was removed.
4357 *
4358 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4359 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4360 */
Robin Lee25e26452015-06-02 09:56:29 -07004361 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004362 if (mService != null) {
4363 try {
4364 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4365 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004366 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004367 }
4368 }
4369 return false;
4370 }
4371
4372 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004373 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004374 * available in the parent profile.
4375 *
4376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4377 * @return The white-listed package list.
4378 *
4379 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4380 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4381 */
Robin Lee25e26452015-06-02 09:56:29 -07004382 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004383 if (mService != null) {
4384 try {
4385 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4386 if (providers != null) {
4387 return providers;
4388 }
4389 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004390 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004391 }
4392 }
4393 return Collections.emptyList();
4394 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004395
4396 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004397 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004398 *
4399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4400 * @param icon the bitmap to set as the photo.
4401 */
Robin Lee25e26452015-06-02 09:56:29 -07004402 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004403 try {
4404 mService.setUserIcon(admin, icon);
4405 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004406 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004407 }
4408 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004409
4410 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004411 * Called by device owners to set a local system update policy. When a new policy is set,
4412 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004413 *
Robin Lee25e26452015-06-02 09:56:29 -07004414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4415 * components in the device owner package can set system update policies and the
4416 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004417 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004418 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004419 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004420 */
Robin Lee25e26452015-06-02 09:56:29 -07004421 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004422 if (mService != null) {
4423 try {
Robin Lee25e26452015-06-02 09:56:29 -07004424 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004425 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004426 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004427 }
4428 }
4429 }
4430
4431 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004432 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004433 *
Robin Lee25e26452015-06-02 09:56:29 -07004434 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004435 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004436 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004437 if (mService != null) {
4438 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004439 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004440 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004441 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004442 }
4443 }
4444 return null;
4445 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004446
4447 /**
4448 * Called by a device owner to disable the keyguard altogether.
4449 *
4450 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4451 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4452 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4453 * being disabled.
4454 *
4455 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004456 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004457 *
4458 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004459 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004460 */
Robin Lee25e26452015-06-02 09:56:29 -07004461 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004462 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004463 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004464 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004465 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004466 return false;
4467 }
4468 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004469
4470 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004471 * Called by device owner to disable the status bar. Disabling the status bar blocks
4472 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004473 * a single use device.
4474 *
4475 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004476 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4477 *
4478 * @return {@code false} if attempting to disable the status bar failed.
4479 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004480 */
Robin Lee25e26452015-06-02 09:56:29 -07004481 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004482 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004483 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004484 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004485 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004486 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004487 }
4488 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004489
4490 /**
4491 * Callable by the system update service to notify device owners about pending updates.
4492 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4493 * permission.
4494 *
4495 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4496 * when the current pending update was first available. -1 if no update is available.
4497 * @hide
4498 */
4499 @SystemApi
4500 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4501 if (mService != null) {
4502 try {
4503 mService.notifyPendingSystemUpdate(updateReceivedTime);
4504 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004505 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004506 }
4507 }
4508 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004509
4510 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004511 * Called by profile or device owners to set the default response for future runtime permission
4512 * requests by applications. The policy can allow for normal operation which prompts the
4513 * user to grant a permission, or can allow automatic granting or denying of runtime
4514 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004515 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4516 * the permission grant state via {@link #setPermissionGrantState}.
4517 *
4518 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004519 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004520 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004521 * @param admin Which profile or device owner this request is associated with.
4522 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4523 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004524 *
4525 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004526 */
Robin Lee25e26452015-06-02 09:56:29 -07004527 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004528 try {
4529 mService.setPermissionPolicy(admin, policy);
4530 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004531 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004532 }
4533 }
4534
4535 /**
4536 * Returns the current runtime permission policy set by the device or profile owner. The
4537 * default is {@link #PERMISSION_POLICY_PROMPT}.
4538 * @param admin Which profile or device owner this request is associated with.
4539 * @return the current policy for future permission requests.
4540 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004541 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004542 try {
4543 return mService.getPermissionPolicy(admin);
4544 } catch (RemoteException re) {
4545 return PERMISSION_POLICY_PROMPT;
4546 }
4547 }
4548
4549 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004550 * Sets the grant state of a runtime permission for a specific application. The state
4551 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4552 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4553 * is denied and the user cannot manage it through the UI, and {@link
4554 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4555 * user cannot manage it through the UI. This might affect all permissions in a
4556 * group that the runtime permission belongs to. This method can only be called
4557 * by a profile or device owner.
4558 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004559 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4560 * revoke the permission. It retains the previous grant, if any.
4561 *
4562 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004563 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004564 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004565 * @param admin Which profile or device owner this request is associated with.
4566 * @param packageName The application to grant or revoke a permission to.
4567 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004568 * @param grantState The permission grant state which is one of {@link
4569 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4570 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4571 * @return whether the permission was successfully granted or revoked.
4572 *
4573 * @see #PERMISSION_GRANT_STATE_DENIED
4574 * @see #PERMISSION_GRANT_STATE_DEFAULT
4575 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004576 */
Robin Lee25e26452015-06-02 09:56:29 -07004577 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004578 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004579 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004580 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004581 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004582 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004583 return false;
4584 }
4585 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004586
4587 /**
4588 * Returns the current grant state of a runtime permission for a specific application.
4589 *
4590 * @param admin Which profile or device owner this request is associated with.
4591 * @param packageName The application to check the grant state for.
4592 * @param permission The permission to check for.
4593 * @return the current grant state specified by device policy. If the profile or device owner
4594 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4595 * This does not indicate whether or not the permission is currently granted for the package.
4596 *
4597 * <p/>If a grant state was set by the profile or device owner, then the return value will
4598 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4599 * which indicates if the permission is currently denied or granted.
4600 *
4601 * @see #setPermissionGrantState(ComponentName, String, String, int)
4602 * @see PackageManager#checkPermission(String, String)
4603 */
Robin Lee25e26452015-06-02 09:56:29 -07004604 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004605 String permission) {
4606 try {
4607 return mService.getPermissionGrantState(admin, packageName, permission);
4608 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004609 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07004610 return PERMISSION_GRANT_STATE_DEFAULT;
4611 }
4612 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004613
4614 /**
4615 * Returns if provisioning a managed profile or device is possible or not.
4616 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4617 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4618 * Note that even if this method returns true, there is a slight possibility that the
4619 * provisioning will not be allowed when it is actually initiated because some event has
4620 * happened in between.
4621 * @return if provisioning a managed profile or device is possible or not.
4622 * @throws IllegalArgumentException if the supplied action is not valid.
4623 */
4624 public boolean isProvisioningAllowed(String action) {
4625 try {
4626 return mService.isProvisioningAllowed(action);
4627 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004628 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004629 return false;
4630 }
4631 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004632
4633 /**
4634 * @hide
4635 * Return if this user is a managed profile of another user. An admin can become the profile
4636 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4637 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4638 * @param admin Which profile owner this request is associated with.
4639 * @return if this user is a managed profile of another user.
4640 */
4641 public boolean isManagedProfile(@NonNull ComponentName admin) {
4642 try {
4643 return mService.isManagedProfile(admin);
4644 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004645 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004646 return false;
4647 }
4648 }
4649
4650 /**
4651 * @hide
4652 * Return if this user is a system-only user. An admin can manage a device from a system only
4653 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4654 * @param admin Which device owner this request is associated with.
4655 * @return if this user is a system-only user.
4656 */
4657 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4658 try {
4659 return mService.isSystemOnlyUser(admin);
4660 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004661 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004662 return false;
4663 }
4664 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004665
4666 /**
4667 * Called by device owner to get the MAC address of the Wi-Fi device.
4668 *
4669 * @return the MAC address of the Wi-Fi device, or null when the information is not
4670 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
4671 *
4672 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
4673 */
4674 public String getWifiMacAddress() {
4675 try {
4676 return mService.getWifiMacAddress();
4677 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004678 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004679 return null;
4680 }
4681 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004682}