blob: 2d863c2c82ce1534c2f6d43dcc8252f20bdf6509 [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;
Ricky Wai494b95d2015-11-20 16:07:15 +000043import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000044import android.provider.Settings;
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;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000059import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010060import java.security.PrivateKey;
61import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040062import java.security.cert.CertificateException;
63import java.security.cert.CertificateFactory;
64import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010065import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000066import java.security.spec.PKCS8EncodedKeySpec;
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 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003095 * Called by device or profile owners for setting the package suspended for this user.
3096 * A suspended package will not be started by the package manager, its notifications will
3097 * be hidden and it will not show up in recents. The package must already be installed.
3098 *
3099 * @param admin The name of the admin component to check.
3100 * @param packageName The package name of the app to suspend or unsuspend.
3101 * @param suspended If set to {@code true} than the package will be suspended, if set to
3102 * {@code false} the package will be unsuspended.
3103 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3104 * otherwise.
3105 */
3106 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3107 boolean suspended) {
3108 if (mService != null) {
3109 try {
3110 return mService.setPackageSuspended(admin, packageName, suspended);
3111 } catch (RemoteException re) {
3112 Log.w(TAG, "Failed talking with device policy service", re);
3113 }
3114 }
3115 return false;
3116 }
3117
3118 /**
3119 * Called by device or profile owners to determine if a package is suspended.
3120 *
3121 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3122 * @param packageName The name of the package to retrieve the suspended status of.
3123 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3124 */
3125 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3126 if (mService != null) {
3127 try {
3128 return mService.getPackageSuspended(admin, packageName);
3129 } catch (RemoteException e) {
3130 Log.w(TAG, "Failed talking with device policy service", e);
3131 }
3132 }
3133 return false;
3134 }
3135
3136 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003137 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3138 * be used. Only the profile owner can call this.
3139 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003140 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003141 *
3142 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3143 */
Robin Lee25e26452015-06-02 09:56:29 -07003144 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003145 if (mService != null) {
3146 try {
3147 mService.setProfileEnabled(admin);
3148 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003149 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003150 }
3151 }
3152 }
3153
3154 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003155 * Sets the name of the profile. In the device owner case it sets the name of the user
3156 * 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 +01003157 * never called by the profile or device owner, the name will be set to default values.
3158 *
3159 * @see #isProfileOwnerApp
3160 * @see #isDeviceOwnerApp
3161 *
Robin Lee25e26452015-06-02 09:56:29 -07003162 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003163 * @param profileName The name of the profile.
3164 */
Robin Lee25e26452015-06-02 09:56:29 -07003165 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003166 if (mService != null) {
3167 try {
Robin Lee25e26452015-06-02 09:56:29 -07003168 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003169 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003170 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003171 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003172 }
3173 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003174
3175 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003176 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003177 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003178 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003179 *
3180 * @param packageName The package name of the app to compare with the registered profile owner.
3181 * @return Whether or not the package is registered as the profile owner.
3182 */
3183 public boolean isProfileOwnerApp(String packageName) {
3184 if (mService != null) {
3185 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003186 ComponentName profileOwner = mService.getProfileOwner(
3187 Process.myUserHandle().getIdentifier());
3188 return profileOwner != null
3189 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003190 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003191 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003192 }
3193 }
3194 return false;
3195 }
3196
3197 /**
3198 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003199 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003200 * owner has been set for that user.
3201 * @throws IllegalArgumentException if the userId is invalid.
3202 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003203 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003204 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003205 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3206 }
3207
3208 /**
3209 * @see #getProfileOwner()
3210 * @hide
3211 */
3212 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003213 if (mService != null) {
3214 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003215 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003216 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003217 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003218 throw new IllegalArgumentException(
3219 "Requested profile owner for invalid userId", re);
3220 }
3221 }
3222 return null;
3223 }
3224
3225 /**
3226 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003227 * @return the human readable name of the organisation associated with this DPM or {@code null}
3228 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003229 * @throws IllegalArgumentException if the userId is invalid.
3230 */
3231 public String getProfileOwnerName() throws IllegalArgumentException {
3232 if (mService != null) {
3233 try {
3234 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3235 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003236 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003237 throw new IllegalArgumentException(
3238 "Requested profile owner for invalid userId", re);
3239 }
3240 }
3241 return null;
3242 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003243
3244 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003245 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003246 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003247 * @return the human readable name of the organisation associated with this profile owner or
3248 * null if one is not set.
3249 * @throws IllegalArgumentException if the userId is invalid.
3250 */
3251 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003252 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003253 if (mService != null) {
3254 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003255 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003256 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003257 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003258 throw new IllegalArgumentException(
3259 "Requested profile owner for invalid userId", re);
3260 }
3261 }
3262 return null;
3263 }
3264
3265 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003266 * Called by a profile owner or device owner to add a default intent handler activity for
3267 * intents that match a certain intent filter. This activity will remain the default intent
3268 * handler even if the set of potential event handlers for the intent filter changes and if
3269 * the intent preferences are reset.
3270 *
3271 * <p>The default disambiguation mechanism takes over if the activity is not installed
3272 * (anymore). When the activity is (re)installed, it is automatically reset as default
3273 * intent handler for the filter.
3274 *
3275 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3276 * security exception will be thrown.
3277 *
3278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3279 * @param filter The IntentFilter for which a default handler is added.
3280 * @param activity The Activity that is added as default intent handler.
3281 */
Robin Lee25e26452015-06-02 09:56:29 -07003282 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3283 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003284 if (mService != null) {
3285 try {
3286 mService.addPersistentPreferredActivity(admin, filter, activity);
3287 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003288 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003289 }
3290 }
3291 }
3292
3293 /**
3294 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003295 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003296 *
3297 * <p>The calling device admin must be a profile owner. If it is not, a security
3298 * exception will be thrown.
3299 *
3300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3301 * @param packageName The name of the package for which preferences are removed.
3302 */
Robin Lee25e26452015-06-02 09:56:29 -07003303 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003304 String packageName) {
3305 if (mService != null) {
3306 try {
3307 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3308 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003309 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003310 }
3311 }
3312 }
Robin Lee66e5d962014-04-09 16:44:21 +01003313
3314 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003315 * Called by a profile owner or device owner to grant permission to a package to manage
3316 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3317 * {@link #getApplicationRestrictions}.
3318 * <p>
3319 * This permission is persistent until it is later cleared by calling this method with a
3320 * {@code null} value or uninstalling the managing package.
3321 *
3322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3323 * @param packageName The package name which will be given access to application restrictions
3324 * APIs. If {@code null} is given the current package will be cleared.
3325 */
3326 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3327 @Nullable String packageName) {
3328 if (mService != null) {
3329 try {
3330 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3331 } catch (RemoteException e) {
3332 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3333 }
3334 }
3335 }
3336
3337 /**
3338 * Called by a profile owner or device owner to retrieve the application restrictions managing
3339 * package for the current user, or {@code null} if none is set.
3340 *
3341 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3342 * @return The package name allowed to manage application restrictions on the current user, or
3343 * {@code null} if none is set.
3344 */
3345 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3346 if (mService != null) {
3347 try {
3348 return mService.getApplicationRestrictionsManagingPackage(admin);
3349 } catch (RemoteException e) {
3350 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3351 }
3352 }
3353 return null;
3354 }
3355
3356 /**
3357 * Returns {@code true} if the calling package has been granted permission via
3358 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3359 * restrictions for the calling user.
3360 */
3361 public boolean isCallerApplicationRestrictionsManagingPackage() {
3362 if (mService != null) {
3363 try {
3364 return mService.isCallerApplicationRestrictionsManagingPackage();
3365 } catch (RemoteException e) {
3366 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3367 }
3368 }
3369 return false;
3370 }
3371
3372 /**
3373 * Sets the application restrictions for a given target application running in the calling user.
3374 *
3375 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3376 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3377 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003378 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003379 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3380 * <ul>
3381 * <li>{@code boolean}
3382 * <li>{@code int}
3383 * <li>{@code String} or {@code String[]}
3384 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3385 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003386 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003387 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003388 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003389 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3390 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003391 * <p>The application restrictions are only made visible to the target application via
3392 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3393 * device owner, and the application restrictions managing package via
3394 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003395 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003396 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3397 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003398 * @param packageName The name of the package to update restricted settings for.
3399 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3400 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003401 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003402 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003403 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003404 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003405 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003406 Bundle settings) {
3407 if (mService != null) {
3408 try {
3409 mService.setApplicationRestrictions(admin, packageName, settings);
3410 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003411 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003412 }
3413 }
3414 }
3415
3416 /**
Jim Millere303bf42014-08-26 17:12:29 -07003417 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3418 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3419 * trust agents but those enabled by this function call. If flag
3420 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003421 *
3422 * <p>The calling device admin must have requested
3423 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003424 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003425 *
3426 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003427 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003428 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003429 * will be strictly disabled according to the state of the
3430 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3431 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3432 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3433 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003434 */
Robin Lee25e26452015-06-02 09:56:29 -07003435 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3436 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003437 if (mService != null) {
3438 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003439 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003440 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003441 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003442 }
3443 }
3444 }
3445
3446 /**
Jim Millere303bf42014-08-26 17:12:29 -07003447 * Gets configuration for the given trust agent based on aggregating all calls to
3448 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3449 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003450 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3452 * this function returns a list of configurations for all admins that declare
3453 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3454 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3455 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3456 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003457 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003458 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003459 */
Robin Lee25e26452015-06-02 09:56:29 -07003460 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3461 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003462 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003463 }
3464
3465 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003466 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3467 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003468 if (mService != null) {
3469 try {
Jim Millere303bf42014-08-26 17:12:29 -07003470 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003471 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003472 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003473 }
3474 }
Jim Millere303bf42014-08-26 17:12:29 -07003475 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003476 }
3477
3478 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003479 * Called by a profile owner of a managed profile to set whether caller-Id information from
3480 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003481 *
3482 * <p>The calling device admin must be a profile owner. If it is not, a
3483 * security exception will be thrown.
3484 *
Robin Lee25e26452015-06-02 09:56:29 -07003485 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003486 * @param disabled If true caller-Id information in the managed profile is not displayed.
3487 */
Robin Lee25e26452015-06-02 09:56:29 -07003488 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003489 if (mService != null) {
3490 try {
Robin Lee25e26452015-06-02 09:56:29 -07003491 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003492 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003493 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003494 }
3495 }
3496 }
3497
3498 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003499 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3500 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003501 *
3502 * <p>The calling device admin must be a profile owner. If it is not, a
3503 * security exception will be thrown.
3504 *
Robin Lee25e26452015-06-02 09:56:29 -07003505 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003506 */
Robin Lee25e26452015-06-02 09:56:29 -07003507 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003508 if (mService != null) {
3509 try {
Robin Lee25e26452015-06-02 09:56:29 -07003510 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003511 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003512 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003513 }
3514 }
3515 return false;
3516 }
3517
3518 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003519 * Determine whether or not caller-Id information has been disabled.
3520 *
3521 * @param userHandle The user for whom to check the caller-id permission
3522 * @hide
3523 */
3524 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3525 if (mService != null) {
3526 try {
3527 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3528 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003529 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003530 }
3531 }
3532 return false;
3533 }
3534
3535 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003536 * Called by a profile owner of a managed profile to set whether contacts search from
3537 * the managed profile will be shown in the parent profile, for incoming calls.
3538 *
3539 * <p>The calling device admin must be a profile owner. If it is not, a
3540 * security exception will be thrown.
3541 *
3542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3543 * @param disabled If true contacts search in the managed profile is not displayed.
3544 */
3545 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3546 boolean disabled) {
3547 if (mService != null) {
3548 try {
3549 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3550 } catch (RemoteException e) {
3551 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3552 }
3553 }
3554 }
3555
3556 /**
3557 * Called by a profile owner of a managed profile to determine whether or not contacts search
3558 * has been disabled.
3559 *
3560 * <p>The calling device admin must be a profile owner. If it is not, a
3561 * security exception will be thrown.
3562 *
3563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3564 */
3565 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3566 if (mService != null) {
3567 try {
3568 return mService.getCrossProfileContactsSearchDisabled(admin);
3569 } catch (RemoteException e) {
3570 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3571 }
3572 }
3573 return false;
3574 }
3575
3576
3577 /**
3578 * Determine whether or not contacts search has been disabled.
3579 *
3580 * @param userHandle The user for whom to check the contacts search permission
3581 * @hide
3582 */
3583 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3584 if (mService != null) {
3585 try {
3586 return mService
3587 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3588 } catch (RemoteException e) {
3589 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3590 }
3591 }
3592 return false;
3593 }
3594
3595 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003596 * Start Quick Contact on the managed profile for the user, if the policy allows.
Makoto Onuki1040da12015-03-19 11:24:00 -07003597 * @hide
3598 */
3599 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003600 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003601 if (mService != null) {
3602 try {
3603 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003604 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003605 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003606 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003607 }
3608 }
3609 }
3610
3611 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003612 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003613 * @hide
3614 */
3615 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3616 Intent originalIntent) {
3617 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3618 originalIntent);
3619 }
3620
3621 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003622 * Called by a profile owner of a managed profile to set whether bluetooth
3623 * devices can access enterprise contacts.
3624 * <p>
3625 * The calling device admin must be a profile owner. If it is not, a
3626 * security exception will be thrown.
3627 * <p>
3628 * This API works on managed profile only.
3629 *
Robin Lee25e26452015-06-02 09:56:29 -07003630 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003631 * with.
3632 * @param disabled If true, bluetooth devices cannot access enterprise
3633 * contacts.
3634 */
Robin Lee25e26452015-06-02 09:56:29 -07003635 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003636 if (mService != null) {
3637 try {
Robin Lee25e26452015-06-02 09:56:29 -07003638 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003639 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003641 }
3642 }
3643 }
3644
3645 /**
3646 * Called by a profile owner of a managed profile to determine whether or
3647 * not Bluetooth devices cannot access enterprise contacts.
3648 * <p>
3649 * The calling device admin must be a profile owner. If it is not, a
3650 * security exception will be thrown.
3651 * <p>
3652 * This API works on managed profile only.
3653 *
Robin Lee25e26452015-06-02 09:56:29 -07003654 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003655 * with.
3656 */
Robin Lee25e26452015-06-02 09:56:29 -07003657 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003658 if (mService != null) {
3659 try {
Robin Lee25e26452015-06-02 09:56:29 -07003660 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003661 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003662 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003663 }
3664 }
3665 return true;
3666 }
3667
3668 /**
3669 * Determine whether or not Bluetooth devices cannot access contacts.
3670 * <p>
3671 * This API works on managed profile UserHandle only.
3672 *
3673 * @param userHandle The user for whom to check the caller-id permission
3674 * @hide
3675 */
3676 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3677 if (mService != null) {
3678 try {
3679 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3680 .getIdentifier());
3681 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003682 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003683 }
3684 }
3685 return true;
3686 }
3687
3688 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003689 * Called by the profile owner of a managed profile so that some intents sent in the managed
3690 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003691 * Only activity intents are supported.
3692 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003693 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003694 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3695 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003696 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3697 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003698 */
Robin Lee25e26452015-06-02 09:56:29 -07003699 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003700 if (mService != null) {
3701 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003702 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003703 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003704 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003705 }
3706 }
3707 }
3708
3709 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003710 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3711 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003712 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3714 */
Robin Lee25e26452015-06-02 09:56:29 -07003715 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003716 if (mService != null) {
3717 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003718 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003719 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003720 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003721 }
3722 }
3723 }
3724
3725 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003726 * Called by a profile or device owner to set the permitted accessibility services. When
3727 * set by a device owner or profile owner the restriction applies to all profiles of the
3728 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003729 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003730 * By default the user can use any accessiblity service. When zero or more packages have
3731 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003732 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003733 *
3734 * <p> Calling with a null value for the list disables the restriction so that all services
3735 * can be used, calling with an empty list only allows the builtin system's services.
3736 *
3737 * <p> System accesibility services are always available to the user the list can't modify
3738 * this.
3739 *
3740 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3741 * @param packageNames List of accessibility service package names.
3742 *
3743 * @return true if setting the restriction succeeded. It fail if there is
3744 * one or more non-system accessibility services enabled, that are not in the list.
3745 */
Robin Lee25e26452015-06-02 09:56:29 -07003746 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003747 List<String> packageNames) {
3748 if (mService != null) {
3749 try {
3750 return mService.setPermittedAccessibilityServices(admin, packageNames);
3751 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003752 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003753 }
3754 }
3755 return false;
3756 }
3757
3758 /**
3759 * Returns the list of permitted accessibility services set by this device or profile owner.
3760 *
3761 * <p>An empty list means no accessibility services except system services are allowed.
3762 * Null means all accessibility services are allowed.
3763 *
3764 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3765 * @return List of accessiblity service package names.
3766 */
Robin Lee25e26452015-06-02 09:56:29 -07003767 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003768 if (mService != null) {
3769 try {
3770 return mService.getPermittedAccessibilityServices(admin);
3771 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003772 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003773 }
3774 }
3775 return null;
3776 }
3777
3778 /**
3779 * Returns the list of accessibility services permitted by the device or profiles
3780 * owners of this user.
3781 *
3782 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3783 * it will contain the intersection of the permitted lists for any device or profile
3784 * owners that apply to this user. It will also include any system accessibility services.
3785 *
3786 * @param userId which user to check for.
3787 * @return List of accessiblity service package names.
3788 * @hide
3789 */
3790 @SystemApi
3791 public List<String> getPermittedAccessibilityServices(int userId) {
3792 if (mService != null) {
3793 try {
3794 return mService.getPermittedAccessibilityServicesForUser(userId);
3795 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003796 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003797 }
3798 }
3799 return null;
3800 }
3801
3802 /**
3803 * Called by a profile or device owner to set the permitted input methods services. When
3804 * set by a device owner or profile owner the restriction applies to all profiles of the
3805 * user the device owner or profile owner is an admin for.
3806 *
3807 * By default the user can use any input method. When zero or more packages have
3808 * been added, input method that are not in the list and not part of the system
3809 * can not be enabled by the user.
3810 *
3811 * This method will fail if it is called for a admin that is not for the foreground user
3812 * or a profile of the foreground user.
3813 *
3814 * <p> Calling with a null value for the list disables the restriction so that all input methods
3815 * can be used, calling with an empty list disables all but the system's own input methods.
3816 *
3817 * <p> System input methods are always available to the user this method can't modify this.
3818 *
3819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3820 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003821 * @return true if setting the restriction succeeded. It will fail if there are
3822 * one or more non-system input methods currently enabled that are not in
3823 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003824 */
Robin Lee25e26452015-06-02 09:56:29 -07003825 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003826 if (mService != null) {
3827 try {
3828 return mService.setPermittedInputMethods(admin, packageNames);
3829 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003830 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003831 }
3832 }
3833 return false;
3834 }
3835
3836
3837 /**
3838 * Returns the list of permitted input methods set by this device or profile owner.
3839 *
3840 * <p>An empty list means no input methods except system input methods are allowed.
3841 * Null means all input methods are allowed.
3842 *
3843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3844 * @return List of input method package names.
3845 */
Robin Lee25e26452015-06-02 09:56:29 -07003846 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003847 if (mService != null) {
3848 try {
3849 return mService.getPermittedInputMethods(admin);
3850 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003851 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003852 }
3853 }
3854 return null;
3855 }
3856
3857 /**
3858 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08003859 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003860 *
3861 * <p>Null means all input methods are allowed, if a non-null list is returned
3862 * it will contain the intersection of the permitted lists for any device or profile
3863 * owners that apply to this user. It will also include any system input methods.
3864 *
3865 * @return List of input method package names.
3866 * @hide
3867 */
3868 @SystemApi
3869 public List<String> getPermittedInputMethodsForCurrentUser() {
3870 if (mService != null) {
3871 try {
3872 return mService.getPermittedInputMethodsForCurrentUser();
3873 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003874 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003875 }
3876 }
3877 return null;
3878 }
3879
3880 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003881 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
3882 * currently installed it.
3883 *
3884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3885 *
3886 * @return List of package names to keep cached.
3887 * @hide
3888 */
3889 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
3890 if (mService != null) {
3891 try {
3892 return mService.getKeepUninstalledPackages(admin);
3893 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003894 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003895 }
3896 }
3897 return null;
3898 }
3899
3900 /**
3901 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
3902 * currently installed it.
3903 *
3904 * <p>Please note that setting this policy does not imply that specified apps will be
3905 * automatically pre-cached.</p>
3906 *
3907 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3908 * @param packageNames List of package names to keep cached.
3909 * @hide
3910 */
3911 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
3912 @NonNull List<String> packageNames) {
3913 if (mService != null) {
3914 try {
3915 mService.setKeepUninstalledPackages(admin, packageNames);
3916 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003917 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003918 }
3919 }
3920 }
3921
3922 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003923 * Called by a device owner to create a user with the specified name. The UserHandle returned
3924 * by this method should not be persisted as user handles are recycled as users are removed and
3925 * created. If you need to persist an identifier for this user, use
3926 * {@link UserManager#getSerialNumberForUser}.
3927 *
3928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3929 * @param name the user's name
3930 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003931 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3932 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003933 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003934 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003935 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003936 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003937 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003938 try {
3939 return mService.createUser(admin, name);
3940 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003941 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04003942 }
3943 return null;
3944 }
3945
3946 /**
Jason Monk03978a42014-06-10 15:05:30 -04003947 * Called by a device owner to create a user with the specified name. The UserHandle returned
3948 * by this method should not be persisted as user handles are recycled as users are removed and
3949 * created. If you need to persist an identifier for this user, use
3950 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3951 * immediately.
3952 *
3953 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3954 * as registered as an active admin on the new user. The profile owner package will be
3955 * installed on the new user if it already is installed on the device.
3956 *
3957 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3958 * profileOwnerComponent when onEnable is called.
3959 *
3960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3961 * @param name the user's name
3962 * @param ownerName the human readable name of the organisation associated with this DPM.
3963 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3964 * the user.
3965 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3966 * on the new user.
3967 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003968 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3969 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003970 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003971 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003972 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003973 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003974 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3975 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003976 try {
3977 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3978 adminExtras);
3979 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003980 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04003981 }
3982 return null;
3983 }
3984
3985 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003986 * Called by a device owner to remove a user and all associated data. The primary user can
3987 * not be removed.
3988 *
3989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3990 * @param userHandle the user to remove.
3991 * @return {@code true} if the user was removed, {@code false} otherwise.
3992 */
Robin Lee25e26452015-06-02 09:56:29 -07003993 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003994 try {
3995 return mService.removeUser(admin, userHandle);
3996 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003997 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04003998 return false;
3999 }
4000 }
4001
4002 /**
Jason Monk582d9112014-07-09 19:57:08 -04004003 * Called by a device owner to switch the specified user to the foreground.
4004 *
4005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4006 * @param userHandle the user to switch to; null will switch to primary.
4007 * @return {@code true} if the switch was successful, {@code false} otherwise.
4008 *
4009 * @see Intent#ACTION_USER_FOREGROUND
4010 */
Robin Lee25e26452015-06-02 09:56:29 -07004011 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004012 try {
4013 return mService.switchUser(admin, userHandle);
4014 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004015 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004016 return false;
4017 }
4018 }
4019
4020 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004021 * Retrieves the application restrictions for a given target application running in the calling
4022 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004023 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004024 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4025 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4026 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004027 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4029 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004030 * @param packageName The name of the package to fetch restricted settings of.
4031 * @return {@link Bundle} of settings corresponding to what was set last time
4032 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4033 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004034 *
4035 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004036 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004037 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004038 if (mService != null) {
4039 try {
4040 return mService.getApplicationRestrictions(admin, packageName);
4041 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004042 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004043 }
4044 }
4045 return null;
4046 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004047
4048 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004049 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004050 * <p>
4051 * The calling device admin must be a profile or device owner; if it is not,
4052 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004053 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004054 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4055 * with.
4056 * @param key The key of the restriction. See the constants in
4057 * {@link android.os.UserManager} for the list of keys.
4058 */
Robin Lee25e26452015-06-02 09:56:29 -07004059 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004060 if (mService != null) {
4061 try {
4062 mService.setUserRestriction(admin, key, true);
4063 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004064 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004065 }
4066 }
4067 }
4068
4069 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004070 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004071 * <p>
4072 * The calling device admin must be a profile or device owner; if it is not,
4073 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004074 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004075 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4076 * with.
4077 * @param key The key of the restriction. See the constants in
4078 * {@link android.os.UserManager} for the list of keys.
4079 */
Robin Lee25e26452015-06-02 09:56:29 -07004080 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004081 if (mService != null) {
4082 try {
4083 mService.setUserRestriction(admin, key, false);
4084 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004085 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004086 }
4087 }
4088 }
Adam Connors010cfd42014-04-16 12:48:13 +01004089
4090 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004091 * Called by a profile or device owner to get user restrictions set with
4092 * {@link #addUserRestriction(ComponentName, String)}.
4093 * <p>
4094 * The target user may have more restrictions set by the system or other device owner / profile
4095 * owner. To get all the user restrictions currently set, use
4096 * {@link UserManager#getUserRestrictions()}.
4097 *
4098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004099 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004100 */
4101 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004102 return getUserRestrictions(admin, myUserId());
4103 }
4104
4105 /** @hide per-user version */
4106 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004107 Bundle ret = null;
4108 if (mService != null) {
4109 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004110 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004111 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004112 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004113 }
4114 }
4115 return ret == null ? new Bundle() : ret;
4116 }
4117
4118 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004119 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004120 * is unavailable for use, but the data and actual package file remain.
4121 *
4122 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004123 * @param packageName The name of the package to hide or unhide.
4124 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4125 * unhidden.
4126 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004127 */
Robin Lee25e26452015-06-02 09:56:29 -07004128 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004129 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004130 if (mService != null) {
4131 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004132 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004133 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004134 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004135 }
4136 }
4137 return false;
4138 }
4139
4140 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004141 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004142 *
4143 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004144 * @param packageName The name of the package to retrieve the hidden status of.
4145 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004146 */
Robin Lee25e26452015-06-02 09:56:29 -07004147 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004148 if (mService != null) {
4149 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004150 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004151 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004152 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004153 }
4154 }
4155 return false;
4156 }
4157
4158 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004159 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004160 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004161 *
4162 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004163 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004164 */
Robin Lee25e26452015-06-02 09:56:29 -07004165 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004166 if (mService != null) {
4167 try {
4168 mService.enableSystemApp(admin, packageName);
4169 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004170 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004171 }
4172 }
4173 }
4174
4175 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004176 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004177 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004178 *
4179 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4180 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004181 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004182 * @return int The number of activities that matched the intent and were installed.
4183 */
Robin Lee25e26452015-06-02 09:56:29 -07004184 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004185 if (mService != null) {
4186 try {
4187 return mService.enableSystemAppWithIntent(admin, intent);
4188 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004189 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004190 }
4191 }
4192 return 0;
4193 }
4194
4195 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004196 * Called by a device owner or profile owner to disable account management for a specific type
4197 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004198 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004199 * <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 +01004200 * security exception will be thrown.
4201 *
4202 * <p>When account management is disabled for an account type, adding or removing an account
4203 * of that type will not be possible.
4204 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004205 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4206 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4207 * management for a specific type is disabled.
4208 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004209 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4210 * @param accountType For which account management is disabled or enabled.
4211 * @param disabled The boolean indicating that account management will be disabled (true) or
4212 * enabled (false).
4213 */
Robin Lee25e26452015-06-02 09:56:29 -07004214 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004215 boolean disabled) {
4216 if (mService != null) {
4217 try {
4218 mService.setAccountManagementDisabled(admin, accountType, disabled);
4219 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004220 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004221 }
4222 }
4223 }
4224
4225 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004226 * Gets the array of accounts for which account management is disabled by the profile owner.
4227 *
4228 * <p> Account management can be disabled/enabled by calling
4229 * {@link #setAccountManagementDisabled}.
4230 *
4231 * @return a list of account types for which account management has been disabled.
4232 *
4233 * @see #setAccountManagementDisabled
4234 */
4235 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004236 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004237 }
4238
4239 /**
4240 * @see #getAccountTypesWithManagementDisabled()
4241 * @hide
4242 */
4243 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004244 if (mService != null) {
4245 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004246 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004247 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004248 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004249 }
4250 }
4251
4252 return null;
4253 }
justinzhang511e0d82014-03-24 16:09:24 -04004254
4255 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004256 * Sets which packages may enter lock task mode.
4257 *
4258 * <p>Any packages that shares uid with an allowed package will also be allowed
4259 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004260 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004261 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004262 * package list results in locked tasks belonging to those packages to be finished.
4263 *
Jason Monkc5185f22014-06-24 11:12:42 -04004264 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004265 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004266 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004267 *
4268 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004269 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4270 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004271 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004272 */
Robin Lee25e26452015-06-02 09:56:29 -07004273 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004274 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004275 if (mService != null) {
4276 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004277 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004278 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004279 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004280 }
4281 }
4282 }
4283
4284 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004285 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004286 *
4287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004288 * @hide
4289 */
Robin Lee25e26452015-06-02 09:56:29 -07004290 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004291 if (mService != null) {
4292 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004293 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004294 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004295 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004296 }
4297 }
4298 return null;
4299 }
4300
4301 /**
4302 * This function lets the caller know whether the given component is allowed to start the
4303 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004304 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004305 */
Jason Monkd7b86212014-06-16 13:15:38 -04004306 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004307 if (mService != null) {
4308 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004309 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004310 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004312 }
4313 }
4314 return false;
4315 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004316
4317 /**
4318 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4319 * 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 -04004320 * <p>The settings that can be updated with this method are:
4321 * <ul>
4322 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4323 * <li>{@link Settings.Global#AUTO_TIME}</li>
4324 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004325 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004326 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004327 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004328 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004329 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004330 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004331 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004332 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004333 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004334 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004335 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004336 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004337 * <ul>
4338 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4339 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4340 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4341 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4342 * <li>{@link Settings.Global#MODE_RINGER}.
4343 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4344 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4345 * <li>{@link Settings.Global#WIFI_ON}.
4346 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4347 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004348 *
4349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4350 * @param setting The name of the setting to update.
4351 * @param value The value to update the setting to.
4352 */
Robin Lee25e26452015-06-02 09:56:29 -07004353 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004354 if (mService != null) {
4355 try {
4356 mService.setGlobalSetting(admin, setting, value);
4357 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004358 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004359 }
4360 }
4361 }
4362
4363 /**
4364 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4365 * that the value of the setting is in the correct form for the setting type should be performed
4366 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004367 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004368 * <ul>
4369 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004370 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004371 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4372 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004373 * <p>A device owner can additionally update the following settings:
4374 * <ul>
4375 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4376 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004377 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4378 * @param setting The name of the setting to update.
4379 * @param value The value to update the setting to.
4380 */
Robin Lee25e26452015-06-02 09:56:29 -07004381 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004382 if (mService != null) {
4383 try {
4384 mService.setSecureSetting(admin, setting, value);
4385 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004386 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004387 }
4388 }
4389 }
4390
Amith Yamasanif20d6402014-05-24 15:34:37 -07004391 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004392 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004393 * making permission requests of a local or remote administrator of the user.
4394 * <p/>
4395 * Only a profile owner can designate the restrictions provider.
4396 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004397 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004398 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004399 * it removes the restrictions provider previously assigned.
4400 */
Robin Lee25e26452015-06-02 09:56:29 -07004401 public void setRestrictionsProvider(@NonNull ComponentName admin,
4402 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004403 if (mService != null) {
4404 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004405 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004406 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004407 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004408 }
4409 }
4410 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004411
4412 /**
4413 * Called by profile or device owners to set the master volume mute on or off.
4414 *
4415 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4416 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4417 */
Robin Lee25e26452015-06-02 09:56:29 -07004418 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004419 if (mService != null) {
4420 try {
4421 mService.setMasterVolumeMuted(admin, on);
4422 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004423 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004424 }
4425 }
4426 }
4427
4428 /**
4429 * Called by profile or device owners to check whether the master volume mute is on or off.
4430 *
4431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4432 * @return {@code true} if master volume is muted, {@code false} if it's not.
4433 */
Robin Lee25e26452015-06-02 09:56:29 -07004434 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004435 if (mService != null) {
4436 try {
4437 return mService.isMasterVolumeMuted(admin);
4438 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004439 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004440 }
4441 }
4442 return false;
4443 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004444
4445 /**
4446 * Called by profile or device owners to change whether a user can uninstall
4447 * a package.
4448 *
4449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4450 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004451 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004452 */
Robin Lee25e26452015-06-02 09:56:29 -07004453 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004454 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004455 if (mService != null) {
4456 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004457 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004458 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004459 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004460 }
4461 }
4462 }
4463
4464 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004465 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004466 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004467 * <p>
4468 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004469 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004470 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004471 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004472 *
Robin Lee25e26452015-06-02 09:56:29 -07004473 * @param admin The name of the admin component whose blocking policy will be checked, or
4474 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004475 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004476 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004477 */
Robin Lee25e26452015-06-02 09:56:29 -07004478 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004479 if (mService != null) {
4480 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004481 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004482 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004483 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004484 }
4485 }
4486 return false;
4487 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004488
4489 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004490 * Called by the profile owner of a managed profile to enable widget providers from a
4491 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004492 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004493 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004494 * a package may have zero or more provider components, where each component
4495 * provides a different widget type.
4496 * <p>
4497 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004498 *
4499 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4500 * @param packageName The package from which widget providers are white-listed.
4501 * @return Whether the package was added.
4502 *
4503 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4504 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4505 */
Robin Lee25e26452015-06-02 09:56:29 -07004506 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004507 if (mService != null) {
4508 try {
4509 return mService.addCrossProfileWidgetProvider(admin, packageName);
4510 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004511 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004512 }
4513 }
4514 return false;
4515 }
4516
4517 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004518 * Called by the profile owner of a managed profile to disable widget providers from a given
4519 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004520 * package should have been added via {@link #addCrossProfileWidgetProvider(
4521 * android.content.ComponentName, String)}.
4522 * <p>
4523 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004524 *
4525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4526 * @param packageName The package from which widget providers are no longer
4527 * white-listed.
4528 * @return Whether the package was removed.
4529 *
4530 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4531 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4532 */
Robin Lee25e26452015-06-02 09:56:29 -07004533 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004534 if (mService != null) {
4535 try {
4536 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4537 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004538 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004539 }
4540 }
4541 return false;
4542 }
4543
4544 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004545 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004546 * available in the parent profile.
4547 *
4548 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4549 * @return The white-listed package list.
4550 *
4551 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4552 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4553 */
Robin Lee25e26452015-06-02 09:56:29 -07004554 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004555 if (mService != null) {
4556 try {
4557 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4558 if (providers != null) {
4559 return providers;
4560 }
4561 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004562 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004563 }
4564 }
4565 return Collections.emptyList();
4566 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004567
4568 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004569 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004570 *
4571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4572 * @param icon the bitmap to set as the photo.
4573 */
Robin Lee25e26452015-06-02 09:56:29 -07004574 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004575 try {
4576 mService.setUserIcon(admin, icon);
4577 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004578 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004579 }
4580 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004581
4582 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004583 * Called by device owners to set a local system update policy. When a new policy is set,
4584 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004585 *
Robin Lee25e26452015-06-02 09:56:29 -07004586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4587 * components in the device owner package can set system update policies and the
4588 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004589 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004590 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004591 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004592 */
Robin Lee25e26452015-06-02 09:56:29 -07004593 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004594 if (mService != null) {
4595 try {
Robin Lee25e26452015-06-02 09:56:29 -07004596 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004597 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004598 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004599 }
4600 }
4601 }
4602
4603 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004604 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004605 *
Robin Lee25e26452015-06-02 09:56:29 -07004606 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004607 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004608 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004609 if (mService != null) {
4610 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004611 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004612 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004613 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004614 }
4615 }
4616 return null;
4617 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004618
4619 /**
4620 * Called by a device owner to disable the keyguard altogether.
4621 *
4622 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4623 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4624 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4625 * being disabled.
4626 *
4627 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004628 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004629 *
4630 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004631 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004632 */
Robin Lee25e26452015-06-02 09:56:29 -07004633 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004634 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004635 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004636 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004637 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01004638 return false;
4639 }
4640 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004641
4642 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004643 * Called by device owner to disable the status bar. Disabling the status bar blocks
4644 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004645 * a single use device.
4646 *
4647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004648 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4649 *
4650 * @return {@code false} if attempting to disable the status bar failed.
4651 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004652 */
Robin Lee25e26452015-06-02 09:56:29 -07004653 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004654 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004655 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004656 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004657 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004658 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004659 }
4660 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004661
4662 /**
4663 * Callable by the system update service to notify device owners about pending updates.
4664 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4665 * permission.
4666 *
4667 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4668 * when the current pending update was first available. -1 if no update is available.
4669 * @hide
4670 */
4671 @SystemApi
4672 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4673 if (mService != null) {
4674 try {
4675 mService.notifyPendingSystemUpdate(updateReceivedTime);
4676 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004677 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01004678 }
4679 }
4680 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004681
4682 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004683 * Called by profile or device owners to set the default response for future runtime permission
4684 * requests by applications. The policy can allow for normal operation which prompts the
4685 * user to grant a permission, or can allow automatic granting or denying of runtime
4686 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004687 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4688 * the permission grant state via {@link #setPermissionGrantState}.
4689 *
4690 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004691 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004692 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004693 * @param admin Which profile or device owner this request is associated with.
4694 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4695 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004696 *
4697 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004698 */
Robin Lee25e26452015-06-02 09:56:29 -07004699 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004700 try {
4701 mService.setPermissionPolicy(admin, policy);
4702 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004703 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004704 }
4705 }
4706
4707 /**
4708 * Returns the current runtime permission policy set by the device or profile owner. The
4709 * default is {@link #PERMISSION_POLICY_PROMPT}.
4710 * @param admin Which profile or device owner this request is associated with.
4711 * @return the current policy for future permission requests.
4712 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004713 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004714 try {
4715 return mService.getPermissionPolicy(admin);
4716 } catch (RemoteException re) {
4717 return PERMISSION_POLICY_PROMPT;
4718 }
4719 }
4720
4721 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004722 * Sets the grant state of a runtime permission for a specific application. The state
4723 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4724 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4725 * is denied and the user cannot manage it through the UI, and {@link
4726 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4727 * user cannot manage it through the UI. This might affect all permissions in a
4728 * group that the runtime permission belongs to. This method can only be called
4729 * by a profile or device owner.
4730 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004731 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4732 * revoke the permission. It retains the previous grant, if any.
4733 *
4734 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004735 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004736 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004737 * @param admin Which profile or device owner this request is associated with.
4738 * @param packageName The application to grant or revoke a permission to.
4739 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004740 * @param grantState The permission grant state which is one of {@link
4741 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4742 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4743 * @return whether the permission was successfully granted or revoked.
4744 *
4745 * @see #PERMISSION_GRANT_STATE_DENIED
4746 * @see #PERMISSION_GRANT_STATE_DEFAULT
4747 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004748 */
Robin Lee25e26452015-06-02 09:56:29 -07004749 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004750 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004751 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004752 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004753 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004754 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004755 return false;
4756 }
4757 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004758
4759 /**
4760 * Returns the current grant state of a runtime permission for a specific application.
4761 *
4762 * @param admin Which profile or device owner this request is associated with.
4763 * @param packageName The application to check the grant state for.
4764 * @param permission The permission to check for.
4765 * @return the current grant state specified by device policy. If the profile or device owner
4766 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4767 * This does not indicate whether or not the permission is currently granted for the package.
4768 *
4769 * <p/>If a grant state was set by the profile or device owner, then the return value will
4770 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4771 * which indicates if the permission is currently denied or granted.
4772 *
4773 * @see #setPermissionGrantState(ComponentName, String, String, int)
4774 * @see PackageManager#checkPermission(String, String)
4775 */
Robin Lee25e26452015-06-02 09:56:29 -07004776 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004777 String permission) {
4778 try {
4779 return mService.getPermissionGrantState(admin, packageName, permission);
4780 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004781 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07004782 return PERMISSION_GRANT_STATE_DEFAULT;
4783 }
4784 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004785
4786 /**
4787 * Returns if provisioning a managed profile or device is possible or not.
4788 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4789 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4790 * Note that even if this method returns true, there is a slight possibility that the
4791 * provisioning will not be allowed when it is actually initiated because some event has
4792 * happened in between.
4793 * @return if provisioning a managed profile or device is possible or not.
4794 * @throws IllegalArgumentException if the supplied action is not valid.
4795 */
4796 public boolean isProvisioningAllowed(String action) {
4797 try {
4798 return mService.isProvisioningAllowed(action);
4799 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004800 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004801 return false;
4802 }
4803 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004804
4805 /**
4806 * @hide
4807 * Return if this user is a managed profile of another user. An admin can become the profile
4808 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4809 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4810 * @param admin Which profile owner this request is associated with.
4811 * @return if this user is a managed profile of another user.
4812 */
4813 public boolean isManagedProfile(@NonNull ComponentName admin) {
4814 try {
4815 return mService.isManagedProfile(admin);
4816 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004817 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004818 return false;
4819 }
4820 }
4821
4822 /**
4823 * @hide
4824 * Return if this user is a system-only user. An admin can manage a device from a system only
4825 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4826 * @param admin Which device owner this request is associated with.
4827 * @return if this user is a system-only user.
4828 */
4829 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4830 try {
4831 return mService.isSystemOnlyUser(admin);
4832 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004833 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004834 return false;
4835 }
4836 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004837
4838 /**
4839 * Called by device owner to get the MAC address of the Wi-Fi device.
4840 *
4841 * @return the MAC address of the Wi-Fi device, or null when the information is not
4842 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
4843 *
4844 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
4845 */
4846 public String getWifiMacAddress() {
4847 try {
4848 return mService.getWifiMacAddress();
4849 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004850 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08004851 return null;
4852 }
4853 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00004854
4855 /**
4856 * Called by device owner to reboot the device.
4857 */
4858 public void reboot(@NonNull ComponentName admin) {
4859 try {
4860 mService.reboot(admin);
4861 } catch (RemoteException re) {
4862 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4863 }
4864 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004865}