blob: 7634d89c16cbb5436a6b4dde841d590a79f32277 [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000034import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010035import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040043import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010044import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070045import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.util.Log;
47
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070048import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040049import com.android.org.conscrypt.TrustedCertificateStore;
50
Jessica Hummel91da58d2014-04-10 17:39:43 +010051import org.xmlpull.v1.XmlPullParserException;
52
Maggie Benthallda51e682013-08-08 22:35:44 -040053import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070055import java.net.InetSocketAddress;
56import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010057import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010058import java.security.PrivateKey;
59import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040060import java.security.cert.CertificateException;
61import java.security.cert.CertificateFactory;
62import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010063import java.security.spec.PKCS8EncodedKeySpec;
64import java.security.spec.InvalidKeySpecException;
65import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070066import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070067import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080068import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080069
70/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000071 * Public interface for managing policies enforced on a device. Most clients of this class must be
72 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000073 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000074 * a device administrator may be registered as either a profile or device owner. A given method is
75 * accessible to all device administrators unless the documentation for that method specifies that
76 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080077 *
78 * <div class="special reference">
79 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000080 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080081 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070082 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080083 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080084 */
85public class DevicePolicyManager {
86 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080087
88 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080089 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070090
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070091 private DevicePolicyManager(Context context) {
92 this(context, IDevicePolicyManager.Stub.asInterface(
93 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080094 }
95
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080096 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070097 @VisibleForTesting
98 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
99 mContext = context;
100 mService = service;
101 }
102
103 /** @hide */
104 public static DevicePolicyManager create(Context context) {
105 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800106 return me.mService != null ? me : null;
107 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700108
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109 /** @hide test will override it. */
110 @VisibleForTesting
111 protected int myUserId() {
112 return UserHandle.myUserId();
113 }
114
Dianne Hackbornd6847842010-01-12 18:14:19 -0800115 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000116 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000117 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100118 * <p>A managed profile allows data separation for example for the usage of a
119 * device as a personal and corporate device. The user which provisioning is started from and
120 * the managed profile share a launcher.
121 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800122 * <p>This intent will typically be sent by a mobile device management application (MDM).
123 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
124 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100125 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000126 * <p>It is possible to check if provisioning is allowed or not by querying the method
127 * {@link #isProvisioningAllowed(String)}.
128 *
129 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000130 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700131 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000132 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
133 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000134 * This intent may also contain the extra {@link #EXTRA_PROVISIONING_LOGO_URI}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000135 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000136 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
137 * in the provisioning intent. The
138 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
139 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
140 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100141 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100142 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
143 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100144 *
145 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
146 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
147 * the provisioning flow was successful, although this doesn't guarantee the full flow will
148 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
149 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000150 */
151 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
152 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100153 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000154
155 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000156 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000157 * Activity action: Starts the provisioning flow which sets up a managed user.
158 *
159 * <p>This intent will typically be sent by a mobile device management application (MDM).
160 * Provisioning configures the current user as managed user and sets the MDM as the profile
161 * owner who has full control over the user. Provisioning can only happen before user setup has
162 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
163 * allowed.
164 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000165 * <p>This intent should contain the extra
166 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000167 *
168 * <p> If provisioning fails, the device returns to its previous state.
169 *
170 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
171 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
172 * the provisioning flow was successful, although this doesn't guarantee the full flow will
173 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
174 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000175 */
176 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
177 public static final String ACTION_PROVISION_MANAGED_USER
178 = "android.app.action.PROVISION_MANAGED_USER";
179
180 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100181 * Activity action: Starts the provisioning flow which sets up a managed device.
182 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
183 *
184 * <p> During device owner provisioning a device admin app is set as the owner of the device.
185 * A device owner has full control over the device. The device owner can not be modified by the
186 * user.
187 *
188 * <p> A typical use case would be a device that is owned by a company, but used by either an
189 * employee or client.
190 *
191 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000192 * It is possible to check if provisioning is allowed or not by querying the method
193 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100194 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000195 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100196 * <ul>
197 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
198 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
199 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100200 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000201 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100202 * </ul>
203 *
204 * <p> When device owner provisioning has completed, an intent of the type
205 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
206 * device owner.
207 *
208 * <p> If provisioning fails, the device is factory reset.
209 *
Alan Treadway4582f812015-07-28 11:49:35 +0100210 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
211 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
212 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
213 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 */
215 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
216 public static final String ACTION_PROVISION_MANAGED_DEVICE
217 = "android.app.action.PROVISION_MANAGED_DEVICE";
218
219 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000220 * Activity action: Starts the provisioning flow which sets up a managed device.
221 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
222 *
223 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
224 * management state that is distinct from that reached by
225 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
226 * user, and only has control over device-wide policies, not individual users and their data.
227 * The primary benefit is that multiple non-system users are supported when provisioning using
228 * this form of device management.
229 *
230 * <p> During device owner provisioning a device admin app is set as the owner of the device.
231 * A device owner has full control over the device. The device owner can not be modified by the
232 * user.
233 *
234 * <p> A typical use case would be a device that is owned by a company, but used by either an
235 * employee or client.
236 *
237 * <p> An intent with this action can be sent only on an unprovisioned device.
238 * It is possible to check if provisioning is allowed or not by querying the method
239 * {@link #isProvisioningAllowed(String)}.
240 *
241 * <p>The intent contains the following extras:
242 * <ul>
243 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
244 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
245 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
246 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
247 * </ul>
248 *
249 * <p> When device owner provisioning has completed, an intent of the type
250 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
251 * device owner.
252 *
253 * <p> If provisioning fails, the device is factory reset.
254 *
255 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
256 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
257 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
258 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
259 *
260 * @hide
261 */
262 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
263 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
264 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
265
266 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100267 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100268 * allows a mobile device management application or NFC programmer application which starts
269 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100270 * <p>
271 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
272 * sends the intent to pass data to itself on the newly created profile.
273 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
274 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100275 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
276 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
277 * message should contain a stringified {@link java.util.Properties} instance, whose string
278 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
279 * management application after provisioning.
280 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100281 * <p>
282 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700283 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
284 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100285 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100286 */
287 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100288 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100289
290 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100291 * A String extra holding the package name of the mobile device management application that
292 * will be set as the profile owner or device owner.
293 *
294 * <p>If an application starts provisioning directly via an intent with action
295 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
296 * application that started provisioning. The package will be set as profile owner in that case.
297 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000298 * <p>This package is set as device owner when device owner provisioning is started by an NFC
299 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000300 *
301 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700302 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000303
304 * @see DeviceAdminReceiver
305 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100306 * supported, but only if there is only one device admin receiver in the package that requires
307 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000308 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000309 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000310 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100311 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000312
313 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000314 * A ComponentName extra indicating the device admin receiver of the mobile device management
315 * application that will be set as the profile owner or device owner and active admin.
316 *
317 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100318 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
319 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
320 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000321 *
322 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100323 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
324 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400325 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000326 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000327 *
328 * @see DeviceAdminReceiver
329 */
330 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
331 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
332
333 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000334 * An {@link android.accounts.Account} extra holding the account to migrate during managed
335 * profile provisioning. If the account supplied is present in the primary user, it will be
336 * copied, along with its credentials to the managed profile and removed from the primary user.
337 *
338 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
339 */
340
341 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
342 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
343
344 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100345 * A String extra that, holds the email address of the account which a managed profile is
346 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
347 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100348 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100349 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
350 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100351 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
352 * contains this extra, it is forwarded in the
353 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
354 * device management application that was set as the profile owner during provisioning.
355 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100356 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100357 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
358 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100359
360 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000361 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700362 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000363 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100364 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
365 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000366 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000367 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
368 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000369
370 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100371 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
372 * will be set to.
373 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000374 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
375 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100376 */
377 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100378 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100379
380 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100381 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
382 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100383 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000384 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
385 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100386 */
387 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100388 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100389
390 /**
391 * A String extra holding the {@link java.util.Locale} that the device will be set to.
392 * Format: xx_yy, where xx is the language code, and yy the country code.
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_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100398 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100399
400 /**
401 * A String extra holding the ssid of the wifi network that should be used during nfc device
402 * owner provisioning for downloading the mobile device management application.
403 *
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_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100408 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100409
410 /**
411 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
412 * is hidden or not.
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_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100418 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100419
420 /**
421 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100422 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
423 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100424 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000425 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
426 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100427 */
428 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100429 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100430
431 /**
432 * A String extra holding the password of the wifi network in
433 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
434 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000435 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
436 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100437 */
438 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100439 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100440
441 /**
442 * A String extra holding the proxy host for the wifi network in
443 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
444 *
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_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100449 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100450
451 /**
452 * An int extra holding the proxy port for 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_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100459 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100460
461 /**
462 * A String extra holding the proxy bypass 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_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100469 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100470
471 /**
472 * A String extra holding the proxy auto-config (PAC) URL 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_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100479 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100480
481 /**
482 * A String extra holding a url that specifies the download location of the device admin
483 * package. When not provided it is assumed that the device admin package is already installed.
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_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100489 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100490
491 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400492 * An int extra holding a minimum required version code for the device admin package. If the
493 * device admin is already installed on the device, it will only be re-downloaded from
494 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
495 * installed package is less than this version code.
496 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400497 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400498 * provisioning via an NFC bump.
499 */
500 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
501 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
502
503 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100504 * A String extra holding a http cookie header which should be used in the http request to the
505 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
506 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000507 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
508 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100509 */
510 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100511 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100512
513 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100514 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
515 * the file at download location specified in
516 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100517 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100518 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100519 * present. The provided checksum should match the checksum of the file at the download
520 * location. If the checksum doesn't match an error will be shown to the user and the user will
521 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100522 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000523 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
524 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100525 *
526 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
527 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700528 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100529 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100530 */
531 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100532 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100533
534 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100535 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100536 * android package archive at the download location specified in {@link
537 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
538 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100539 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100540 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
541 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
542 *
543 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100544 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100545 * the download location. If the checksum does not match an error will be shown to the user and
546 * the user will be asked to factory reset the device.
547 *
548 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
549 * provisioning via an NFC bump.
550 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100551 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
552 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100553
554 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000555 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
556 * has completed successfully.
557 *
558 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700559 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000560 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800561 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000562 * corresponds to the account requested to be migrated at provisioning time, if any.
563 */
564 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
565 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
566 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
567
568 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400569 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500570 * provisioning.
571 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400572 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100573 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500574 */
575 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
576 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
577
578 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000579 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
580 * provisioning. If this extra is not passed, a default image will be shown.
581 * <h5>The following URI schemes are accepted:</h5>
582 * <ul>
583 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
584 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
585 * </ul>
586 *
587 * <p> It is the responsability of the caller to provide an image with a reasonable
588 * pixed density for the device.
589 *
590 * <p> If a content: URI is passed, the intent should have the flag
591 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
592 * {@link android.content.ClipData} of the intent too.
593 *
594 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
595 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
596 */
597 public static final String EXTRA_PROVISIONING_LOGO_URI =
598 "android.app.extra.PROVISIONING_LOGO_URI";
599
600 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400601 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400603 * <p>During device owner provisioning a device admin app is set as the owner of the device.
604 * A device owner has full control over the device. The device owner can not be modified by the
605 * user and the only way of resetting the device is if the device owner app calls a factory
606 * reset.
607 *
608 * <p> A typical use case would be a device that is owned by a company, but used by either an
609 * employee or client.
610 *
611 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000613 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100614 * contains the following properties:
615 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400616 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
617 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100618 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400619 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
621 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
622 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
623 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
624 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
625 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
626 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
627 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
628 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
629 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100630 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
631 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
632 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000634 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700635 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400636 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
637 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
638 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400639 */
640 public static final String MIME_TYPE_PROVISIONING_NFC
641 = "application/com.android.managedprovisioning";
642
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800644 * Activity action: ask the user to add a new device administrator to the system.
645 * The desired policy is the ComponentName of the policy in the
646 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
647 * bring the user through adding the device administrator to the system (or
648 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700649 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800650 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
651 * field to provide the user with additional explanation (in addition
652 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800653 *
654 * <p>If your administrator is already active, this will ordinarily return immediately (without
655 * user intervention). However, if your administrator has been updated and is requesting
656 * additional uses-policy flags, the user will be presented with the new list. New policies
657 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800658 */
659 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
660 public static final String ACTION_ADD_DEVICE_ADMIN
661 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700662
Dianne Hackbornd6847842010-01-12 18:14:19 -0800663 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700664 * @hide
665 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700666 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700667 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700668 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
669 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700670 * to remotely control restrictions on the user.
671 *
Makoto Onuki219bbaf2015-11-12 01:38:47 +0000672 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700673 * result of whether or not the user approved the action. If approved, the result will
674 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
675 * as a profile owner.
676 *
677 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
678 * field to provide the user with additional explanation (in addition
679 * to your component's description) about what is being added.
680 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700681 * <p>If there is already a profile owner active or the caller is not a system app, the
682 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700683 */
684 @SystemApi
685 public static final String ACTION_SET_PROFILE_OWNER
686 = "android.app.action.SET_PROFILE_OWNER";
687
688 /**
689 * @hide
690 * Name of the profile owner admin that controls the user.
691 */
692 @SystemApi
693 public static final String EXTRA_PROFILE_OWNER_NAME
694 = "android.app.extra.PROFILE_OWNER_NAME";
695
696 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100697 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700698 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700699 *
Jim Miller284b62e2010-06-08 14:27:42 -0700700 * @hide
701 */
702 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
703 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
704
705 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100706 * Broadcast action: sent when the device owner is set or changed.
707 *
708 * This broadcast is sent only to the primary user.
709 * @see #ACTION_PROVISION_MANAGED_DEVICE
710 */
711 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
712 public static final String ACTION_DEVICE_OWNER_CHANGED
713 = "android.app.action.DEVICE_OWNER_CHANGED";
714
715 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800716 * The ComponentName of the administrator component.
717 *
718 * @see #ACTION_ADD_DEVICE_ADMIN
719 */
720 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700721
Dianne Hackbornd6847842010-01-12 18:14:19 -0800722 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800723 * An optional CharSequence providing additional explanation for why the
724 * admin is being added.
725 *
726 * @see #ACTION_ADD_DEVICE_ADMIN
727 */
728 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700729
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800730 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700731 * Activity action: have the user enter a new password. This activity should
732 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
733 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
734 * enter a new password that meets the current requirements. You can use
735 * {@link #isActivePasswordSufficient()} to determine whether you need to
736 * have the user select a new password in order to meet the current
737 * constraints. Upon being resumed from this activity, you can check the new
738 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800739 */
740 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
741 public static final String ACTION_SET_NEW_PASSWORD
742 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700743
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000744 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000745 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
746 * the parent profile to access intents sent from the managed profile.
747 * That is, when an app in the managed profile calls
748 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
749 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000750 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100751 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000752
753 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000754 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
755 * the managed profile to access intents sent from the parent profile.
756 * That is, when an app in the parent profile calls
757 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
758 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000759 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100760 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700761
Dianne Hackbornd6847842010-01-12 18:14:19 -0800762 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100763 * Broadcast action: notify that a new local system update policy has been set by the device
764 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000765 */
766 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100767 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
768 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000769
Amith Yamasanid49489b2015-04-28 14:00:26 -0700770 /**
771 * Permission policy to prompt user for new permission requests for runtime permissions.
772 * Already granted or denied permissions are not affected by this.
773 */
774 public static final int PERMISSION_POLICY_PROMPT = 0;
775
776 /**
777 * Permission policy to always grant new permission requests for runtime permissions.
778 * Already granted or denied permissions are not affected by this.
779 */
780 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
781
782 /**
783 * Permission policy to always deny new permission requests for runtime permissions.
784 * Already granted or denied permissions are not affected by this.
785 */
786 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
787
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700788 /**
789 * Runtime permission state: The user can manage the permission
790 * through the UI.
791 */
792 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
793
794 /**
795 * Runtime permission state: The permission is granted to the app
796 * and the user cannot manage the permission through the UI.
797 */
798 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
799
800 /**
801 * Runtime permission state: The permission is denied to the app
802 * and the user cannot manage the permission through the UI.
803 */
804 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000805
806 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800807 * Return true if the given administrator component is currently
808 * active (enabled) in the system.
809 */
Robin Lee25e26452015-06-02 09:56:29 -0700810 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700811 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100812 }
813
814 /**
815 * @see #isAdminActive(ComponentName)
816 * @hide
817 */
Robin Lee25e26452015-06-02 09:56:29 -0700818 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800819 if (mService != null) {
820 try {
Robin Lee25e26452015-06-02 09:56:29 -0700821 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800822 } catch (RemoteException e) {
823 Log.w(TAG, "Failed talking with device policy service", e);
824 }
825 }
826 return false;
827 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800828 /**
829 * Return true if the given administrator component is currently being removed
830 * for the user.
831 * @hide
832 */
Robin Lee25e26452015-06-02 09:56:29 -0700833 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800834 if (mService != null) {
835 try {
Robin Lee25e26452015-06-02 09:56:29 -0700836 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800837 } catch (RemoteException e) {
838 Log.w(TAG, "Failed talking with device policy service", e);
839 }
840 }
841 return false;
842 }
843
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700844
Dianne Hackbornd6847842010-01-12 18:14:19 -0800845 /**
Robin Lee25e26452015-06-02 09:56:29 -0700846 * Return a list of all currently active device administrators' component
847 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800848 * returned.
849 */
850 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700851 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100852 }
853
854 /**
855 * @see #getActiveAdmins()
856 * @hide
857 */
858 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800859 if (mService != null) {
860 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100861 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800862 } catch (RemoteException e) {
863 Log.w(TAG, "Failed talking with device policy service", e);
864 }
865 }
866 return null;
867 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700868
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800869 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700870 * Used by package administration code to determine if a package can be stopped
871 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800872 * @hide
873 */
874 public boolean packageHasActiveAdmins(String packageName) {
875 if (mService != null) {
876 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700877 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800878 } catch (RemoteException e) {
879 Log.w(TAG, "Failed talking with device policy service", e);
880 }
881 }
882 return false;
883 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700884
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800885 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800886 * Remove a current administration component. This can only be called
887 * by the application that owns the administration component; if you
888 * try to remove someone else's component, a security exception will be
889 * thrown.
890 */
Robin Lee25e26452015-06-02 09:56:29 -0700891 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800892 if (mService != null) {
893 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700894 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800895 } catch (RemoteException e) {
896 Log.w(TAG, "Failed talking with device policy service", e);
897 }
898 }
899 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700900
Dianne Hackbornd6847842010-01-12 18:14:19 -0800901 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800902 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700903 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800904 * but requires additional policies after an upgrade.
905 *
906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
907 * an active administrator, or an exception will be thrown.
908 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
909 */
Robin Lee25e26452015-06-02 09:56:29 -0700910 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800911 if (mService != null) {
912 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700913 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800914 } catch (RemoteException e) {
915 Log.w(TAG, "Failed talking with device policy service", e);
916 }
917 }
918 return false;
919 }
920
921 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800922 * Constant for {@link #setPasswordQuality}: the policy has no requirements
923 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800924 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800925 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800926 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700927
Dianne Hackbornd6847842010-01-12 18:14:19 -0800928 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700929 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
930 * recognition technology. This implies technologies that can recognize the identity of
931 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
932 * Note that quality constants are ordered so that higher values are more restrictive.
933 */
934 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
935
936 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800937 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100938 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800939 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800940 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800941 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700942
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800943 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800944 * Constant for {@link #setPasswordQuality}: the user must have entered a
945 * password containing at least numeric characters. Note that quality
946 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800947 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800948 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700949
Dianne Hackbornd6847842010-01-12 18:14:19 -0800950 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800951 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800952 * password containing at least numeric characters with no repeating (4444)
953 * or ordered (1234, 4321, 2468) sequences. Note that quality
954 * constants are ordered so that higher values are more restrictive.
955 */
956 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
957
958 /**
959 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700960 * password containing at least alphabetic (or other symbol) characters.
961 * Note that quality constants are ordered so that higher values are more
962 * restrictive.
963 */
964 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700965
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700966 /**
967 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800968 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700969 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800970 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800971 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700972 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700973
Dianne Hackbornd6847842010-01-12 18:14:19 -0800974 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700975 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700976 * password containing at least a letter, a numerical digit and a special
977 * symbol, by default. With this password quality, passwords can be
978 * restricted to contain various sets of characters, like at least an
979 * uppercase letter, etc. These are specified using various methods,
980 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
981 * that quality constants are ordered so that higher values are more
982 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700983 */
984 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
985
986 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800987 * Called by an application that is administering the device to set the
988 * password restrictions it is imposing. After setting this, the user
989 * will not be able to enter a new password that is not at least as
990 * restrictive as what has been set. Note that the current password
991 * will remain until the user has set a new one, so the change does not
992 * take place immediately. To prompt the user for a new password, use
993 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700994 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800995 * <p>Quality constants are ordered so that higher values are more restrictive;
996 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800997 * the user's preference, and any other considerations) is the one that
998 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700999 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001000 * <p>The calling device admin must have requested
1001 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1002 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001004 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001005 * @param quality The new desired quality. One of
1006 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001007 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1008 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1009 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001010 */
Robin Lee25e26452015-06-02 09:56:29 -07001011 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001012 if (mService != null) {
1013 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001014 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001015 } catch (RemoteException e) {
1016 Log.w(TAG, "Failed talking with device policy service", e);
1017 }
1018 }
1019 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001020
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001022 * Retrieve the current minimum password quality for all admins of this user
1023 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001024 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001025 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 */
Robin Lee25e26452015-06-02 09:56:29 -07001027 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001028 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001029 }
1030
1031 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001032 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001033 if (mService != null) {
1034 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001035 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001036 } catch (RemoteException e) {
1037 Log.w(TAG, "Failed talking with device policy service", e);
1038 }
1039 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001040 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001041 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001042
Dianne Hackbornd6847842010-01-12 18:14:19 -08001043 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001044 * Called by an application that is administering the device to set the
1045 * minimum allowed password length. After setting this, the user
1046 * will not be able to enter a new password that is not at least as
1047 * restrictive as what has been set. Note that the current password
1048 * will remain until the user has set a new one, so the change does not
1049 * take place immediately. To prompt the user for a new password, use
1050 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1051 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001052 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1053 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1054 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001055 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001056 * <p>The calling device admin must have requested
1057 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1058 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 * @param length The new desired minimum password length. A value of 0
1062 * means there is no restriction.
1063 */
Robin Lee25e26452015-06-02 09:56:29 -07001064 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 if (mService != null) {
1066 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001067 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 } catch (RemoteException e) {
1069 Log.w(TAG, "Failed talking with device policy service", e);
1070 }
1071 }
1072 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001073
Dianne Hackbornd6847842010-01-12 18:14:19 -08001074 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001075 * Retrieve the current minimum password length for all admins of this
1076 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001077 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001078 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001081 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001082 }
1083
1084 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001085 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001086 if (mService != null) {
1087 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001088 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001089 } catch (RemoteException e) {
1090 Log.w(TAG, "Failed talking with device policy service", e);
1091 }
1092 }
1093 return 0;
1094 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001095
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001096 /**
1097 * Called by an application that is administering the device to set the
1098 * minimum number of upper case letters required in the password. After
1099 * setting this, the user will not be able to enter a new password that is
1100 * not at least as restrictive as what has been set. Note that the current
1101 * password will remain until the user has set a new one, so the change does
1102 * not take place immediately. To prompt the user for a new password, use
1103 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1104 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001105 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1106 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001107 * <p>
1108 * The calling device admin must have requested
1109 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1110 * this method; if it has not, a security exception will be thrown.
1111 *
1112 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1113 * with.
1114 * @param length The new desired minimum number of upper case letters
1115 * required in the password. A value of 0 means there is no
1116 * restriction.
1117 */
Robin Lee25e26452015-06-02 09:56:29 -07001118 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001119 if (mService != null) {
1120 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001121 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001122 } catch (RemoteException e) {
1123 Log.w(TAG, "Failed talking with device policy service", e);
1124 }
1125 }
1126 }
1127
1128 /**
1129 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001130 * password for all admins of this user and its profiles or a particular one.
1131 * This is the same value as set by
1132 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001133 * and only applies when the password quality is
1134 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001135 *
Robin Lee25e26452015-06-02 09:56:29 -07001136 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001137 * aggregate all admins.
1138 * @return The minimum number of upper case letters required in the
1139 * password.
1140 */
Robin Lee25e26452015-06-02 09:56:29 -07001141 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001142 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001143 }
1144
1145 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001146 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001147 if (mService != null) {
1148 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001149 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001150 } catch (RemoteException e) {
1151 Log.w(TAG, "Failed talking with device policy service", e);
1152 }
1153 }
1154 return 0;
1155 }
1156
1157 /**
1158 * Called by an application that is administering the device to set the
1159 * minimum number of lower case letters required in the password. After
1160 * setting this, the user will not be able to enter a new password that is
1161 * not at least as restrictive as what has been set. Note that the current
1162 * password will remain until the user has set a new one, so the change does
1163 * not take place immediately. To prompt the user for a new password, use
1164 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1165 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001166 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1167 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001168 * <p>
1169 * The calling device admin must have requested
1170 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1171 * this method; if it has not, a security exception will be thrown.
1172 *
1173 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1174 * with.
1175 * @param length The new desired minimum number of lower case letters
1176 * required in the password. A value of 0 means there is no
1177 * restriction.
1178 */
Robin Lee25e26452015-06-02 09:56:29 -07001179 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001180 if (mService != null) {
1181 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001182 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001183 } catch (RemoteException e) {
1184 Log.w(TAG, "Failed talking with device policy service", e);
1185 }
1186 }
1187 }
1188
1189 /**
1190 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001191 * password for all admins of this user and its profiles or a particular one.
1192 * This is the same value as set by
1193 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001194 * and only applies when the password quality is
1195 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001196 *
Robin Lee25e26452015-06-02 09:56:29 -07001197 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001198 * aggregate all admins.
1199 * @return The minimum number of lower case letters required in the
1200 * password.
1201 */
Robin Lee25e26452015-06-02 09:56:29 -07001202 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001203 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001204 }
1205
1206 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001207 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001208 if (mService != null) {
1209 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001210 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001211 } catch (RemoteException e) {
1212 Log.w(TAG, "Failed talking with device policy service", e);
1213 }
1214 }
1215 return 0;
1216 }
1217
1218 /**
1219 * Called by an application that is administering the device to set the
1220 * minimum number of letters required in the password. After setting this,
1221 * the user will not be able to enter a new password that is not at least as
1222 * restrictive as what has been set. Note that the current password will
1223 * remain until the user has set a new one, so the change does not take
1224 * place immediately. To prompt the user for a new password, use
1225 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1226 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001227 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1228 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001229 * <p>
1230 * The calling device admin must have requested
1231 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1232 * this method; if it has not, a security exception will be thrown.
1233 *
1234 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1235 * with.
1236 * @param length The new desired minimum number of letters required in the
1237 * password. A value of 0 means there is no restriction.
1238 */
Robin Lee25e26452015-06-02 09:56:29 -07001239 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001240 if (mService != null) {
1241 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001242 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001243 } catch (RemoteException e) {
1244 Log.w(TAG, "Failed talking with device policy service", e);
1245 }
1246 }
1247 }
1248
1249 /**
1250 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001251 * admins or a particular one. This is the same value as
1252 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1253 * and only applies when the password quality is
1254 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001255 *
Robin Lee25e26452015-06-02 09:56:29 -07001256 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001257 * aggregate all admins.
1258 * @return The minimum number of letters required in the password.
1259 */
Robin Lee25e26452015-06-02 09:56:29 -07001260 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001261 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001262 }
1263
1264 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001265 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001266 if (mService != null) {
1267 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001268 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001269 } catch (RemoteException e) {
1270 Log.w(TAG, "Failed talking with device policy service", e);
1271 }
1272 }
1273 return 0;
1274 }
1275
1276 /**
1277 * Called by an application that is administering the device to set the
1278 * minimum number of numerical digits required in the password. After
1279 * setting this, the user will not be able to enter a new password that is
1280 * not at least as restrictive as what has been set. Note that the current
1281 * password will remain until the user has set a new one, so the change does
1282 * not take place immediately. To prompt the user for a new password, use
1283 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1284 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001285 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1286 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001287 * <p>
1288 * The calling device admin must have requested
1289 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1290 * this method; if it has not, a security exception will be thrown.
1291 *
1292 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1293 * with.
1294 * @param length The new desired minimum number of numerical digits required
1295 * in the password. A value of 0 means there is no restriction.
1296 */
Robin Lee25e26452015-06-02 09:56:29 -07001297 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001298 if (mService != null) {
1299 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001300 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001301 } catch (RemoteException e) {
1302 Log.w(TAG, "Failed talking with device policy service", e);
1303 }
1304 }
1305 }
1306
1307 /**
1308 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001309 * for all admins of this user and its profiles or a particular one.
1310 * This is the same value as set by
1311 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001312 * and only applies when the password quality is
1313 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001314 *
Robin Lee25e26452015-06-02 09:56:29 -07001315 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001316 * aggregate all admins.
1317 * @return The minimum number of numerical digits required in the password.
1318 */
Robin Lee25e26452015-06-02 09:56:29 -07001319 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001320 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001321 }
1322
1323 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001324 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 if (mService != null) {
1326 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001327 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001328 } catch (RemoteException e) {
1329 Log.w(TAG, "Failed talking with device policy service", e);
1330 }
1331 }
1332 return 0;
1333 }
1334
1335 /**
1336 * Called by an application that is administering the device to set the
1337 * minimum number of symbols required in the password. After setting this,
1338 * the user will not be able to enter a new password that is not at least as
1339 * restrictive as what has been set. Note that the current password will
1340 * remain until the user has set a new one, so the change does not take
1341 * place immediately. To prompt the user for a new password, use
1342 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1343 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001344 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1345 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001346 * <p>
1347 * The calling device admin must have requested
1348 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1349 * this method; if it has not, a security exception will be thrown.
1350 *
1351 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1352 * with.
1353 * @param length The new desired minimum number of symbols required in the
1354 * password. A value of 0 means there is no restriction.
1355 */
Robin Lee25e26452015-06-02 09:56:29 -07001356 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001357 if (mService != null) {
1358 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001359 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001360 } catch (RemoteException e) {
1361 Log.w(TAG, "Failed talking with device policy service", e);
1362 }
1363 }
1364 }
1365
1366 /**
1367 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001368 * admins or a particular one. This is the same value as
1369 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1370 * and only applies when the password quality is
1371 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001372 *
Robin Lee25e26452015-06-02 09:56:29 -07001373 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001374 * aggregate all admins.
1375 * @return The minimum number of symbols required in the password.
1376 */
Robin Lee25e26452015-06-02 09:56:29 -07001377 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001378 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001379 }
1380
1381 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001382 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001383 if (mService != null) {
1384 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001385 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001386 } catch (RemoteException e) {
1387 Log.w(TAG, "Failed talking with device policy service", e);
1388 }
1389 }
1390 return 0;
1391 }
1392
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001393 /**
1394 * Called by an application that is administering the device to set the
1395 * minimum number of non-letter characters (numerical digits or symbols)
1396 * required in the password. After setting this, the user will not be able
1397 * to enter a new password that is not at least as restrictive as what has
1398 * been set. Note that the current password will remain until the user has
1399 * set a new one, so the change does not take place immediately. To prompt
1400 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1401 * setting this value. This constraint is only imposed if the administrator
1402 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1403 * {@link #setPasswordQuality}. The default value is 0.
1404 * <p>
1405 * The calling device admin must have requested
1406 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1407 * this method; if it has not, a security exception will be thrown.
1408 *
1409 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1410 * with.
1411 * @param length The new desired minimum number of letters required in the
1412 * password. A value of 0 means there is no restriction.
1413 */
Robin Lee25e26452015-06-02 09:56:29 -07001414 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001415 if (mService != null) {
1416 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001417 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001418 } catch (RemoteException e) {
1419 Log.w(TAG, "Failed talking with device policy service", e);
1420 }
1421 }
1422 }
1423
1424 /**
1425 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001426 * password for all admins of this user and its profiles or a particular one.
1427 * This is the same value as set by
1428 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001429 * and only applies when the password quality is
1430 * {@link #PASSWORD_QUALITY_COMPLEX}.
1431 *
Robin Lee25e26452015-06-02 09:56:29 -07001432 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001433 * aggregate all admins.
1434 * @return The minimum number of letters required in the password.
1435 */
Robin Lee25e26452015-06-02 09:56:29 -07001436 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001437 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001438 }
1439
1440 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001441 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001442 if (mService != null) {
1443 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001444 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001445 } catch (RemoteException e) {
1446 Log.w(TAG, "Failed talking with device policy service", e);
1447 }
1448 }
1449 return 0;
1450 }
1451
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001452 /**
1453 * Called by an application that is administering the device to set the length
1454 * of the password history. After setting this, the user will not be able to
1455 * enter a new password that is the same as any password in the history. Note
1456 * that the current password will remain until the user has set a new one, so
1457 * the change does not take place immediately. To prompt the user for a new
1458 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1459 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001460 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1461 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1462 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001463 *
1464 * <p>
1465 * The calling device admin must have requested
1466 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1467 * method; if it has not, a security exception will be thrown.
1468 *
1469 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1470 * with.
1471 * @param length The new desired length of password history. A value of 0
1472 * means there is no restriction.
1473 */
Robin Lee25e26452015-06-02 09:56:29 -07001474 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001475 if (mService != null) {
1476 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001477 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001478 } catch (RemoteException e) {
1479 Log.w(TAG, "Failed talking with device policy service", e);
1480 }
1481 }
1482 }
1483
1484 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001485 * Called by a device admin to set the password expiration timeout. Calling this method
1486 * will restart the countdown for password expiration for the given admin, as will changing
1487 * the device password (for all admins).
1488 *
1489 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1490 * For example, to have the password expire 5 days from now, timeout would be
1491 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1492 *
1493 * <p>To disable password expiration, a value of 0 may be used for timeout.
1494 *
Jim Millera4e28d12010-11-08 16:15:47 -08001495 * <p>The calling device admin must have requested
1496 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1497 * method; if it has not, a security exception will be thrown.
1498 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001499 * <p> Note that setting the password will automatically reset the expiration time for all
1500 * active admins. Active admins do not need to explicitly call this method in that case.
1501 *
Jim Millera4e28d12010-11-08 16:15:47 -08001502 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1503 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1504 * means there is no restriction (unlimited).
1505 */
Robin Lee25e26452015-06-02 09:56:29 -07001506 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001507 if (mService != null) {
1508 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001509 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001510 } catch (RemoteException e) {
1511 Log.w(TAG, "Failed talking with device policy service", e);
1512 }
1513 }
1514 }
1515
1516 /**
Jim Miller6b857682011-02-16 16:27:41 -08001517 * Get the password expiration timeout for the given admin. The expiration timeout is the
1518 * recurring expiration timeout provided in the call to
1519 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001520 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001521 *
Robin Lee25e26452015-06-02 09:56:29 -07001522 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001523 * @return The timeout for the given admin or the minimum of all timeouts
1524 */
Robin Lee25e26452015-06-02 09:56:29 -07001525 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001526 if (mService != null) {
1527 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001528 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001529 } catch (RemoteException e) {
1530 Log.w(TAG, "Failed talking with device policy service", e);
1531 }
1532 }
1533 return 0;
1534 }
1535
1536 /**
1537 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001538 * all admins of this user and its profiles if admin is null. If the password is
1539 * expired, this will return the time since the password expired as a negative number.
1540 * If admin is null, then a composite of all expiration timeouts is returned
1541 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001542 *
Robin Lee25e26452015-06-02 09:56:29 -07001543 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001544 * @return The password expiration time, in ms.
1545 */
Robin Lee25e26452015-06-02 09:56:29 -07001546 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001547 if (mService != null) {
1548 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001549 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001550 } catch (RemoteException e) {
1551 Log.w(TAG, "Failed talking with device policy service", e);
1552 }
1553 }
1554 return 0;
1555 }
1556
1557 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001558 * Retrieve the current password history length for all admins of this
1559 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001560 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001561 * all admins.
1562 * @return The length of the password history
1563 */
Robin Lee25e26452015-06-02 09:56:29 -07001564 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001565 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001566 }
1567
1568 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001569 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001570 if (mService != null) {
1571 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001572 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001573 } catch (RemoteException e) {
1574 Log.w(TAG, "Failed talking with device policy service", e);
1575 }
1576 }
1577 return 0;
1578 }
1579
Dianne Hackbornd6847842010-01-12 18:14:19 -08001580 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001581 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001582 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001583 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001584 * @return Returns the maximum length that the user can enter.
1585 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001586 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001587 // Kind-of arbitrary.
1588 return 16;
1589 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001590
Dianne Hackborn254cb442010-01-27 19:23:59 -08001591 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001592 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001593 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001594 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001595 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001596 * <p>The calling device admin must have requested
1597 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1598 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001599 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001600 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001601 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001602 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001603 if (mService != null) {
1604 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001605 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001606 } catch (RemoteException e) {
1607 Log.w(TAG, "Failed talking with device policy service", e);
1608 }
1609 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001610 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001611 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001612
Dianne Hackbornd6847842010-01-12 18:14:19 -08001613 /**
1614 * Retrieve the number of times the user has failed at entering a
1615 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001616 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001617 * <p>The calling device admin must have requested
1618 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1619 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 */
1621 public int getCurrentFailedPasswordAttempts() {
1622 if (mService != null) {
1623 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001624 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001625 } catch (RemoteException e) {
1626 Log.w(TAG, "Failed talking with device policy service", e);
1627 }
1628 }
1629 return -1;
1630 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001631
1632 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001633 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001634 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001635 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001636 * @hide
1637 */
1638 public boolean getDoNotAskCredentialsOnBoot() {
1639 if (mService != null) {
1640 try {
1641 return mService.getDoNotAskCredentialsOnBoot();
1642 } catch (RemoteException e) {
1643 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1644 }
1645 }
1646 return false;
1647 }
1648
1649 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001650 * Setting this to a value greater than zero enables a built-in policy
1651 * that will perform a device wipe after too many incorrect
1652 * device-unlock passwords have been entered. This built-in policy combines
1653 * watching for failed passwords and wiping the device, and requires
1654 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001655 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001656 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001657 * <p>To implement any other policy (e.g. wiping data for a particular
1658 * application only, erasing or revoking credentials, or reporting the
1659 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001660 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001661 * instead. Do not use this API, because if the maximum count is reached,
1662 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001663 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001665 * @param num The number of failed password attempts at which point the
1666 * device will wipe its data.
1667 */
Robin Lee25e26452015-06-02 09:56:29 -07001668 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001669 if (mService != null) {
1670 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001671 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001672 } catch (RemoteException e) {
1673 Log.w(TAG, "Failed talking with device policy service", e);
1674 }
1675 }
1676 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001677
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001678 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001679 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001680 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001681 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001682 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001683 * all admins.
1684 */
Robin Lee25e26452015-06-02 09:56:29 -07001685 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001686 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001687 }
1688
1689 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001690 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001691 if (mService != null) {
1692 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001693 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001694 } catch (RemoteException e) {
1695 Log.w(TAG, "Failed talking with device policy service", e);
1696 }
1697 }
1698 return 0;
1699 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001700
Dianne Hackborn254cb442010-01-27 19:23:59 -08001701 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001702 * Returns the profile with the smallest maximum failed passwords for wipe,
1703 * for the given user. So for primary user, it might return the primary or
1704 * a managed profile. For a secondary user, it would be the same as the
1705 * user passed in.
1706 * @hide Used only by Keyguard
1707 */
1708 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1709 if (mService != null) {
1710 try {
1711 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1712 } catch (RemoteException e) {
1713 Log.w(TAG, "Failed talking with device policy service", e);
1714 }
1715 }
1716 return UserHandle.USER_NULL;
1717 }
1718
1719 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001720 * Flag for {@link #resetPassword}: don't allow other admins to change
1721 * the password again until the user has entered it.
1722 */
1723 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001724
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001725 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001726 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1727 * If the flag is set, the device can be booted without asking for user password.
1728 * The absence of this flag does not change the current boot requirements. This flag
1729 * can be set by the device owner only. If the app is not the device owner, the flag
1730 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1731 * device to factory defaults.
1732 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001733 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001734
1735 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001736 * Force a new device unlock password (the password needed to access the
1737 * entire device, not for individual accounts) on the user. This takes
1738 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001739 *
1740 * <p>Calling this from a managed profile that shares the password with the owner profile
1741 * will throw a security exception.
1742 *
1743 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1744 * device admins that are not device owner and not profile owner.
1745 * The password can now only be changed if there is currently no password set. Device owner
1746 * and profile owner can still do this.</em>
1747 *
1748 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001749 * current password quality and length constraints as returned by
1750 * {@link #getPasswordQuality(ComponentName)} and
1751 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1752 * these constraints, then it will be rejected and false returned. Note
1753 * that the password may be a stronger quality (containing alphanumeric
1754 * characters when the requested quality is only numeric), in which case
1755 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001757 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001758 * pattern or password if the current password constraints allow it. <em>Note: This will not
1759 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1760 * device owner and not profile owner. Once set, the password cannot be changed to null or
1761 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001762 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001763 * <p>The calling device admin must have requested
1764 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1765 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001766 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001767 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001768 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001769 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001770 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001771 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001772 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001773 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001774 if (mService != null) {
1775 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001776 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001777 } catch (RemoteException e) {
1778 Log.w(TAG, "Failed talking with device policy service", e);
1779 }
1780 }
1781 return false;
1782 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001783
Dianne Hackbornd6847842010-01-12 18:14:19 -08001784 /**
1785 * Called by an application that is administering the device to set the
1786 * maximum time for user activity until the device will lock. This limits
1787 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001788 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001789 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001790 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001791 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001792 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001793 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001794 * @param timeMs The new desired maximum time to lock in milliseconds.
1795 * A value of 0 means there is no restriction.
1796 */
Robin Lee25e26452015-06-02 09:56:29 -07001797 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001798 if (mService != null) {
1799 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001800 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 } catch (RemoteException e) {
1802 Log.w(TAG, "Failed talking with device policy service", e);
1803 }
1804 }
1805 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001806
Dianne Hackbornd6847842010-01-12 18:14:19 -08001807 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001808 * Retrieve the current maximum time to unlock for all admins of this user
1809 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001810 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001811 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001812 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001813 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001814 */
Robin Lee25e26452015-06-02 09:56:29 -07001815 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001816 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001817 }
1818
1819 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001820 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 if (mService != null) {
1822 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001823 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 } catch (RemoteException e) {
1825 Log.w(TAG, "Failed talking with device policy service", e);
1826 }
1827 }
1828 return 0;
1829 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001830
Dianne Hackbornd6847842010-01-12 18:14:19 -08001831 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001832 * Make the device lock immediately, as if the lock screen timeout has
1833 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001834 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001835 * <p>The calling device admin must have requested
1836 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1837 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001838 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001839 public void lockNow() {
1840 if (mService != null) {
1841 try {
1842 mService.lockNow();
1843 } catch (RemoteException e) {
1844 Log.w(TAG, "Failed talking with device policy service", e);
1845 }
1846 }
1847 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001848
Dianne Hackbornd6847842010-01-12 18:14:19 -08001849 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001850 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001851 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001852 */
1853 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1854
1855 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001856 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1857 * data.
1858 *
Paul Crowley2934b262014-12-02 11:21:13 +00001859 * <p>This flag may only be set by device owner admins; if it is set by
1860 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001861 */
1862 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1863
1864 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001865 * Ask the user data be wiped. Wiping the primary user will cause the
1866 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001867 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001868 * <p>The calling device admin must have requested
1869 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1870 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001871 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001872 * @param flags Bit mask of additional options: currently supported flags
1873 * are {@link #WIPE_EXTERNAL_STORAGE} and
1874 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001875 */
1876 public void wipeData(int flags) {
1877 if (mService != null) {
1878 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001879 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001880 } catch (RemoteException e) {
1881 Log.w(TAG, "Failed talking with device policy service", e);
1882 }
1883 }
1884 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001885
Dianne Hackbornd6847842010-01-12 18:14:19 -08001886 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001887 * Called by an application that is administering the device to set the
1888 * global proxy and exclusion list.
1889 * <p>
1890 * The calling device admin must have requested
1891 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1892 * this method; if it has not, a security exception will be thrown.
1893 * Only the first device admin can set the proxy. If a second admin attempts
1894 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001895 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001896 * be returned.
1897 * The method can be called repeatedly by the device admin alrady setting the
1898 * proxy to update the proxy and exclusion list.
1899 *
Robin Lee25e26452015-06-02 09:56:29 -07001900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001901 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1902 * Pass Proxy.NO_PROXY to reset the proxy.
1903 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001904 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1905 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001906 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001907 */
Robin Lee25e26452015-06-02 09:56:29 -07001908 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001909 List<String> exclusionList ) {
1910 if (proxySpec == null) {
1911 throw new NullPointerException();
1912 }
1913 if (mService != null) {
1914 try {
1915 String hostSpec;
1916 String exclSpec;
1917 if (proxySpec.equals(Proxy.NO_PROXY)) {
1918 hostSpec = null;
1919 exclSpec = null;
1920 } else {
1921 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1922 throw new IllegalArgumentException();
1923 }
1924 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1925 String hostName = sa.getHostName();
1926 int port = sa.getPort();
1927 StringBuilder hostBuilder = new StringBuilder();
1928 hostSpec = hostBuilder.append(hostName)
1929 .append(":").append(Integer.toString(port)).toString();
1930 if (exclusionList == null) {
1931 exclSpec = "";
1932 } else {
1933 StringBuilder listBuilder = new StringBuilder();
1934 boolean firstDomain = true;
1935 for (String exclDomain : exclusionList) {
1936 if (!firstDomain) {
1937 listBuilder = listBuilder.append(",");
1938 } else {
1939 firstDomain = false;
1940 }
1941 listBuilder = listBuilder.append(exclDomain.trim());
1942 }
1943 exclSpec = listBuilder.toString();
1944 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001945 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1946 != android.net.Proxy.PROXY_VALID)
1947 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001948 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001949 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001950 } catch (RemoteException e) {
1951 Log.w(TAG, "Failed talking with device policy service", e);
1952 }
1953 }
1954 return null;
1955 }
1956
1957 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001958 * Set a network-independent global HTTP proxy. This is not normally what you want
1959 * for typical HTTP proxies - they are generally network dependent. However if you're
1960 * doing something unusual like general internal filtering this may be useful. On
1961 * a private network where the proxy is not accessible, you may break HTTP using this.
1962 *
1963 * <p>This method requires the caller to be the device owner.
1964 *
1965 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1966 * @see ProxyInfo
1967 *
1968 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1969 * with.
1970 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1971 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1972 */
Robin Lee25e26452015-06-02 09:56:29 -07001973 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1974 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001975 if (mService != null) {
1976 try {
1977 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1978 } catch (RemoteException e) {
1979 Log.w(TAG, "Failed talking with device policy service", e);
1980 }
1981 }
1982 }
1983
1984 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001985 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001986 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
1987 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001988 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001989 */
1990 public ComponentName getGlobalProxyAdmin() {
1991 if (mService != null) {
1992 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001993 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07001994 } catch (RemoteException e) {
1995 Log.w(TAG, "Failed talking with device policy service", e);
1996 }
1997 }
1998 return null;
1999 }
2000
2001 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002002 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002003 * indicating that encryption is not supported.
2004 */
2005 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2006
2007 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002008 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002009 * indicating that encryption is supported, but is not currently active.
2010 */
2011 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2012
2013 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002014 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002015 * indicating that encryption is not currently active, but is currently
2016 * being activated. This is only reported by devices that support
2017 * encryption of data and only when the storage is currently
2018 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2019 * to become encrypted will never return this value.
2020 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002021 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002022
2023 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002024 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002025 * indicating that encryption is active.
2026 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002027 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002028
2029 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002030 * Result code for {@link #getStorageEncryptionStatus}:
2031 * indicating that encryption is active, but an encryption key has not
2032 * been set by the user.
2033 */
2034 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2035
2036 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002037 * Activity action: begin the process of encrypting data on the device. This activity should
2038 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2039 * After resuming from this activity, use {@link #getStorageEncryption}
2040 * to check encryption status. However, on some devices this activity may never return, as
2041 * it may trigger a reboot and in some cases a complete data wipe of the device.
2042 */
2043 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2044 public static final String ACTION_START_ENCRYPTION
2045 = "android.app.action.START_ENCRYPTION";
2046
2047 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002048 * Widgets are enabled in keyguard
2049 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002050 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002051
2052 /**
Jim Miller50e62182014-04-23 17:25:00 -07002053 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002054 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002055 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2056
2057 /**
2058 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2059 */
2060 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2061
2062 /**
Jim Miller50e62182014-04-23 17:25:00 -07002063 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2064 */
2065 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2066
2067 /**
2068 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2069 */
2070 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2071
2072 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002073 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002074 * (e.g. PIN/Pattern/Password).
2075 */
2076 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2077
2078 /**
Jim Miller06e34502014-07-17 14:46:05 -07002079 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2080 */
2081 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2082
2083 /**
Jim Miller35207742012-11-02 15:33:20 -07002084 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002085 */
2086 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002087
2088 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002089 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002090 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002091 *
2092 * <p>When multiple device administrators attempt to control device
2093 * encryption, the most secure, supported setting will always be
2094 * used. If any device administrator requests device encryption,
2095 * it will be enabled; Conversely, if a device administrator
2096 * attempts to disable device encryption while another
2097 * device administrator has enabled it, the call to disable will
2098 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2099 *
2100 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002101 * written to other storage areas may or may not be encrypted, and this policy does not require
2102 * or control the encryption of any other storage areas.
2103 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2104 * {@code true}, then the directory returned by
2105 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2106 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002107 *
2108 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2109 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2110 * the encryption key may not be fully secured. For maximum security, the administrator should
2111 * also require (and check for) a pattern, PIN, or password.
2112 *
2113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2114 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002115 * @return the new request status (for all active admins) - will be one of
2116 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2117 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2118 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002119 */
Robin Lee25e26452015-06-02 09:56:29 -07002120 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002121 if (mService != null) {
2122 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002123 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002124 } catch (RemoteException e) {
2125 Log.w(TAG, "Failed talking with device policy service", e);
2126 }
2127 }
2128 return ENCRYPTION_STATUS_UNSUPPORTED;
2129 }
2130
2131 /**
2132 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002133 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002134 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002135 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2136 * this will return the requested encryption setting as an aggregate of all active
2137 * administrators.
2138 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002139 */
Robin Lee25e26452015-06-02 09:56:29 -07002140 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002141 if (mService != null) {
2142 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002143 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002144 } catch (RemoteException e) {
2145 Log.w(TAG, "Failed talking with device policy service", e);
2146 }
2147 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002148 return false;
2149 }
2150
2151 /**
2152 * Called by an application that is administering the device to
2153 * determine the current encryption status of the device.
2154 *
2155 * Depending on the returned status code, the caller may proceed in different
2156 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2157 * storage system does not support encryption. If the
2158 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2159 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002160 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2161 * storage system has enabled encryption but no password is set so further action
2162 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002163 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2164 *
Robin Lee7e678712014-07-24 16:41:31 +01002165 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002166 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002167 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2168 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002169 */
2170 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002171 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002172 }
2173
2174 /** @hide per-user version */
2175 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002176 if (mService != null) {
2177 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002178 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002179 } catch (RemoteException e) {
2180 Log.w(TAG, "Failed talking with device policy service", e);
2181 }
2182 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002183 return ENCRYPTION_STATUS_UNSUPPORTED;
2184 }
2185
2186 /**
Robin Lee7e678712014-07-24 16:41:31 +01002187 * Installs the given certificate as a user CA.
2188 *
Robin Lee25e26452015-06-02 09:56:29 -07002189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2190 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002191 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002192 *
2193 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002194 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002195 */
Robin Lee25e26452015-06-02 09:56:29 -07002196 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002197 if (mService != null) {
2198 try {
Robin Lee7e678712014-07-24 16:41:31 +01002199 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002200 } catch (RemoteException e) {
2201 Log.w(TAG, "Failed talking with device policy service", e);
2202 }
2203 }
2204 return false;
2205 }
2206
2207 /**
Robin Lee7e678712014-07-24 16:41:31 +01002208 * Uninstalls the given certificate from trusted user CAs, if present.
2209 *
Robin Lee25e26452015-06-02 09:56:29 -07002210 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2211 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002212 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002213 */
Robin Lee25e26452015-06-02 09:56:29 -07002214 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002215 if (mService != null) {
2216 try {
Robin Lee306fe082014-06-19 14:04:24 +00002217 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002218 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002219 } catch (CertificateException e) {
2220 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002221 } catch (RemoteException e) {
2222 Log.w(TAG, "Failed talking with device policy service", e);
2223 }
2224 }
2225 }
2226
2227 /**
Robin Lee7e678712014-07-24 16:41:31 +01002228 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2229 * If a user has installed any certificates by other means than device policy these will be
2230 * included too.
2231 *
Robin Lee25e26452015-06-02 09:56:29 -07002232 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2233 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002234 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002235 */
Robin Lee25e26452015-06-02 09:56:29 -07002236 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002237 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002238 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002239 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002240 mService.enforceCanManageCaCerts(admin);
2241 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2242 for (String alias : certStore.userAliases()) {
2243 try {
2244 certs.add(certStore.getCertificate(alias).getEncoded());
2245 } catch (CertificateException ce) {
2246 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2247 }
2248 }
2249 } catch (RemoteException re) {
2250 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002251 }
2252 }
2253 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002254 }
2255
2256 /**
Robin Lee7e678712014-07-24 16:41:31 +01002257 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2258 * means other than device policy will also be removed, except for system CA certificates.
2259 *
Robin Lee25e26452015-06-02 09:56:29 -07002260 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2261 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002262 */
Robin Lee25e26452015-06-02 09:56:29 -07002263 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002264 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002265 try {
2266 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2267 .toArray(new String[0]));
2268 } catch (RemoteException re) {
2269 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002270 }
2271 }
2272 }
2273
2274 /**
2275 * Returns whether this certificate is installed as a trusted CA.
2276 *
Robin Lee25e26452015-06-02 09:56:29 -07002277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2278 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002279 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002280 */
Robin Lee25e26452015-06-02 09:56:29 -07002281 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002282 if (mService != null) {
2283 try {
2284 mService.enforceCanManageCaCerts(admin);
2285 return getCaCertAlias(certBuffer) != null;
2286 } catch (RemoteException re) {
2287 Log.w(TAG, "Failed talking with device policy service", re);
2288 } catch (CertificateException ce) {
2289 Log.w(TAG, "Could not parse certificate", ce);
2290 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002291 }
2292 return false;
2293 }
2294
2295 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002296 * Called by a device or profile owner to install a certificate and private key pair. The
2297 * keypair will be visible to all apps within the profile.
2298 *
Robin Lee25e26452015-06-02 09:56:29 -07002299 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2300 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002301 * @param privKey The private key to install.
2302 * @param cert The certificate to install.
2303 * @param alias The private key alias under which to install the certificate. If a certificate
2304 * with that alias already exists, it will be overwritten.
2305 * @return {@code true} if the keys were installed, {@code false} otherwise.
2306 */
Robin Lee25e26452015-06-02 09:56:29 -07002307 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002308 String alias) {
2309 try {
2310 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002311 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2312 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002313 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002314 } catch (RemoteException e) {
2315 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002316 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2317 Log.w(TAG, "Failed to obtain private key material", e);
2318 } catch (CertificateException | IOException e) {
2319 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002320 }
2321 return false;
2322 }
2323
2324 /**
Robin Lee25e26452015-06-02 09:56:29 -07002325 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002326 * doesn't exist.
2327 */
2328 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2329 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2330 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2331 new ByteArrayInputStream(certBuffer));
2332 return new TrustedCertificateStore().getCertificateAlias(cert);
2333 }
2334
2335 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002336 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002337 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002338 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002339 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002340 * <p>
2341 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2342 * it is later cleared by calling this method with a null value or uninstallling the certificate
2343 * installer.
2344 *
Robin Lee25e26452015-06-02 09:56:29 -07002345 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002346 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002347 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002348 */
Robin Lee25e26452015-06-02 09:56:29 -07002349 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2350 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002351 if (mService != null) {
2352 try {
Robin Lee25e26452015-06-02 09:56:29 -07002353 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002354 } catch (RemoteException e) {
2355 Log.w(TAG, "Failed talking with device policy service", e);
2356 }
2357 }
2358 }
2359
2360 /**
2361 * Called by a profile owner or device owner to retrieve the certificate installer for the
2362 * current user. null if none is set.
2363 *
Robin Lee25e26452015-06-02 09:56:29 -07002364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2365 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002366 * if none is set.
2367 */
Robin Lee25e26452015-06-02 09:56:29 -07002368 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002369 if (mService != null) {
2370 try {
Robin Lee25e26452015-06-02 09:56:29 -07002371 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002372 } catch (RemoteException e) {
2373 Log.w(TAG, "Failed talking with device policy service", e);
2374 }
2375 }
2376 return null;
2377 }
2378
2379 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002380 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002381 * on the device, for this user. After setting this, no applications running as this user
2382 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002383 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002384 * <p>If the caller is device owner, then the restriction will be applied to all users.
2385 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002386 * <p>The calling device admin must have requested
2387 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2388 * this method; if it has not, a security exception will be thrown.
2389 *
2390 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2391 * @param disabled Whether or not the camera should be disabled.
2392 */
Robin Lee25e26452015-06-02 09:56:29 -07002393 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002394 if (mService != null) {
2395 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002396 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002397 } catch (RemoteException e) {
2398 Log.w(TAG, "Failed talking with device policy service", e);
2399 }
2400 }
2401 }
2402
2403 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002404 * Determine whether or not the device's cameras have been disabled for this user,
2405 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002406 * @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 -07002407 * have disabled the camera
2408 */
Robin Lee25e26452015-06-02 09:56:29 -07002409 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002410 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002411 }
2412
2413 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002414 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002415 if (mService != null) {
2416 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002417 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002418 } catch (RemoteException e) {
2419 Log.w(TAG, "Failed talking with device policy service", e);
2420 }
2421 }
2422 return false;
2423 }
2424
2425 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002426 * Determine whether or not creating a guest user has been disabled for the device
2427 *
2428 * @hide
2429 */
2430 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2431 // Currently guest users can always be created if multi-user is enabled
2432 // TODO introduce a policy for guest user creation
2433 return false;
2434 }
2435
2436 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002437 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2438 * screen capture also prevents the content from being shown on display devices that do not have
2439 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2440 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002441 *
2442 * <p>The calling device admin must be a device or profile owner. If it is not, a
2443 * security exception will be thrown.
2444 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002445 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002446 * blocks assist requests for all activities of the relevant user.
2447 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002448 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002449 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002450 */
Robin Lee25e26452015-06-02 09:56:29 -07002451 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002452 if (mService != null) {
2453 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002454 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002455 } catch (RemoteException e) {
2456 Log.w(TAG, "Failed talking with device policy service", e);
2457 }
2458 }
2459 }
2460
2461 /**
2462 * Determine whether or not screen capture has been disabled by the current
2463 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002464 * @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 +01002465 * have disabled screen capture.
2466 */
Robin Lee25e26452015-06-02 09:56:29 -07002467 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002468 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002469 }
2470
2471 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002472 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002473 if (mService != null) {
2474 try {
2475 return mService.getScreenCaptureDisabled(admin, userHandle);
2476 } catch (RemoteException e) {
2477 Log.w(TAG, "Failed talking with device policy service", e);
2478 }
2479 }
2480 return false;
2481 }
2482
2483 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002484 * Called by a device owner to set whether auto time is required. If auto time is
2485 * required the user cannot set the date and time, but has to use network date and time.
2486 *
2487 * <p>Note: if auto time is required the user can still manually set the time zone.
2488 *
2489 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2490 * be thrown.
2491 *
2492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2493 * @param required Whether auto time is set required or not.
2494 */
Robin Lee25e26452015-06-02 09:56:29 -07002495 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002496 if (mService != null) {
2497 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002498 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002499 } catch (RemoteException e) {
2500 Log.w(TAG, "Failed talking with device policy service", e);
2501 }
2502 }
2503 }
2504
2505 /**
2506 * @return true if auto time is required.
2507 */
2508 public boolean getAutoTimeRequired() {
2509 if (mService != null) {
2510 try {
2511 return mService.getAutoTimeRequired();
2512 } catch (RemoteException e) {
2513 Log.w(TAG, "Failed talking with device policy service", e);
2514 }
2515 }
2516 return false;
2517 }
2518
2519 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002520 * Called by an application that is administering the device to disable keyguard customizations,
2521 * such as widgets. After setting this, keyguard features will be disabled according to the
2522 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002523 *
2524 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002525 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002526 * this method; if it has not, a security exception will be thrown.
2527 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002528 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002529 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002530 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002531 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002532 * <ul>
2533 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2534 * these will affect the profile's parent user.
2535 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2536 * generated by applications in the managed profile.
2537 * </ul>
2538 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2539 * can check which features have been disabled by calling
2540 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002541 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002542 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002543 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2544 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002545 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002546 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2547 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002548 */
Robin Lee25e26452015-06-02 09:56:29 -07002549 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002550 if (mService != null) {
2551 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002552 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002553 } catch (RemoteException e) {
2554 Log.w(TAG, "Failed talking with device policy service", e);
2555 }
2556 }
2557 }
2558
2559 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002560 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002561 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002562 * @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 -07002563 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002564 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2565 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002566 */
Robin Lee25e26452015-06-02 09:56:29 -07002567 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002568 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002569 }
2570
2571 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002572 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002573 if (mService != null) {
2574 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002575 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002576 } catch (RemoteException e) {
2577 Log.w(TAG, "Failed talking with device policy service", e);
2578 }
2579 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002580 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002581 }
2582
2583 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002584 * @hide
2585 */
Robin Lee25e26452015-06-02 09:56:29 -07002586 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2587 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002588 if (mService != null) {
2589 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002590 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002591 } catch (RemoteException e) {
2592 Log.w(TAG, "Failed talking with device policy service", e);
2593 }
2594 }
2595 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002596
Dianne Hackbornd6847842010-01-12 18:14:19 -08002597 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002598 * @hide
2599 */
Robin Lee25e26452015-06-02 09:56:29 -07002600 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002601 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002602 }
2603
2604 /**
Robin Lee25e26452015-06-02 09:56:29 -07002605 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002606 * @hide
2607 */
Robin Lee25e26452015-06-02 09:56:29 -07002608 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002609 ActivityInfo ai;
2610 try {
2611 ai = mContext.getPackageManager().getReceiverInfo(cn,
2612 PackageManager.GET_META_DATA);
2613 } catch (PackageManager.NameNotFoundException e) {
2614 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2615 return null;
2616 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002617
Dianne Hackbornd6847842010-01-12 18:14:19 -08002618 ResolveInfo ri = new ResolveInfo();
2619 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002620
Dianne Hackbornd6847842010-01-12 18:14:19 -08002621 try {
2622 return new DeviceAdminInfo(mContext, ri);
2623 } catch (XmlPullParserException e) {
2624 Log.w(TAG, "Unable to parse device policy " + cn, e);
2625 return null;
2626 } catch (IOException e) {
2627 Log.w(TAG, "Unable to parse device policy " + cn, e);
2628 return null;
2629 }
2630 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002631
Dianne Hackbornd6847842010-01-12 18:14:19 -08002632 /**
2633 * @hide
2634 */
Robin Lee25e26452015-06-02 09:56:29 -07002635 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002636 if (mService != null) {
2637 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002638 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002639 } catch (RemoteException e) {
2640 Log.w(TAG, "Failed talking with device policy service", e);
2641 }
2642 }
2643 }
2644
2645 /**
2646 * @hide
2647 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002648 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002649 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002650 if (mService != null) {
2651 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002652 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002653 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002654 } catch (RemoteException e) {
2655 Log.w(TAG, "Failed talking with device policy service", e);
2656 }
2657 }
2658 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002659
Dianne Hackbornd6847842010-01-12 18:14:19 -08002660 /**
2661 * @hide
2662 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002663 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002664 if (mService != null) {
2665 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002666 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002667 } catch (RemoteException e) {
2668 Log.w(TAG, "Failed talking with device policy service", e);
2669 }
2670 }
2671 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002672
Dianne Hackbornd6847842010-01-12 18:14:19 -08002673 /**
2674 * @hide
2675 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002676 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002677 if (mService != null) {
2678 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002679 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002680 } catch (RemoteException e) {
2681 Log.w(TAG, "Failed talking with device policy service", e);
2682 }
2683 }
2684 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002685
2686 /**
2687 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002688 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002689 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2690 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002691 * @return whether the package was successfully registered as the device owner.
2692 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002693 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002694 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002695 public boolean setDeviceOwner(ComponentName who) {
2696 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002697 }
2698
2699 /**
2700 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002701 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002702 public boolean setDeviceOwner(ComponentName who, int userId) {
2703 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002704 }
2705
2706 /**
2707 * @hide
2708 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002709 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2710 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002711 }
2712
2713 /**
2714 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002715 * Sets the given package as the device owner. The package must already be installed. There
2716 * must not already be a device owner.
2717 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2718 * this method.
2719 * Calling this after the setup phase of the primary user has completed is allowed only if
2720 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002721 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002722 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002723 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002724 * @return whether the package was successfully registered as the device owner.
2725 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002726 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002727 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002728 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002729 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002730 if (mService != null) {
2731 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002732 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002733 } catch (RemoteException re) {
2734 Log.w(TAG, "Failed to set device owner");
2735 }
2736 }
2737 return false;
2738 }
2739
2740 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002741 * Used to determine if a particular package has been registered as a Device Owner app.
2742 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002743 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002744 * package is currently registered as the device owner app, pass in the package name from
2745 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002746 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002747 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2748 * the setup process.
2749 * @param packageName the package name of the app, to compare with the registered device owner
2750 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002751 * @return whether or not the package is registered as the device owner app. Note this method
2752 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002753 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002754 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002755 if (packageName == null) {
2756 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002757 }
Makoto Onuki70f929e2015-11-11 12:40:15 -08002758 final ComponentName deviceOwner = getDeviceOwnerComponent();
2759 if (deviceOwner == null) {
2760 return false;
2761 }
2762 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002763 }
2764
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002765 /**
2766 * @hide
2767 * Redirect to isDeviceOwnerApp.
2768 */
2769 public boolean isDeviceOwner(String packageName) {
2770 return isDeviceOwnerApp(packageName);
2771 }
2772
Jason Monkb0dced82014-06-06 14:36:20 -04002773 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002774 * Check whether a given component is registered as a device owner.
2775 * Note this method does *not* check weather the device owner is actually running on the current
2776 * user.
2777 *
2778 * @hide
2779 */
2780 public boolean isDeviceOwner(ComponentName who) {
2781 return (who != null) && who.equals(getDeviceOwner());
2782 }
2783
2784 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002785 * Clears the current device owner. The caller must be the device owner.
2786 *
2787 * This function should be used cautiously as once it is called it cannot
2788 * be undone. The device owner can only be set as a part of device setup
2789 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002790 *
2791 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002792 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002793 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002794 if (mService != null) {
2795 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002796 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002797 } catch (RemoteException re) {
2798 Log.w(TAG, "Failed to clear device owner");
2799 }
2800 }
2801 }
2802
Makoto Onukia52562c2015-10-01 16:12:31 -07002803 /**
2804 * Returns the device owner package name. Note this method will still return the device owner
2805 * package name even if it's running on a different user.
2806 *
2807 * @hide
2808 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002809 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002810 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002811 final ComponentName componentName = getDeviceOwnerComponent();
2812 return componentName == null ? null : componentName.getPackageName();
2813 }
2814
2815 /**
2816 * Returns the device owner name. Note this method will still return the device owner
2817 * name even if it's running on a different user.
2818 *
2819 * @hide
2820 */
2821 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002822 if (mService != null) {
2823 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002824 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002825 } catch (RemoteException re) {
2826 Log.w(TAG, "Failed to get device owner");
2827 }
2828 }
2829 return null;
2830 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002831
Makoto Onukia52562c2015-10-01 16:12:31 -07002832 /**
2833 * Returns the device owner component name. Note this method will still return the device owner
2834 * component name even if it's running on a different user.
2835 *
2836 * @hide
2837 */
2838 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002839 if (mService != null) {
2840 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002841 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002842 } catch (RemoteException re) {
2843 Log.w(TAG, "Failed to get device owner");
2844 }
2845 }
2846 return null;
2847 }
Adam Connors776c5552014-01-09 10:42:56 +00002848
2849 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002850 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002851 * @deprecated Do not use
2852 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002853 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002854 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002855 @SystemApi
2856 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002857 return null;
2858 }
2859
2860 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002861 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002862 * @deprecated Do not use
2863 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002864 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002865 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002866 @SystemApi
2867 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002868 return null;
2869 }
2870
Julia Reynolds20118f12015-02-11 12:34:08 -05002871 /**
Adam Connors776c5552014-01-09 10:42:56 +00002872 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002873 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302874 * Sets the given component as an active admin and registers the package as the profile
2875 * owner for this user. The package must already be installed and there shouldn't be
2876 * an existing profile owner registered for this user. Also, this method must be called
2877 * before the user setup has been completed.
2878 * <p>
2879 * This method can only be called by system apps that hold MANAGE_USERS permission and
2880 * MANAGE_DEVICE_ADMINS permission.
2881 * @param admin The component to register as an active admin and profile owner.
2882 * @param ownerName The user-visible name of the entity that is managing this user.
2883 * @return whether the admin was successfully registered as the profile owner.
2884 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2885 * the user has already been set up.
2886 */
Justin Morey80440cc2014-07-24 09:16:35 -05002887 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002888 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302889 throws IllegalArgumentException {
2890 if (mService != null) {
2891 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002892 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302893 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002894 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302895 } catch (RemoteException re) {
2896 Log.w(TAG, "Failed to set profile owner " + re);
2897 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2898 }
2899 }
2900 return false;
2901 }
2902
2903 /**
2904 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002905 * Clears the active profile owner and removes all user restrictions. The caller must
2906 * be from the same package as the active profile owner for this user, otherwise a
2907 * SecurityException will be thrown.
2908 *
2909 * @param admin The component to remove as the profile owner.
2910 * @return
2911 */
2912 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002913 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002914 if (mService != null) {
2915 try {
2916 mService.clearProfileOwner(admin);
2917 } catch (RemoteException re) {
2918 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2919 }
2920 }
2921 }
2922
2923 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002924 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002925 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002926 */
2927 public boolean hasUserSetupCompleted() {
2928 if (mService != null) {
2929 try {
2930 return mService.hasUserSetupCompleted();
2931 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002932 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002933 }
2934 }
2935 return true;
2936 }
2937
2938 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002939 * @hide
2940 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002941 * already be installed. There must not already be a profile owner for this user.
2942 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2943 * this method.
2944 * Calling this after the setup phase of the specified user has completed is allowed only if:
2945 * - the caller is SYSTEM_UID.
2946 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002947 * @param admin the component name to be registered as profile owner.
2948 * @param ownerName the human readable name of the organisation associated with this DPM.
2949 * @param userHandle the userId to set the profile owner for.
2950 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002951 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2952 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002953 */
Robin Lee25e26452015-06-02 09:56:29 -07002954 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002955 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002956 if (mService != null) {
2957 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002958 if (ownerName == null) {
2959 ownerName = "";
2960 }
2961 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002962 } catch (RemoteException re) {
2963 Log.w(TAG, "Failed to set profile owner", re);
2964 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2965 }
2966 }
2967 return false;
2968 }
2969
2970 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00002971 * Sets the device owner information to be shown on the lock screen.
2972 *
2973 * <p>If the device owner information is {@code null} or empty then the device owner info is
2974 * cleared and the user owner info is shown on the lock screen if it is set.
2975 *
2976 * @param admin The name of the admin component to check.
2977 * @param info Device owner information which will be displayed instead of the user
2978 * owner info.
2979 * @return Whether the device owner information has been set.
2980 */
2981 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
2982 if (mService != null) {
2983 try {
2984 return mService.setDeviceOwnerLockScreenInfo(admin, info);
2985 } catch (RemoteException re) {
2986 Log.w(TAG, "Failed talking with device policy service", re);
2987 }
2988 }
2989 return false;
2990 }
2991
2992 /**
2993 * @return The device owner information. If it is not set returns {@code null}.
2994 */
2995 public String getDeviceOwnerLockScreenInfo() {
2996 if (mService != null) {
2997 try {
2998 return mService.getDeviceOwnerLockScreenInfo();
2999 } catch (RemoteException re) {
3000 Log.w(TAG, "Failed talking with device policy service", re);
3001 }
3002 }
3003 return null;
3004 }
3005
3006 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003007 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3008 * be used. Only the profile owner can call this.
3009 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003010 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003011 *
3012 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3013 */
Robin Lee25e26452015-06-02 09:56:29 -07003014 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003015 if (mService != null) {
3016 try {
3017 mService.setProfileEnabled(admin);
3018 } catch (RemoteException e) {
3019 Log.w(TAG, "Failed talking with device policy service", e);
3020 }
3021 }
3022 }
3023
3024 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003025 * Sets the name of the profile. In the device owner case it sets the name of the user
3026 * 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 +01003027 * never called by the profile or device owner, the name will be set to default values.
3028 *
3029 * @see #isProfileOwnerApp
3030 * @see #isDeviceOwnerApp
3031 *
Robin Lee25e26452015-06-02 09:56:29 -07003032 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003033 * @param profileName The name of the profile.
3034 */
Robin Lee25e26452015-06-02 09:56:29 -07003035 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003036 if (mService != null) {
3037 try {
Robin Lee25e26452015-06-02 09:56:29 -07003038 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003039 } catch (RemoteException e) {
3040 Log.w(TAG, "Failed talking with device policy service", e);
3041 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003042 }
3043 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003044
3045 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003046 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003047 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003048 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003049 *
3050 * @param packageName The package name of the app to compare with the registered profile owner.
3051 * @return Whether or not the package is registered as the profile owner.
3052 */
3053 public boolean isProfileOwnerApp(String packageName) {
3054 if (mService != null) {
3055 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003056 ComponentName profileOwner = mService.getProfileOwner(
3057 Process.myUserHandle().getIdentifier());
3058 return profileOwner != null
3059 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003060 } catch (RemoteException re) {
3061 Log.w(TAG, "Failed to check profile owner");
3062 }
3063 }
3064 return false;
3065 }
3066
3067 /**
3068 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003069 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003070 * owner has been set for that user.
3071 * @throws IllegalArgumentException if the userId is invalid.
3072 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003073 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003074 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003075 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3076 }
3077
3078 /**
3079 * @see #getProfileOwner()
3080 * @hide
3081 */
3082 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003083 if (mService != null) {
3084 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003085 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003086 } catch (RemoteException re) {
3087 Log.w(TAG, "Failed to get profile owner");
3088 throw new IllegalArgumentException(
3089 "Requested profile owner for invalid userId", re);
3090 }
3091 }
3092 return null;
3093 }
3094
3095 /**
3096 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003097 * @return the human readable name of the organisation associated with this DPM or {@code null}
3098 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003099 * @throws IllegalArgumentException if the userId is invalid.
3100 */
3101 public String getProfileOwnerName() throws IllegalArgumentException {
3102 if (mService != null) {
3103 try {
3104 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3105 } catch (RemoteException re) {
3106 Log.w(TAG, "Failed to get profile owner");
3107 throw new IllegalArgumentException(
3108 "Requested profile owner for invalid userId", re);
3109 }
3110 }
3111 return null;
3112 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003113
3114 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003115 * @hide
Makoto Onuki219bbaf2015-11-12 01:38:47 +00003116 * @param user The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003117 * @return the human readable name of the organisation associated with this profile owner or
3118 * null if one is not set.
3119 * @throws IllegalArgumentException if the userId is invalid.
3120 */
3121 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003122 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003123 if (mService != null) {
3124 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003125 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003126 } catch (RemoteException re) {
3127 Log.w(TAG, "Failed to get profile owner");
3128 throw new IllegalArgumentException(
3129 "Requested profile owner for invalid userId", re);
3130 }
3131 }
3132 return null;
3133 }
3134
3135 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003136 * Called by a profile owner or device owner to add a default intent handler activity for
3137 * intents that match a certain intent filter. This activity will remain the default intent
3138 * handler even if the set of potential event handlers for the intent filter changes and if
3139 * the intent preferences are reset.
3140 *
3141 * <p>The default disambiguation mechanism takes over if the activity is not installed
3142 * (anymore). When the activity is (re)installed, it is automatically reset as default
3143 * intent handler for the filter.
3144 *
3145 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3146 * security exception will be thrown.
3147 *
3148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3149 * @param filter The IntentFilter for which a default handler is added.
3150 * @param activity The Activity that is added as default intent handler.
3151 */
Robin Lee25e26452015-06-02 09:56:29 -07003152 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3153 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003154 if (mService != null) {
3155 try {
3156 mService.addPersistentPreferredActivity(admin, filter, activity);
3157 } catch (RemoteException e) {
3158 Log.w(TAG, "Failed talking with device policy service", e);
3159 }
3160 }
3161 }
3162
3163 /**
3164 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003165 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003166 *
3167 * <p>The calling device admin must be a profile owner. If it is not, a security
3168 * exception will be thrown.
3169 *
3170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3171 * @param packageName The name of the package for which preferences are removed.
3172 */
Robin Lee25e26452015-06-02 09:56:29 -07003173 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003174 String packageName) {
3175 if (mService != null) {
3176 try {
3177 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3178 } catch (RemoteException e) {
3179 Log.w(TAG, "Failed talking with device policy service", e);
3180 }
3181 }
3182 }
Robin Lee66e5d962014-04-09 16:44:21 +01003183
3184 /**
3185 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003186 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003187 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003188 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3189 * <ul>
3190 * <li>{@code boolean}
3191 * <li>{@code int}
3192 * <li>{@code String} or {@code String[]}
3193 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3194 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003195 *
3196 * <p>The application restrictions are only made visible to the target application and the
3197 * profile or device owner.
3198 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003199 * <p>If the restrictions are not available yet, but may be applied in the near future,
3200 * the admin can notify the target application of that by adding
3201 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3202 *
Robin Lee66e5d962014-04-09 16:44:21 +01003203 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3204 * exception will be thrown.
3205 *
3206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3207 * @param packageName The name of the package to update restricted settings for.
3208 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3209 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003210 *
3211 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003212 */
Robin Lee25e26452015-06-02 09:56:29 -07003213 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003214 Bundle settings) {
3215 if (mService != null) {
3216 try {
3217 mService.setApplicationRestrictions(admin, packageName, settings);
3218 } catch (RemoteException e) {
3219 Log.w(TAG, "Failed talking with device policy service", e);
3220 }
3221 }
3222 }
3223
3224 /**
Jim Millere303bf42014-08-26 17:12:29 -07003225 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3226 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3227 * trust agents but those enabled by this function call. If flag
3228 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003229 *
3230 * <p>The calling device admin must have requested
3231 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003232 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003233 *
3234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003235 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003236 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003237 * will be strictly disabled according to the state of the
3238 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3239 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3240 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3241 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003242 */
Robin Lee25e26452015-06-02 09:56:29 -07003243 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3244 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003245 if (mService != null) {
3246 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003247 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003248 } catch (RemoteException e) {
3249 Log.w(TAG, "Failed talking with device policy service", e);
3250 }
3251 }
3252 }
3253
3254 /**
Jim Millere303bf42014-08-26 17:12:29 -07003255 * Gets configuration for the given trust agent based on aggregating all calls to
3256 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3257 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003258 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003259 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3260 * this function returns a list of configurations for all admins that declare
3261 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3262 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3263 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3264 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003265 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003266 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003267 */
Robin Lee25e26452015-06-02 09:56:29 -07003268 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3269 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003270 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003271 }
3272
3273 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003274 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3275 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003276 if (mService != null) {
3277 try {
Jim Millere303bf42014-08-26 17:12:29 -07003278 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003279 } catch (RemoteException e) {
3280 Log.w(TAG, "Failed talking with device policy service", e);
3281 }
3282 }
Jim Millere303bf42014-08-26 17:12:29 -07003283 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003284 }
3285
3286 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003287 * Called by a profile owner of a managed profile to set whether caller-Id information from
3288 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003289 *
3290 * <p>The calling device admin must be a profile owner. If it is not, a
3291 * security exception will be thrown.
3292 *
Robin Lee25e26452015-06-02 09:56:29 -07003293 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003294 * @param disabled If true caller-Id information in the managed profile is not displayed.
3295 */
Robin Lee25e26452015-06-02 09:56:29 -07003296 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003297 if (mService != null) {
3298 try {
Robin Lee25e26452015-06-02 09:56:29 -07003299 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003300 } catch (RemoteException e) {
3301 Log.w(TAG, "Failed talking with device policy service", e);
3302 }
3303 }
3304 }
3305
3306 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003307 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3308 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003309 *
3310 * <p>The calling device admin must be a profile owner. If it is not, a
3311 * security exception will be thrown.
3312 *
Robin Lee25e26452015-06-02 09:56:29 -07003313 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003314 */
Robin Lee25e26452015-06-02 09:56:29 -07003315 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003316 if (mService != null) {
3317 try {
Robin Lee25e26452015-06-02 09:56:29 -07003318 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003319 } catch (RemoteException e) {
3320 Log.w(TAG, "Failed talking with device policy service", e);
3321 }
3322 }
3323 return false;
3324 }
3325
3326 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003327 * Determine whether or not caller-Id information has been disabled.
3328 *
3329 * @param userHandle The user for whom to check the caller-id permission
3330 * @hide
3331 */
3332 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3333 if (mService != null) {
3334 try {
3335 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3336 } catch (RemoteException e) {
3337 Log.w(TAG, "Failed talking with device policy service", e);
3338 }
3339 }
3340 return false;
3341 }
3342
3343 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003344 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3345 * @hide
3346 */
3347 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3348 Intent originalIntent) {
3349 if (mService != null) {
3350 try {
3351 mService.startManagedQuickContact(
3352 actualLookupKey, actualContactId, originalIntent);
3353 } catch (RemoteException e) {
3354 Log.w(TAG, "Failed talking with device policy service", e);
3355 }
3356 }
3357 }
3358
3359 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003360 * Called by a profile owner of a managed profile to set whether bluetooth
3361 * devices can access enterprise contacts.
3362 * <p>
3363 * The calling device admin must be a profile owner. If it is not, a
3364 * security exception will be thrown.
3365 * <p>
3366 * This API works on managed profile only.
3367 *
Robin Lee25e26452015-06-02 09:56:29 -07003368 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003369 * with.
3370 * @param disabled If true, bluetooth devices cannot access enterprise
3371 * contacts.
3372 */
Robin Lee25e26452015-06-02 09:56:29 -07003373 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003374 if (mService != null) {
3375 try {
Robin Lee25e26452015-06-02 09:56:29 -07003376 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003377 } catch (RemoteException e) {
3378 Log.w(TAG, "Failed talking with device policy service", e);
3379 }
3380 }
3381 }
3382
3383 /**
3384 * Called by a profile owner of a managed profile to determine whether or
3385 * not Bluetooth devices cannot access enterprise contacts.
3386 * <p>
3387 * The calling device admin must be a profile owner. If it is not, a
3388 * security exception will be thrown.
3389 * <p>
3390 * This API works on managed profile only.
3391 *
Robin Lee25e26452015-06-02 09:56:29 -07003392 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003393 * with.
3394 */
Robin Lee25e26452015-06-02 09:56:29 -07003395 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003396 if (mService != null) {
3397 try {
Robin Lee25e26452015-06-02 09:56:29 -07003398 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003399 } catch (RemoteException e) {
3400 Log.w(TAG, "Failed talking with device policy service", e);
3401 }
3402 }
3403 return true;
3404 }
3405
3406 /**
3407 * Determine whether or not Bluetooth devices cannot access contacts.
3408 * <p>
3409 * This API works on managed profile UserHandle only.
3410 *
3411 * @param userHandle The user for whom to check the caller-id permission
3412 * @hide
3413 */
3414 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3415 if (mService != null) {
3416 try {
3417 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3418 .getIdentifier());
3419 } catch (RemoteException e) {
3420 Log.w(TAG, "Failed talking with device policy service", e);
3421 }
3422 }
3423 return true;
3424 }
3425
3426 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003427 * Called by the profile owner of a managed profile so that some intents sent in the managed
3428 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003429 * Only activity intents are supported.
3430 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003432 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3433 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003434 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3435 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003436 */
Robin Lee25e26452015-06-02 09:56:29 -07003437 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003438 if (mService != null) {
3439 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003440 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003441 } catch (RemoteException e) {
3442 Log.w(TAG, "Failed talking with device policy service", e);
3443 }
3444 }
3445 }
3446
3447 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003448 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3449 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003450 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003451 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3452 */
Robin Lee25e26452015-06-02 09:56:29 -07003453 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003454 if (mService != null) {
3455 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003456 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003457 } catch (RemoteException e) {
3458 Log.w(TAG, "Failed talking with device policy service", e);
3459 }
3460 }
3461 }
3462
3463 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003464 * Called by a profile or device owner to set the permitted accessibility services. When
3465 * set by a device owner or profile owner the restriction applies to all profiles of the
3466 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003467 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003468 * By default the user can use any accessiblity service. When zero or more packages have
3469 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003470 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003471 *
3472 * <p> Calling with a null value for the list disables the restriction so that all services
3473 * can be used, calling with an empty list only allows the builtin system's services.
3474 *
3475 * <p> System accesibility services are always available to the user the list can't modify
3476 * this.
3477 *
3478 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3479 * @param packageNames List of accessibility service package names.
3480 *
3481 * @return true if setting the restriction succeeded. It fail if there is
3482 * one or more non-system accessibility services enabled, that are not in the list.
3483 */
Robin Lee25e26452015-06-02 09:56:29 -07003484 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003485 List<String> packageNames) {
3486 if (mService != null) {
3487 try {
3488 return mService.setPermittedAccessibilityServices(admin, packageNames);
3489 } catch (RemoteException e) {
3490 Log.w(TAG, "Failed talking with device policy service", e);
3491 }
3492 }
3493 return false;
3494 }
3495
3496 /**
3497 * Returns the list of permitted accessibility services set by this device or profile owner.
3498 *
3499 * <p>An empty list means no accessibility services except system services are allowed.
3500 * Null means all accessibility services are allowed.
3501 *
3502 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3503 * @return List of accessiblity service package names.
3504 */
Robin Lee25e26452015-06-02 09:56:29 -07003505 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003506 if (mService != null) {
3507 try {
3508 return mService.getPermittedAccessibilityServices(admin);
3509 } catch (RemoteException e) {
3510 Log.w(TAG, "Failed talking with device policy service", e);
3511 }
3512 }
3513 return null;
3514 }
3515
3516 /**
3517 * Returns the list of accessibility services permitted by the device or profiles
3518 * owners of this user.
3519 *
3520 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3521 * it will contain the intersection of the permitted lists for any device or profile
3522 * owners that apply to this user. It will also include any system accessibility services.
3523 *
3524 * @param userId which user to check for.
3525 * @return List of accessiblity service package names.
3526 * @hide
3527 */
3528 @SystemApi
3529 public List<String> getPermittedAccessibilityServices(int userId) {
3530 if (mService != null) {
3531 try {
3532 return mService.getPermittedAccessibilityServicesForUser(userId);
3533 } catch (RemoteException e) {
3534 Log.w(TAG, "Failed talking with device policy service", e);
3535 }
3536 }
3537 return null;
3538 }
3539
3540 /**
3541 * Called by a profile or device owner to set the permitted input methods services. When
3542 * set by a device owner or profile owner the restriction applies to all profiles of the
3543 * user the device owner or profile owner is an admin for.
3544 *
3545 * By default the user can use any input method. When zero or more packages have
3546 * been added, input method that are not in the list and not part of the system
3547 * can not be enabled by the user.
3548 *
3549 * This method will fail if it is called for a admin that is not for the foreground user
3550 * or a profile of the foreground user.
3551 *
3552 * <p> Calling with a null value for the list disables the restriction so that all input methods
3553 * can be used, calling with an empty list disables all but the system's own input methods.
3554 *
3555 * <p> System input methods are always available to the user this method can't modify this.
3556 *
3557 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3558 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003559 * @return true if setting the restriction succeeded. It will fail if there are
3560 * one or more non-system input methods currently enabled that are not in
3561 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003562 */
Robin Lee25e26452015-06-02 09:56:29 -07003563 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003564 if (mService != null) {
3565 try {
3566 return mService.setPermittedInputMethods(admin, packageNames);
3567 } catch (RemoteException e) {
3568 Log.w(TAG, "Failed talking with device policy service", e);
3569 }
3570 }
3571 return false;
3572 }
3573
3574
3575 /**
3576 * Returns the list of permitted input methods set by this device or profile owner.
3577 *
3578 * <p>An empty list means no input methods except system input methods are allowed.
3579 * Null means all input methods are allowed.
3580 *
3581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3582 * @return List of input method package names.
3583 */
Robin Lee25e26452015-06-02 09:56:29 -07003584 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003585 if (mService != null) {
3586 try {
3587 return mService.getPermittedInputMethods(admin);
3588 } catch (RemoteException e) {
3589 Log.w(TAG, "Failed talking with device policy service", e);
3590 }
3591 }
3592 return null;
3593 }
3594
3595 /**
3596 * Returns the list of input methods permitted by the device or profiles
3597 * owners of the current user.
3598 *
3599 * <p>Null means all input methods are allowed, if a non-null list is returned
3600 * it will contain the intersection of the permitted lists for any device or profile
3601 * owners that apply to this user. It will also include any system input methods.
3602 *
3603 * @return List of input method package names.
3604 * @hide
3605 */
3606 @SystemApi
3607 public List<String> getPermittedInputMethodsForCurrentUser() {
3608 if (mService != null) {
3609 try {
3610 return mService.getPermittedInputMethodsForCurrentUser();
3611 } catch (RemoteException e) {
3612 Log.w(TAG, "Failed talking with device policy service", e);
3613 }
3614 }
3615 return null;
3616 }
3617
3618 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003619 * Called by a device owner to create a user with the specified name. The UserHandle returned
3620 * by this method should not be persisted as user handles are recycled as users are removed and
3621 * created. If you need to persist an identifier for this user, use
3622 * {@link UserManager#getSerialNumberForUser}.
3623 *
3624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3625 * @param name the user's name
3626 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003627 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3628 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003629 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003630 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003631 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003632 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003633 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003634 try {
3635 return mService.createUser(admin, name);
3636 } catch (RemoteException re) {
3637 Log.w(TAG, "Could not create a user", re);
3638 }
3639 return null;
3640 }
3641
3642 /**
Jason Monk03978a42014-06-10 15:05:30 -04003643 * Called by a device owner to create a user with the specified name. The UserHandle returned
3644 * by this method should not be persisted as user handles are recycled as users are removed and
3645 * created. If you need to persist an identifier for this user, use
3646 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3647 * immediately.
3648 *
3649 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3650 * as registered as an active admin on the new user. The profile owner package will be
3651 * installed on the new user if it already is installed on the device.
3652 *
3653 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3654 * profileOwnerComponent when onEnable is called.
3655 *
3656 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3657 * @param name the user's name
3658 * @param ownerName the human readable name of the organisation associated with this DPM.
3659 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3660 * the user.
3661 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3662 * on the new user.
3663 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003664 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3665 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003666 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003667 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003668 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003669 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003670 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3671 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003672 try {
3673 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3674 adminExtras);
3675 } catch (RemoteException re) {
3676 Log.w(TAG, "Could not create a user", re);
3677 }
3678 return null;
3679 }
3680
3681 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003682 * Called by a device owner to remove a user and all associated data. The primary user can
3683 * not be removed.
3684 *
3685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3686 * @param userHandle the user to remove.
3687 * @return {@code true} if the user was removed, {@code false} otherwise.
3688 */
Robin Lee25e26452015-06-02 09:56:29 -07003689 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003690 try {
3691 return mService.removeUser(admin, userHandle);
3692 } catch (RemoteException re) {
3693 Log.w(TAG, "Could not remove user ", re);
3694 return false;
3695 }
3696 }
3697
3698 /**
Jason Monk582d9112014-07-09 19:57:08 -04003699 * Called by a device owner to switch the specified user to the foreground.
3700 *
3701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3702 * @param userHandle the user to switch to; null will switch to primary.
3703 * @return {@code true} if the switch was successful, {@code false} otherwise.
3704 *
3705 * @see Intent#ACTION_USER_FOREGROUND
3706 */
Robin Lee25e26452015-06-02 09:56:29 -07003707 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003708 try {
3709 return mService.switchUser(admin, userHandle);
3710 } catch (RemoteException re) {
3711 Log.w(TAG, "Could not switch user ", re);
3712 return false;
3713 }
3714 }
3715
3716 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003717 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003718 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003719 *
3720 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3721 * exception will be thrown.
3722 *
3723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3724 * @param packageName The name of the package to fetch restricted settings of.
3725 * @return {@link Bundle} of settings corresponding to what was set last time
3726 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3727 * if no restrictions have been set.
3728 */
Robin Lee25e26452015-06-02 09:56:29 -07003729 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003730 if (mService != null) {
3731 try {
3732 return mService.getApplicationRestrictions(admin, packageName);
3733 } catch (RemoteException e) {
3734 Log.w(TAG, "Failed talking with device policy service", e);
3735 }
3736 }
3737 return null;
3738 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003739
3740 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003741 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003742 * <p>
3743 * The calling device admin must be a profile or device owner; if it is not,
3744 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003745 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003746 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3747 * with.
3748 * @param key The key of the restriction. See the constants in
3749 * {@link android.os.UserManager} for the list of keys.
3750 */
Robin Lee25e26452015-06-02 09:56:29 -07003751 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003752 if (mService != null) {
3753 try {
3754 mService.setUserRestriction(admin, key, true);
3755 } catch (RemoteException e) {
3756 Log.w(TAG, "Failed talking with device policy service", e);
3757 }
3758 }
3759 }
3760
3761 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003762 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003763 * <p>
3764 * The calling device admin must be a profile or device owner; if it is not,
3765 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003766 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003767 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3768 * with.
3769 * @param key The key of the restriction. See the constants in
3770 * {@link android.os.UserManager} for the list of keys.
3771 */
Robin Lee25e26452015-06-02 09:56:29 -07003772 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003773 if (mService != null) {
3774 try {
3775 mService.setUserRestriction(admin, key, false);
3776 } catch (RemoteException e) {
3777 Log.w(TAG, "Failed talking with device policy service", e);
3778 }
3779 }
3780 }
Adam Connors010cfd42014-04-16 12:48:13 +01003781
3782 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003783 * Called by a profile or device owner to get user restrictions set with
3784 * {@link #addUserRestriction(ComponentName, String)}.
3785 * <p>
3786 * The target user may have more restrictions set by the system or other device owner / profile
3787 * owner. To get all the user restrictions currently set, use
3788 * {@link UserManager#getUserRestrictions()}.
3789 *
3790 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3791 */
3792 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
3793 Bundle ret = null;
3794 if (mService != null) {
3795 try {
3796 ret = mService.getUserRestrictions(admin);
3797 } catch (RemoteException e) {
3798 Log.w(TAG, "Failed talking with device policy service", e);
3799 }
3800 }
3801 return ret == null ? new Bundle() : ret;
3802 }
3803
3804 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003805 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003806 * is unavailable for use, but the data and actual package file remain.
3807 *
3808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003809 * @param packageName The name of the package to hide or unhide.
3810 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3811 * unhidden.
3812 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003813 */
Robin Lee25e26452015-06-02 09:56:29 -07003814 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003815 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003816 if (mService != null) {
3817 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003818 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003819 } catch (RemoteException e) {
3820 Log.w(TAG, "Failed talking with device policy service", e);
3821 }
3822 }
3823 return false;
3824 }
3825
3826 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003827 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003828 *
3829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003830 * @param packageName The name of the package to retrieve the hidden status of.
3831 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003832 */
Robin Lee25e26452015-06-02 09:56:29 -07003833 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003834 if (mService != null) {
3835 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003836 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003837 } catch (RemoteException e) {
3838 Log.w(TAG, "Failed talking with device policy service", e);
3839 }
3840 }
3841 return false;
3842 }
3843
3844 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003845 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003846 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003847 *
3848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3849 * @param packageName The package to be re-enabled in the current profile.
3850 */
Robin Lee25e26452015-06-02 09:56:29 -07003851 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003852 if (mService != null) {
3853 try {
3854 mService.enableSystemApp(admin, packageName);
3855 } catch (RemoteException e) {
3856 Log.w(TAG, "Failed to install package: " + packageName);
3857 }
3858 }
3859 }
3860
3861 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003862 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003863 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003864 *
3865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3866 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3867 * intent will be re-enabled in the current profile.
3868 * @return int The number of activities that matched the intent and were installed.
3869 */
Robin Lee25e26452015-06-02 09:56:29 -07003870 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003871 if (mService != null) {
3872 try {
3873 return mService.enableSystemAppWithIntent(admin, intent);
3874 } catch (RemoteException e) {
3875 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3876 }
3877 }
3878 return 0;
3879 }
3880
3881 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003882 * Called by a device owner or profile owner to disable account management for a specific type
3883 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003884 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003885 * <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 +01003886 * security exception will be thrown.
3887 *
3888 * <p>When account management is disabled for an account type, adding or removing an account
3889 * of that type will not be possible.
3890 *
3891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3892 * @param accountType For which account management is disabled or enabled.
3893 * @param disabled The boolean indicating that account management will be disabled (true) or
3894 * enabled (false).
3895 */
Robin Lee25e26452015-06-02 09:56:29 -07003896 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003897 boolean disabled) {
3898 if (mService != null) {
3899 try {
3900 mService.setAccountManagementDisabled(admin, accountType, disabled);
3901 } catch (RemoteException e) {
3902 Log.w(TAG, "Failed talking with device policy service", e);
3903 }
3904 }
3905 }
3906
3907 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003908 * Gets the array of accounts for which account management is disabled by the profile owner.
3909 *
3910 * <p> Account management can be disabled/enabled by calling
3911 * {@link #setAccountManagementDisabled}.
3912 *
3913 * @return a list of account types for which account management has been disabled.
3914 *
3915 * @see #setAccountManagementDisabled
3916 */
3917 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003918 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003919 }
3920
3921 /**
3922 * @see #getAccountTypesWithManagementDisabled()
3923 * @hide
3924 */
3925 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003926 if (mService != null) {
3927 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003928 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003929 } catch (RemoteException e) {
3930 Log.w(TAG, "Failed talking with device policy service", e);
3931 }
3932 }
3933
3934 return null;
3935 }
justinzhang511e0d82014-03-24 16:09:24 -04003936
3937 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003938 * Sets which packages may enter lock task mode.
3939 *
3940 * <p>Any packages that shares uid with an allowed package will also be allowed
3941 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04003942 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003943 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01003944 * package list results in locked tasks belonging to those packages to be finished.
3945 *
Jason Monkc5185f22014-06-24 11:12:42 -04003946 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04003947 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04003948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04003949 *
3950 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00003951 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
3952 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04003953 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04003954 */
Robin Lee25e26452015-06-02 09:56:29 -07003955 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04003956 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04003957 if (mService != null) {
3958 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003959 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04003960 } catch (RemoteException e) {
3961 Log.w(TAG, "Failed talking with device policy service", e);
3962 }
3963 }
3964 }
3965
3966 /**
Jason Monkd7b86212014-06-16 13:15:38 -04003967 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04003968 *
3969 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04003970 * @hide
3971 */
Robin Lee25e26452015-06-02 09:56:29 -07003972 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04003973 if (mService != null) {
3974 try {
Jason Monk48aacba2014-08-13 16:29:08 -04003975 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04003976 } catch (RemoteException e) {
3977 Log.w(TAG, "Failed talking with device policy service", e);
3978 }
3979 }
3980 return null;
3981 }
3982
3983 /**
3984 * This function lets the caller know whether the given component is allowed to start the
3985 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04003986 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04003987 */
Jason Monkd7b86212014-06-16 13:15:38 -04003988 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04003989 if (mService != null) {
3990 try {
Jason Monkd7b86212014-06-16 13:15:38 -04003991 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04003992 } catch (RemoteException e) {
3993 Log.w(TAG, "Failed talking with device policy service", e);
3994 }
3995 }
3996 return false;
3997 }
Julia Reynoldsda551652014-05-14 17:15:16 -04003998
3999 /**
4000 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4001 * 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 -04004002 * <p>The settings that can be updated with this method are:
4003 * <ul>
4004 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4005 * <li>{@link Settings.Global#AUTO_TIME}</li>
4006 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004007 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004008 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004009 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004010 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004011 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004012 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004013 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004014 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004015 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004016 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004017 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004018 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004019 * <ul>
4020 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4021 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4022 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4023 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4024 * <li>{@link Settings.Global#MODE_RINGER}.
4025 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4026 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4027 * <li>{@link Settings.Global#WIFI_ON}.
4028 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4029 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004030 *
4031 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4032 * @param setting The name of the setting to update.
4033 * @param value The value to update the setting to.
4034 */
Robin Lee25e26452015-06-02 09:56:29 -07004035 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004036 if (mService != null) {
4037 try {
4038 mService.setGlobalSetting(admin, setting, value);
4039 } catch (RemoteException e) {
4040 Log.w(TAG, "Failed talking with device policy service", e);
4041 }
4042 }
4043 }
4044
4045 /**
4046 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4047 * that the value of the setting is in the correct form for the setting type should be performed
4048 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004049 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004050 * <ul>
4051 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004052 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004053 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4054 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004055 * <p>A device owner can additionally update the following settings:
4056 * <ul>
4057 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4058 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004059 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4060 * @param setting The name of the setting to update.
4061 * @param value The value to update the setting to.
4062 */
Robin Lee25e26452015-06-02 09:56:29 -07004063 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004064 if (mService != null) {
4065 try {
4066 mService.setSecureSetting(admin, setting, value);
4067 } catch (RemoteException e) {
4068 Log.w(TAG, "Failed talking with device policy service", e);
4069 }
4070 }
4071 }
4072
Amith Yamasanif20d6402014-05-24 15:34:37 -07004073 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004074 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004075 * making permission requests of a local or remote administrator of the user.
4076 * <p/>
4077 * Only a profile owner can designate the restrictions provider.
4078 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004079 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004080 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004081 * it removes the restrictions provider previously assigned.
4082 */
Robin Lee25e26452015-06-02 09:56:29 -07004083 public void setRestrictionsProvider(@NonNull ComponentName admin,
4084 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004085 if (mService != null) {
4086 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004087 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004088 } catch (RemoteException re) {
4089 Log.w(TAG, "Failed to set permission provider on device policy service");
4090 }
4091 }
4092 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004093
4094 /**
4095 * Called by profile or device owners to set the master volume mute on or off.
4096 *
4097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4098 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4099 */
Robin Lee25e26452015-06-02 09:56:29 -07004100 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004101 if (mService != null) {
4102 try {
4103 mService.setMasterVolumeMuted(admin, on);
4104 } catch (RemoteException re) {
4105 Log.w(TAG, "Failed to setMasterMute on device policy service");
4106 }
4107 }
4108 }
4109
4110 /**
4111 * Called by profile or device owners to check whether the master volume mute is on or off.
4112 *
4113 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4114 * @return {@code true} if master volume is muted, {@code false} if it's not.
4115 */
Robin Lee25e26452015-06-02 09:56:29 -07004116 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004117 if (mService != null) {
4118 try {
4119 return mService.isMasterVolumeMuted(admin);
4120 } catch (RemoteException re) {
4121 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4122 }
4123 }
4124 return false;
4125 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004126
4127 /**
4128 * Called by profile or device owners to change whether a user can uninstall
4129 * a package.
4130 *
4131 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4132 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004133 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004134 */
Robin Lee25e26452015-06-02 09:56:29 -07004135 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004136 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004137 if (mService != null) {
4138 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004139 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004140 } catch (RemoteException re) {
4141 Log.w(TAG, "Failed to call block uninstall on device policy service");
4142 }
4143 }
4144 }
4145
4146 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004147 * Check whether the current user has been blocked by device policy from uninstalling a package.
4148 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004149 * <p>
4150 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004151 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004152 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004153 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004154 *
Robin Lee25e26452015-06-02 09:56:29 -07004155 * @param admin The name of the admin component whose blocking policy will be checked, or
4156 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004157 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004158 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004159 */
Robin Lee25e26452015-06-02 09:56:29 -07004160 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004161 if (mService != null) {
4162 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004163 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004164 } catch (RemoteException re) {
4165 Log.w(TAG, "Failed to call block uninstall on device policy service");
4166 }
4167 }
4168 return false;
4169 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004170
4171 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004172 * Called by the profile owner of a managed profile to enable widget providers from a
4173 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004174 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004175 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004176 * a package may have zero or more provider components, where each component
4177 * provides a different widget type.
4178 * <p>
4179 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004180 *
4181 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4182 * @param packageName The package from which widget providers are white-listed.
4183 * @return Whether the package was added.
4184 *
4185 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4186 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4187 */
Robin Lee25e26452015-06-02 09:56:29 -07004188 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004189 if (mService != null) {
4190 try {
4191 return mService.addCrossProfileWidgetProvider(admin, packageName);
4192 } catch (RemoteException re) {
4193 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4194 }
4195 }
4196 return false;
4197 }
4198
4199 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004200 * Called by the profile owner of a managed profile to disable widget providers from a given
4201 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004202 * package should have been added via {@link #addCrossProfileWidgetProvider(
4203 * android.content.ComponentName, String)}.
4204 * <p>
4205 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004206 *
4207 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4208 * @param packageName The package from which widget providers are no longer
4209 * white-listed.
4210 * @return Whether the package was removed.
4211 *
4212 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4213 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4214 */
Robin Lee25e26452015-06-02 09:56:29 -07004215 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004216 if (mService != null) {
4217 try {
4218 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4219 } catch (RemoteException re) {
4220 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4221 }
4222 }
4223 return false;
4224 }
4225
4226 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004227 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004228 * available in the parent profile.
4229 *
4230 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4231 * @return The white-listed package list.
4232 *
4233 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4234 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4235 */
Robin Lee25e26452015-06-02 09:56:29 -07004236 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004237 if (mService != null) {
4238 try {
4239 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4240 if (providers != null) {
4241 return providers;
4242 }
4243 } catch (RemoteException re) {
4244 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4245 }
4246 }
4247 return Collections.emptyList();
4248 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004249
4250 /**
4251 * Called by profile or device owners to set the current user's photo.
4252 *
4253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4254 * @param icon the bitmap to set as the photo.
4255 */
Robin Lee25e26452015-06-02 09:56:29 -07004256 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004257 try {
4258 mService.setUserIcon(admin, icon);
4259 } catch (RemoteException re) {
4260 Log.w(TAG, "Could not set the user icon ", re);
4261 }
4262 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004263
4264 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004265 * Called by device owners to set a local system update policy. When a new policy is set,
4266 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004267 *
Robin Lee25e26452015-06-02 09:56:29 -07004268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4269 * components in the device owner package can set system update policies and the
4270 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004271 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004272 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004273 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004274 */
Robin Lee25e26452015-06-02 09:56:29 -07004275 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004276 if (mService != null) {
4277 try {
Robin Lee25e26452015-06-02 09:56:29 -07004278 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004279 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004280 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004281 }
4282 }
4283 }
4284
4285 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004286 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004287 *
Robin Lee25e26452015-06-02 09:56:29 -07004288 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004289 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004290 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004291 if (mService != null) {
4292 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004293 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004294 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004295 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004296 }
4297 }
4298 return null;
4299 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004300
4301 /**
4302 * Called by a device owner to disable the keyguard altogether.
4303 *
4304 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4305 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4306 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4307 * being disabled.
4308 *
4309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004310 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004311 *
4312 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004313 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004314 */
Robin Lee25e26452015-06-02 09:56:29 -07004315 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004316 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004317 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004318 } catch (RemoteException re) {
4319 Log.w(TAG, "Failed talking with device policy service", re);
4320 return false;
4321 }
4322 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004323
4324 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004325 * Called by device owner to disable the status bar. Disabling the status bar blocks
4326 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004327 * a single use device.
4328 *
4329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004330 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4331 *
4332 * @return {@code false} if attempting to disable the status bar failed.
4333 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004334 */
Robin Lee25e26452015-06-02 09:56:29 -07004335 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004336 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004337 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004338 } catch (RemoteException re) {
4339 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004340 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004341 }
4342 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004343
4344 /**
4345 * Callable by the system update service to notify device owners about pending updates.
4346 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4347 * permission.
4348 *
4349 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4350 * when the current pending update was first available. -1 if no update is available.
4351 * @hide
4352 */
4353 @SystemApi
4354 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4355 if (mService != null) {
4356 try {
4357 mService.notifyPendingSystemUpdate(updateReceivedTime);
4358 } catch (RemoteException re) {
4359 Log.w(TAG, "Could not notify device owner about pending system update", re);
4360 }
4361 }
4362 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004363
4364 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004365 * Called by profile or device owners to set the default response for future runtime permission
4366 * requests by applications. The policy can allow for normal operation which prompts the
4367 * user to grant a permission, or can allow automatic granting or denying of runtime
4368 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004369 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4370 * the permission grant state via {@link #setPermissionGrantState}.
4371 *
4372 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004373 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004374 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004375 * @param admin Which profile or device owner this request is associated with.
4376 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4377 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004378 *
4379 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004380 */
Robin Lee25e26452015-06-02 09:56:29 -07004381 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004382 try {
4383 mService.setPermissionPolicy(admin, policy);
4384 } catch (RemoteException re) {
4385 Log.w(TAG, "Failed talking with device policy service", re);
4386 }
4387 }
4388
4389 /**
4390 * Returns the current runtime permission policy set by the device or profile owner. The
4391 * default is {@link #PERMISSION_POLICY_PROMPT}.
4392 * @param admin Which profile or device owner this request is associated with.
4393 * @return the current policy for future permission requests.
4394 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004395 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004396 try {
4397 return mService.getPermissionPolicy(admin);
4398 } catch (RemoteException re) {
4399 return PERMISSION_POLICY_PROMPT;
4400 }
4401 }
4402
4403 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004404 * Sets the grant state of a runtime permission for a specific application. The state
4405 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4406 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4407 * is denied and the user cannot manage it through the UI, and {@link
4408 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4409 * user cannot manage it through the UI. This might affect all permissions in a
4410 * group that the runtime permission belongs to. This method can only be called
4411 * by a profile or device owner.
4412 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004413 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4414 * revoke the permission. It retains the previous grant, if any.
4415 *
4416 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004417 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004418 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004419 * @param admin Which profile or device owner this request is associated with.
4420 * @param packageName The application to grant or revoke a permission to.
4421 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004422 * @param grantState The permission grant state which is one of {@link
4423 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4424 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4425 * @return whether the permission was successfully granted or revoked.
4426 *
4427 * @see #PERMISSION_GRANT_STATE_DENIED
4428 * @see #PERMISSION_GRANT_STATE_DEFAULT
4429 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004430 */
Robin Lee25e26452015-06-02 09:56:29 -07004431 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004432 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004433 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004434 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004435 } catch (RemoteException re) {
4436 Log.w(TAG, "Failed talking with device policy service", re);
4437 return false;
4438 }
4439 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004440
4441 /**
4442 * Returns the current grant state of a runtime permission for a specific application.
4443 *
4444 * @param admin Which profile or device owner this request is associated with.
4445 * @param packageName The application to check the grant state for.
4446 * @param permission The permission to check for.
4447 * @return the current grant state specified by device policy. If the profile or device owner
4448 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4449 * This does not indicate whether or not the permission is currently granted for the package.
4450 *
4451 * <p/>If a grant state was set by the profile or device owner, then the return value will
4452 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4453 * which indicates if the permission is currently denied or granted.
4454 *
4455 * @see #setPermissionGrantState(ComponentName, String, String, int)
4456 * @see PackageManager#checkPermission(String, String)
4457 */
Robin Lee25e26452015-06-02 09:56:29 -07004458 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004459 String permission) {
4460 try {
4461 return mService.getPermissionGrantState(admin, packageName, permission);
4462 } catch (RemoteException re) {
4463 Log.w(TAG, "Failed talking with device policy service", re);
4464 return PERMISSION_GRANT_STATE_DEFAULT;
4465 }
4466 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004467
4468 /**
4469 * Returns if provisioning a managed profile or device is possible or not.
4470 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4471 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4472 * Note that even if this method returns true, there is a slight possibility that the
4473 * provisioning will not be allowed when it is actually initiated because some event has
4474 * happened in between.
4475 * @return if provisioning a managed profile or device is possible or not.
4476 * @throws IllegalArgumentException if the supplied action is not valid.
4477 */
4478 public boolean isProvisioningAllowed(String action) {
4479 try {
4480 return mService.isProvisioningAllowed(action);
4481 } catch (RemoteException re) {
4482 Log.w(TAG, "Failed talking with device policy service", re);
4483 return false;
4484 }
4485 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004486}