blob: 1c65c940033239871f57505edf86ef1310b9573a [file] [log] [blame]
Dianne Hackbornd6847842010-01-12 18:14:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080017package android.app.admin;
Dianne Hackbornd6847842010-01-12 18:14:19 -080018
Robin Lee25e26452015-06-02 09:56:29 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050023import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040024import android.app.Activity;
Dianne Hackbornd6847842010-01-12 18:14:19 -080025import android.content.ComponentName;
26import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010027import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000028import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.ResolveInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050032import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040033import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000034import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010035import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070036import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000037import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080038import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070041import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040042import android.os.UserManager;
Julia Reynoldsda551652014-05-14 17:15:16 -040043import android.provider.Settings;
Ricky Wai494b95d2015-11-20 16:07:15 +000044import android.provider.ContactsContract.Directory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010045import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070046import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080047import android.util.Log;
48
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070049import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040050import com.android.org.conscrypt.TrustedCertificateStore;
51
Jessica Hummel91da58d2014-04-10 17:39:43 +010052import org.xmlpull.v1.XmlPullParserException;
53
Maggie Benthallda51e682013-08-08 22:35:44 -040054import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080055import java.io.IOException;
Oscar Montemayor69238c62010-08-03 10:51:06 -070056import java.net.InetSocketAddress;
57import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010058import java.security.KeyFactory;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010059import java.security.PrivateKey;
60import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040061import java.security.cert.CertificateException;
62import java.security.cert.CertificateFactory;
63import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010064import java.security.spec.PKCS8EncodedKeySpec;
65import java.security.spec.InvalidKeySpecException;
66import java.security.NoSuchAlgorithmException;
Jim Miller604e7552014-07-18 19:00:02 -070067import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070068import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080069import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080070
71/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000072 * Public interface for managing policies enforced on a device. Most clients of this class must be
73 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000074 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000075 * a device administrator may be registered as either a profile or device owner. A given method is
76 * accessible to all device administrators unless the documentation for that method specifies that
77 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080078 *
79 * <div class="special reference">
80 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000081 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080082 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070083 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080084 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080085 */
86public class DevicePolicyManager {
87 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080088
89 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080090 private final IDevicePolicyManager mService;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070091
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070092 private DevicePolicyManager(Context context) {
93 this(context, IDevicePolicyManager.Stub.asInterface(
94 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
Dianne Hackbornd6847842010-01-12 18:14:19 -080095 }
96
Dianne Hackborn87bba1e2010-02-26 17:25:54 -080097 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070098 @VisibleForTesting
99 protected DevicePolicyManager(Context context, IDevicePolicyManager service) {
100 mContext = context;
101 mService = service;
102 }
103
104 /** @hide */
105 public static DevicePolicyManager create(Context context) {
106 DevicePolicyManager me = new DevicePolicyManager(context);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800107 return me.mService != null ? me : null;
108 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700109
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700110 /** @hide test will override it. */
111 @VisibleForTesting
112 protected int myUserId() {
113 return UserHandle.myUserId();
114 }
115
Dianne Hackbornd6847842010-01-12 18:14:19 -0800116 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000117 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000118 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100119 * <p>A managed profile allows data separation for example for the usage of a
120 * device as a personal and corporate device. The user which provisioning is started from and
121 * the managed profile share a launcher.
122 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800123 * <p>This intent will typically be sent by a mobile device management application (MDM).
124 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
125 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100126 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000127 * <p>It is possible to check if provisioning is allowed or not by querying the method
128 * {@link #isProvisioningAllowed(String)}.
129 *
130 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000131 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700132 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000133 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
134 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000135 *
136 * <p> The intent may also contain the following extras:
137 * <ul>
138 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
139 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
140 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000141 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000142 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
143 * in the provisioning intent. The
144 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
145 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
146 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100147 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100148 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
149 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100150 *
151 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
152 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
153 * the provisioning flow was successful, although this doesn't guarantee the full flow will
154 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
155 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156 */
157 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
158 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100159 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000160
161 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000162 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000163 * Activity action: Starts the provisioning flow which sets up a managed user.
164 *
165 * <p>This intent will typically be sent by a mobile device management application (MDM).
166 * Provisioning configures the current user as managed user and sets the MDM as the profile
167 * owner who has full control over the user. Provisioning can only happen before user setup has
168 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
169 * allowed.
170 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000171 * <p>This intent should contain the extra
172 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000173 *
174 * <p> If provisioning fails, the device returns to its previous state.
175 *
176 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
177 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
178 * the provisioning flow was successful, although this doesn't guarantee the full flow will
179 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
180 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000181 */
182 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
183 public static final String ACTION_PROVISION_MANAGED_USER
184 = "android.app.action.PROVISION_MANAGED_USER";
185
186 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100187 * Activity action: Starts the provisioning flow which sets up a managed device.
188 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
189 *
190 * <p> During device owner provisioning a device admin app is set as the owner of the device.
191 * A device owner has full control over the device. The device owner can not be modified by the
192 * user.
193 *
194 * <p> A typical use case would be a device that is owned by a company, but used by either an
195 * employee or client.
196 *
197 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000198 * It is possible to check if provisioning is allowed or not by querying the method
199 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100200 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000201 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100202 * <ul>
203 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
204 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
205 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100206 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000207 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000208 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100209 * </ul>
210 *
211 * <p> When device owner provisioning has completed, an intent of the type
212 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
213 * device owner.
214 *
215 * <p> If provisioning fails, the device is factory reset.
216 *
Alan Treadway4582f812015-07-28 11:49:35 +0100217 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
218 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
219 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
220 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100221 */
222 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
223 public static final String ACTION_PROVISION_MANAGED_DEVICE
224 = "android.app.action.PROVISION_MANAGED_DEVICE";
225
226 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000227 * Activity action: Starts the provisioning flow which sets up a managed device.
228 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
229 *
230 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
231 * management state that is distinct from that reached by
232 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
233 * user, and only has control over device-wide policies, not individual users and their data.
234 * The primary benefit is that multiple non-system users are supported when provisioning using
235 * this form of device management.
236 *
237 * <p> During device owner provisioning a device admin app is set as the owner of the device.
238 * A device owner has full control over the device. The device owner can not be modified by the
239 * user.
240 *
241 * <p> A typical use case would be a device that is owned by a company, but used by either an
242 * employee or client.
243 *
244 * <p> An intent with this action can be sent only on an unprovisioned device.
245 * It is possible to check if provisioning is allowed or not by querying the method
246 * {@link #isProvisioningAllowed(String)}.
247 *
248 * <p>The intent contains the following extras:
249 * <ul>
250 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
251 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
252 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
253 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
254 * </ul>
255 *
256 * <p> When device owner provisioning has completed, an intent of the type
257 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
258 * device owner.
259 *
260 * <p> If provisioning fails, the device is factory reset.
261 *
262 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
263 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
264 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
265 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
266 *
267 * @hide
268 */
269 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
270 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
271 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
272
273 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100274 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100275 * allows a mobile device management application or NFC programmer application which starts
276 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100277 * <p>
278 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
279 * sends the intent to pass data to itself on the newly created profile.
280 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
281 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100282 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
283 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
284 * message should contain a stringified {@link java.util.Properties} instance, whose string
285 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
286 * management application after provisioning.
287 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100288 * <p>
289 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700290 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
291 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100292 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100293 */
294 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100295 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100296
297 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100298 * A String extra holding the package name of the mobile device management application that
299 * will be set as the profile owner or device owner.
300 *
301 * <p>If an application starts provisioning directly via an intent with action
302 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
303 * application that started provisioning. The package will be set as profile owner in that case.
304 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000305 * <p>This package is set as device owner when device owner provisioning is started by an NFC
306 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000307 *
308 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700309 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000310
311 * @see DeviceAdminReceiver
312 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100313 * supported, but only if there is only one device admin receiver in the package that requires
314 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000315 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000316 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000317 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100318 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000319
320 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000321 * A ComponentName extra indicating the device admin receiver of the mobile device management
322 * application that will be set as the profile owner or device owner and active admin.
323 *
324 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100325 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
326 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
327 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000328 *
329 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100330 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
331 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400332 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000333 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000334 *
335 * @see DeviceAdminReceiver
336 */
337 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
338 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
339
340 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000341 * An {@link android.accounts.Account} extra holding the account to migrate during managed
342 * profile provisioning. If the account supplied is present in the primary user, it will be
343 * copied, along with its credentials to the managed profile and removed from the primary user.
344 *
345 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
346 */
347
348 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
349 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
350
351 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100352 * A String extra that, holds the email address of the account which a managed profile is
353 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
354 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100355 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100356 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
357 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100358 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
359 * contains this extra, it is forwarded in the
360 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
361 * device management application that was set as the profile owner during provisioning.
362 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100363 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100364 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
365 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100366
367 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000368 * A integer extra indicating the predominant color to show during the provisioning.
369 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000370 *
371 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
372 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
373 */
374 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
375 "android.app.extra.PROVISIONING_MAIN_COLOR";
376
377 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000378 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700379 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000380 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100381 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
382 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000383 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000384 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
385 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000386
387 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100388 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
389 * will be set to.
390 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000391 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
392 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100393 */
394 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100395 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100396
397 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100398 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
399 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100400 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000401 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
402 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100403 */
404 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100405 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100406
407 /**
408 * A String extra holding the {@link java.util.Locale} that the device will be set to.
409 * Format: xx_yy, where xx is the language code, and yy the country code.
410 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000411 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
412 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100413 */
414 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100415 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100416
417 /**
418 * A String extra holding the ssid of the wifi network that should be used during nfc device
419 * owner provisioning for downloading the mobile device management application.
420 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000421 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
422 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100423 */
424 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100425 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100426
427 /**
428 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
429 * is hidden or not.
430 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000431 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
432 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100433 */
434 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100435 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100436
437 /**
438 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100439 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
440 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100441 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000442 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
443 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100444 */
445 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100446 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100447
448 /**
449 * A String extra holding the password of the wifi network in
450 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
451 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000452 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
453 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100454 */
455 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100456 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100457
458 /**
459 * A String extra holding the proxy host for the wifi network in
460 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
461 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000462 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
463 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100464 */
465 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100466 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100467
468 /**
469 * An int extra holding the proxy port for the wifi network in
470 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
471 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000472 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
473 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100474 */
475 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100476 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100477
478 /**
479 * A String extra holding the proxy bypass for the wifi network in
480 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
481 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000482 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
483 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100484 */
485 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100486 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100487
488 /**
489 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
490 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
491 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000492 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
493 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100494 */
495 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100496 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100497
498 /**
499 * A String extra holding a url that specifies the download location of the device admin
500 * package. When not provided it is assumed that the device admin package is already installed.
501 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000502 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
503 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100504 */
505 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100506 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100507
508 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400509 * An int extra holding a minimum required version code for the device admin package. If the
510 * device admin is already installed on the device, it will only be re-downloaded from
511 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
512 * installed package is less than this version code.
513 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400514 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400515 * provisioning via an NFC bump.
516 */
517 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
518 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
519
520 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100521 * A String extra holding a http cookie header which should be used in the http request to the
522 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
523 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000524 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
525 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100526 */
527 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100528 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100529
530 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100531 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
532 * the file at download location specified in
533 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100534 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100535 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100536 * present. The provided checksum should match the checksum of the file at the download
537 * location. If the checksum doesn't match an error will be shown to the user and the user will
538 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100539 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000540 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
541 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100542 *
543 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
544 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700545 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100546 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100547 */
548 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100549 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100550
551 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100552 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100553 * android package archive at the download location specified in {@link
554 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
555 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100556 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100557 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
558 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
559 *
560 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100561 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100562 * the download location. If the checksum does not match an error will be shown to the user and
563 * the user will be asked to factory reset the device.
564 *
565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
566 * provisioning via an NFC bump.
567 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100568 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
569 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100570
571 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000572 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
573 * has completed successfully.
574 *
575 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700576 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000577 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800578 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000579 * corresponds to the account requested to be migrated at provisioning time, if any.
580 */
581 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
582 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
583 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
584
585 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400586 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500587 * provisioning.
588 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400589 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100590 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500591 */
592 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
593 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
594
595 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000596 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
597 * provisioning. If this extra is not passed, a default image will be shown.
598 * <h5>The following URI schemes are accepted:</h5>
599 * <ul>
600 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
601 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
602 * </ul>
603 *
604 * <p> It is the responsability of the caller to provide an image with a reasonable
605 * pixed density for the device.
606 *
607 * <p> If a content: URI is passed, the intent should have the flag
608 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
609 * {@link android.content.ClipData} of the intent too.
610 *
611 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
612 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
613 */
614 public static final String EXTRA_PROVISIONING_LOGO_URI =
615 "android.app.extra.PROVISIONING_LOGO_URI";
616
617 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400618 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400620 * <p>During device owner provisioning a device admin app is set as the owner of the device.
621 * A device owner has full control over the device. The device owner can not be modified by the
622 * user and the only way of resetting the device is if the device owner app calls a factory
623 * reset.
624 *
625 * <p> A typical use case would be a device that is owned by a company, but used by either an
626 * employee or client.
627 *
628 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000630 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100631 * contains the following properties:
632 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400633 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
634 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100635 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400636 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100637 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
638 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
639 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
640 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
641 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
642 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
643 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
644 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
645 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
646 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100647 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
648 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
649 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100650 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000651 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700652 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400653 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
654 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
655 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400656 */
657 public static final String MIME_TYPE_PROVISIONING_NFC
658 = "application/com.android.managedprovisioning";
659
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100660 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800661 * Activity action: ask the user to add a new device administrator to the system.
662 * The desired policy is the ComponentName of the policy in the
663 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
664 * bring the user through adding the device administrator to the system (or
665 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700666 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800667 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
668 * field to provide the user with additional explanation (in addition
669 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800670 *
671 * <p>If your administrator is already active, this will ordinarily return immediately (without
672 * user intervention). However, if your administrator has been updated and is requesting
673 * additional uses-policy flags, the user will be presented with the new list. New policies
674 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800675 */
676 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
677 public static final String ACTION_ADD_DEVICE_ADMIN
678 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700679
Dianne Hackbornd6847842010-01-12 18:14:19 -0800680 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700681 * @hide
682 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700683 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700684 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700685 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
686 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700687 * to remotely control restrictions on the user.
688 *
Makoto Onuki219bbaf2015-11-12 01:38:47 +0000689 * <p>The intent must be invoked via {@link Activity#startActivityForResult()} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700690 * result of whether or not the user approved the action. If approved, the result will
691 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
692 * as a profile owner.
693 *
694 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
695 * field to provide the user with additional explanation (in addition
696 * to your component's description) about what is being added.
697 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700698 * <p>If there is already a profile owner active or the caller is not a system app, the
699 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700700 */
701 @SystemApi
702 public static final String ACTION_SET_PROFILE_OWNER
703 = "android.app.action.SET_PROFILE_OWNER";
704
705 /**
706 * @hide
707 * Name of the profile owner admin that controls the user.
708 */
709 @SystemApi
710 public static final String EXTRA_PROFILE_OWNER_NAME
711 = "android.app.extra.PROFILE_OWNER_NAME";
712
713 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100714 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700715 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700716 *
Jim Miller284b62e2010-06-08 14:27:42 -0700717 * @hide
718 */
719 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
720 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
721
722 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100723 * Broadcast action: sent when the device owner is set or changed.
724 *
725 * This broadcast is sent only to the primary user.
726 * @see #ACTION_PROVISION_MANAGED_DEVICE
727 */
728 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
729 public static final String ACTION_DEVICE_OWNER_CHANGED
730 = "android.app.action.DEVICE_OWNER_CHANGED";
731
732 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800733 * The ComponentName of the administrator component.
734 *
735 * @see #ACTION_ADD_DEVICE_ADMIN
736 */
737 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700738
Dianne Hackbornd6847842010-01-12 18:14:19 -0800739 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800740 * An optional CharSequence providing additional explanation for why the
741 * admin is being added.
742 *
743 * @see #ACTION_ADD_DEVICE_ADMIN
744 */
745 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700746
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800747 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700748 * Activity action: have the user enter a new password. This activity should
749 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
750 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
751 * enter a new password that meets the current requirements. You can use
752 * {@link #isActivePasswordSufficient()} to determine whether you need to
753 * have the user select a new password in order to meet the current
754 * constraints. Upon being resumed from this activity, you can check the new
755 * password characteristics to see if they are sufficient.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800756 */
757 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
758 public static final String ACTION_SET_NEW_PASSWORD
759 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700760
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000761 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000762 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
763 * the parent profile to access intents sent from the managed profile.
764 * That is, when an app in the managed profile calls
765 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
766 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000767 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100768 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000769
770 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000771 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
772 * the managed profile to access intents sent from the parent profile.
773 * That is, when an app in the parent profile calls
774 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
775 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000776 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100777 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700778
Dianne Hackbornd6847842010-01-12 18:14:19 -0800779 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100780 * Broadcast action: notify that a new local system update policy has been set by the device
781 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000782 */
783 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100784 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
785 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000786
Amith Yamasanid49489b2015-04-28 14:00:26 -0700787 /**
788 * Permission policy to prompt user for new permission requests for runtime permissions.
789 * Already granted or denied permissions are not affected by this.
790 */
791 public static final int PERMISSION_POLICY_PROMPT = 0;
792
793 /**
794 * Permission policy to always grant new permission requests for runtime permissions.
795 * Already granted or denied permissions are not affected by this.
796 */
797 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
798
799 /**
800 * Permission policy to always deny new permission requests for runtime permissions.
801 * Already granted or denied permissions are not affected by this.
802 */
803 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
804
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700805 /**
806 * Runtime permission state: The user can manage the permission
807 * through the UI.
808 */
809 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
810
811 /**
812 * Runtime permission state: The permission is granted to the app
813 * and the user cannot manage the permission through the UI.
814 */
815 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
816
817 /**
818 * Runtime permission state: The permission is denied to the app
819 * and the user cannot manage the permission through the UI.
820 */
821 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000822
823 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 * Return true if the given administrator component is currently
825 * active (enabled) in the system.
826 */
Robin Lee25e26452015-06-02 09:56:29 -0700827 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700828 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100829 }
830
831 /**
832 * @see #isAdminActive(ComponentName)
833 * @hide
834 */
Robin Lee25e26452015-06-02 09:56:29 -0700835 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800836 if (mService != null) {
837 try {
Robin Lee25e26452015-06-02 09:56:29 -0700838 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800839 } catch (RemoteException e) {
840 Log.w(TAG, "Failed talking with device policy service", e);
841 }
842 }
843 return false;
844 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800845 /**
846 * Return true if the given administrator component is currently being removed
847 * for the user.
848 * @hide
849 */
Robin Lee25e26452015-06-02 09:56:29 -0700850 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800851 if (mService != null) {
852 try {
Robin Lee25e26452015-06-02 09:56:29 -0700853 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800854 } catch (RemoteException e) {
855 Log.w(TAG, "Failed talking with device policy service", e);
856 }
857 }
858 return false;
859 }
860
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700861
Dianne Hackbornd6847842010-01-12 18:14:19 -0800862 /**
Robin Lee25e26452015-06-02 09:56:29 -0700863 * Return a list of all currently active device administrators' component
864 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800865 * returned.
866 */
867 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700868 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100869 }
870
871 /**
872 * @see #getActiveAdmins()
873 * @hide
874 */
875 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800876 if (mService != null) {
877 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100878 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800879 } catch (RemoteException e) {
880 Log.w(TAG, "Failed talking with device policy service", e);
881 }
882 }
883 return null;
884 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700885
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800886 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700887 * Used by package administration code to determine if a package can be stopped
888 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800889 * @hide
890 */
891 public boolean packageHasActiveAdmins(String packageName) {
892 if (mService != null) {
893 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700894 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800895 } catch (RemoteException e) {
896 Log.w(TAG, "Failed talking with device policy service", e);
897 }
898 }
899 return false;
900 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700901
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800902 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 * Remove a current administration component. This can only be called
904 * by the application that owns the administration component; if you
905 * try to remove someone else's component, a security exception will be
906 * thrown.
907 */
Robin Lee25e26452015-06-02 09:56:29 -0700908 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800909 if (mService != null) {
910 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700911 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -0800912 } catch (RemoteException e) {
913 Log.w(TAG, "Failed talking with device policy service", e);
914 }
915 }
916 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700917
Dianne Hackbornd6847842010-01-12 18:14:19 -0800918 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800919 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -0700920 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800921 * but requires additional policies after an upgrade.
922 *
923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
924 * an active administrator, or an exception will be thrown.
925 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
926 */
Robin Lee25e26452015-06-02 09:56:29 -0700927 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800928 if (mService != null) {
929 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700930 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800931 } catch (RemoteException e) {
932 Log.w(TAG, "Failed talking with device policy service", e);
933 }
934 }
935 return false;
936 }
937
938 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800939 * Constant for {@link #setPasswordQuality}: the policy has no requirements
940 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800941 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800942 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800943 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700944
Dianne Hackbornd6847842010-01-12 18:14:19 -0800945 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700946 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
947 * recognition technology. This implies technologies that can recognize the identity of
948 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
949 * Note that quality constants are ordered so that higher values are more restrictive.
950 */
951 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
952
953 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800954 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +0100955 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800956 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800957 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800958 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700959
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800960 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800961 * Constant for {@link #setPasswordQuality}: the user must have entered a
962 * password containing at least numeric characters. Note that quality
963 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800964 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800965 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700966
Dianne Hackbornd6847842010-01-12 18:14:19 -0800967 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800968 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -0800969 * password containing at least numeric characters with no repeating (4444)
970 * or ordered (1234, 4321, 2468) sequences. Note that quality
971 * constants are ordered so that higher values are more restrictive.
972 */
973 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
974
975 /**
976 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700977 * password containing at least alphabetic (or other symbol) characters.
978 * Note that quality constants are ordered so that higher values are more
979 * restrictive.
980 */
981 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700982
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700983 /**
984 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800985 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700986 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800987 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800988 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -0700989 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700990
Dianne Hackbornd6847842010-01-12 18:14:19 -0800991 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -0700992 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -0700993 * password containing at least a letter, a numerical digit and a special
994 * symbol, by default. With this password quality, passwords can be
995 * restricted to contain various sets of characters, like at least an
996 * uppercase letter, etc. These are specified using various methods,
997 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
998 * that quality constants are ordered so that higher values are more
999 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001000 */
1001 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1002
1003 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001004 * Called by an application that is administering the device to set the
1005 * password restrictions it is imposing. After setting this, the user
1006 * will not be able to enter a new password that is not at least as
1007 * restrictive as what has been set. Note that the current password
1008 * will remain until the user has set a new one, so the change does not
1009 * take place immediately. To prompt the user for a new password, use
1010 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001011 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001012 * <p>Quality constants are ordered so that higher values are more restrictive;
1013 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001014 * the user's preference, and any other considerations) is the one that
1015 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001016 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001017 * <p>The calling device admin must have requested
1018 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1019 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001020 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001021 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001022 * @param quality The new desired quality. One of
1023 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001024 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1025 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1026 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001027 */
Robin Lee25e26452015-06-02 09:56:29 -07001028 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001029 if (mService != null) {
1030 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001031 mService.setPasswordQuality(admin, quality);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001032 } catch (RemoteException e) {
1033 Log.w(TAG, "Failed talking with device policy service", e);
1034 }
1035 }
1036 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001037
Dianne Hackbornd6847842010-01-12 18:14:19 -08001038 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001039 * Retrieve the current minimum password quality for all admins of this user
1040 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001041 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001042 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001043 */
Robin Lee25e26452015-06-02 09:56:29 -07001044 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001045 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001046 }
1047
1048 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001049 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001050 if (mService != null) {
1051 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001052 return mService.getPasswordQuality(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001053 } catch (RemoteException e) {
1054 Log.w(TAG, "Failed talking with device policy service", e);
1055 }
1056 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001057 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 * Called by an application that is administering the device to set the
1062 * minimum allowed password length. After setting this, the user
1063 * will not be able to enter a new password that is not at least as
1064 * restrictive as what has been set. Note that the current password
1065 * will remain until the user has set a new one, so the change does not
1066 * take place immediately. To prompt the user for a new password, use
1067 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1068 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001069 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1070 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1071 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001072 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001073 * <p>The calling device admin must have requested
1074 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1075 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001076 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001078 * @param length The new desired minimum password length. A value of 0
1079 * means there is no restriction.
1080 */
Robin Lee25e26452015-06-02 09:56:29 -07001081 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001082 if (mService != null) {
1083 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001084 mService.setPasswordMinimumLength(admin, length);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001085 } catch (RemoteException e) {
1086 Log.w(TAG, "Failed talking with device policy service", e);
1087 }
1088 }
1089 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001090
Dianne Hackbornd6847842010-01-12 18:14:19 -08001091 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001092 * Retrieve the current minimum password length for all admins of this
1093 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001094 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001095 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001096 */
Robin Lee25e26452015-06-02 09:56:29 -07001097 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001098 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001099 }
1100
1101 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001102 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001103 if (mService != null) {
1104 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001105 return mService.getPasswordMinimumLength(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001106 } catch (RemoteException e) {
1107 Log.w(TAG, "Failed talking with device policy service", e);
1108 }
1109 }
1110 return 0;
1111 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001112
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001113 /**
1114 * Called by an application that is administering the device to set the
1115 * minimum number of upper case letters required in the password. After
1116 * setting this, the user will not be able to enter a new password that is
1117 * not at least as restrictive as what has been set. Note that the current
1118 * password will remain until the user has set a new one, so the change does
1119 * not take place immediately. To prompt the user for a new password, use
1120 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1121 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001122 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1123 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001124 * <p>
1125 * The calling device admin must have requested
1126 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1127 * this method; if it has not, a security exception will be thrown.
1128 *
1129 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1130 * with.
1131 * @param length The new desired minimum number of upper case letters
1132 * required in the password. A value of 0 means there is no
1133 * restriction.
1134 */
Robin Lee25e26452015-06-02 09:56:29 -07001135 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001136 if (mService != null) {
1137 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001138 mService.setPasswordMinimumUpperCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001139 } catch (RemoteException e) {
1140 Log.w(TAG, "Failed talking with device policy service", e);
1141 }
1142 }
1143 }
1144
1145 /**
1146 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001147 * password for all admins of this user and its profiles or a particular one.
1148 * This is the same value as set by
1149 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001150 * and only applies when the password quality is
1151 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001152 *
Robin Lee25e26452015-06-02 09:56:29 -07001153 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001154 * aggregate all admins.
1155 * @return The minimum number of upper case letters required in the
1156 * password.
1157 */
Robin Lee25e26452015-06-02 09:56:29 -07001158 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001159 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001160 }
1161
1162 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001163 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001164 if (mService != null) {
1165 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001166 return mService.getPasswordMinimumUpperCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001167 } catch (RemoteException e) {
1168 Log.w(TAG, "Failed talking with device policy service", e);
1169 }
1170 }
1171 return 0;
1172 }
1173
1174 /**
1175 * Called by an application that is administering the device to set the
1176 * minimum number of lower case letters required in the password. After
1177 * setting this, the user will not be able to enter a new password that is
1178 * not at least as restrictive as what has been set. Note that the current
1179 * password will remain until the user has set a new one, so the change does
1180 * not take place immediately. To prompt the user for a new password, use
1181 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1182 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001183 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1184 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001185 * <p>
1186 * The calling device admin must have requested
1187 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1188 * this method; if it has not, a security exception will be thrown.
1189 *
1190 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1191 * with.
1192 * @param length The new desired minimum number of lower case letters
1193 * required in the password. A value of 0 means there is no
1194 * restriction.
1195 */
Robin Lee25e26452015-06-02 09:56:29 -07001196 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001197 if (mService != null) {
1198 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001199 mService.setPasswordMinimumLowerCase(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001200 } catch (RemoteException e) {
1201 Log.w(TAG, "Failed talking with device policy service", e);
1202 }
1203 }
1204 }
1205
1206 /**
1207 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001208 * password for all admins of this user and its profiles or a particular one.
1209 * This is the same value as set by
1210 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001211 * and only applies when the password quality is
1212 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001213 *
Robin Lee25e26452015-06-02 09:56:29 -07001214 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001215 * aggregate all admins.
1216 * @return The minimum number of lower case letters required in the
1217 * password.
1218 */
Robin Lee25e26452015-06-02 09:56:29 -07001219 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001220 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001221 }
1222
1223 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001224 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001225 if (mService != null) {
1226 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001227 return mService.getPasswordMinimumLowerCase(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001228 } catch (RemoteException e) {
1229 Log.w(TAG, "Failed talking with device policy service", e);
1230 }
1231 }
1232 return 0;
1233 }
1234
1235 /**
1236 * Called by an application that is administering the device to set the
1237 * minimum number of letters required in the password. After setting this,
1238 * the user will not be able to enter a new password that is not at least as
1239 * restrictive as what has been set. Note that the current password will
1240 * remain until the user has set a new one, so the change does not take
1241 * place immediately. To prompt the user for a new password, use
1242 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1243 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001244 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1245 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001246 * <p>
1247 * The calling device admin must have requested
1248 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1249 * this method; if it has not, a security exception will be thrown.
1250 *
1251 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1252 * with.
1253 * @param length The new desired minimum number of letters required in the
1254 * password. A value of 0 means there is no restriction.
1255 */
Robin Lee25e26452015-06-02 09:56:29 -07001256 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001257 if (mService != null) {
1258 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001259 mService.setPasswordMinimumLetters(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001260 } catch (RemoteException e) {
1261 Log.w(TAG, "Failed talking with device policy service", e);
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001268 * admins or a particular one. This is the same value as
1269 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1270 * and only applies when the password quality is
1271 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001272 *
Robin Lee25e26452015-06-02 09:56:29 -07001273 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001274 * aggregate all admins.
1275 * @return The minimum number of letters required in the password.
1276 */
Robin Lee25e26452015-06-02 09:56:29 -07001277 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001278 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001279 }
1280
1281 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001282 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 if (mService != null) {
1284 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001285 return mService.getPasswordMinimumLetters(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001286 } catch (RemoteException e) {
1287 Log.w(TAG, "Failed talking with device policy service", e);
1288 }
1289 }
1290 return 0;
1291 }
1292
1293 /**
1294 * Called by an application that is administering the device to set the
1295 * minimum number of numerical digits required in the password. After
1296 * setting this, the user will not be able to enter a new password that is
1297 * not at least as restrictive as what has been set. Note that the current
1298 * password will remain until the user has set a new one, so the change does
1299 * not take place immediately. To prompt the user for a new password, use
1300 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1301 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001302 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1303 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001304 * <p>
1305 * The calling device admin must have requested
1306 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1307 * this method; if it has not, a security exception will be thrown.
1308 *
1309 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1310 * with.
1311 * @param length The new desired minimum number of numerical digits required
1312 * in the password. A value of 0 means there is no restriction.
1313 */
Robin Lee25e26452015-06-02 09:56:29 -07001314 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001315 if (mService != null) {
1316 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001317 mService.setPasswordMinimumNumeric(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001318 } catch (RemoteException e) {
1319 Log.w(TAG, "Failed talking with device policy service", e);
1320 }
1321 }
1322 }
1323
1324 /**
1325 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001326 * for all admins of this user and its profiles or a particular one.
1327 * This is the same value as set by
1328 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001329 * and only applies when the password quality is
1330 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001331 *
Robin Lee25e26452015-06-02 09:56:29 -07001332 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001333 * aggregate all admins.
1334 * @return The minimum number of numerical digits required in the password.
1335 */
Robin Lee25e26452015-06-02 09:56:29 -07001336 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001337 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001338 }
1339
1340 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001341 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001342 if (mService != null) {
1343 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001344 return mService.getPasswordMinimumNumeric(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001345 } catch (RemoteException e) {
1346 Log.w(TAG, "Failed talking with device policy service", e);
1347 }
1348 }
1349 return 0;
1350 }
1351
1352 /**
1353 * Called by an application that is administering the device to set the
1354 * minimum number of symbols required in the password. After setting this,
1355 * the user will not be able to enter a new password that is not at least as
1356 * restrictive as what has been set. Note that the current password will
1357 * remain until the user has set a new one, so the change does not take
1358 * place immediately. To prompt the user for a new password, use
1359 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1360 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001361 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1362 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001363 * <p>
1364 * The calling device admin must have requested
1365 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1366 * this method; if it has not, a security exception will be thrown.
1367 *
1368 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1369 * with.
1370 * @param length The new desired minimum number of symbols required in the
1371 * password. A value of 0 means there is no restriction.
1372 */
Robin Lee25e26452015-06-02 09:56:29 -07001373 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001374 if (mService != null) {
1375 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001376 mService.setPasswordMinimumSymbols(admin, length);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001377 } catch (RemoteException e) {
1378 Log.w(TAG, "Failed talking with device policy service", e);
1379 }
1380 }
1381 }
1382
1383 /**
1384 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001385 * admins or a particular one. This is the same value as
1386 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1387 * and only applies when the password quality is
1388 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001389 *
Robin Lee25e26452015-06-02 09:56:29 -07001390 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001391 * aggregate all admins.
1392 * @return The minimum number of symbols required in the password.
1393 */
Robin Lee25e26452015-06-02 09:56:29 -07001394 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001395 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001396 }
1397
1398 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001399 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 if (mService != null) {
1401 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001402 return mService.getPasswordMinimumSymbols(admin, userHandle);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001403 } catch (RemoteException e) {
1404 Log.w(TAG, "Failed talking with device policy service", e);
1405 }
1406 }
1407 return 0;
1408 }
1409
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001410 /**
1411 * Called by an application that is administering the device to set the
1412 * minimum number of non-letter characters (numerical digits or symbols)
1413 * required in the password. After setting this, the user will not be able
1414 * to enter a new password that is not at least as restrictive as what has
1415 * been set. Note that the current password will remain until the user has
1416 * set a new one, so the change does not take place immediately. To prompt
1417 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1418 * setting this value. This constraint is only imposed if the administrator
1419 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1420 * {@link #setPasswordQuality}. The default value is 0.
1421 * <p>
1422 * The calling device admin must have requested
1423 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1424 * this method; if it has not, a security exception will be thrown.
1425 *
1426 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1427 * with.
1428 * @param length The new desired minimum number of letters required in the
1429 * password. A value of 0 means there is no restriction.
1430 */
Robin Lee25e26452015-06-02 09:56:29 -07001431 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001432 if (mService != null) {
1433 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001434 mService.setPasswordMinimumNonLetter(admin, length);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001435 } catch (RemoteException e) {
1436 Log.w(TAG, "Failed talking with device policy service", e);
1437 }
1438 }
1439 }
1440
1441 /**
1442 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001443 * password for all admins of this user and its profiles or a particular one.
1444 * This is the same value as set by
1445 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001446 * and only applies when the password quality is
1447 * {@link #PASSWORD_QUALITY_COMPLEX}.
1448 *
Robin Lee25e26452015-06-02 09:56:29 -07001449 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001450 * aggregate all admins.
1451 * @return The minimum number of letters required in the password.
1452 */
Robin Lee25e26452015-06-02 09:56:29 -07001453 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001454 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001455 }
1456
1457 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001458 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001459 if (mService != null) {
1460 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001461 return mService.getPasswordMinimumNonLetter(admin, userHandle);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001462 } catch (RemoteException e) {
1463 Log.w(TAG, "Failed talking with device policy service", e);
1464 }
1465 }
1466 return 0;
1467 }
1468
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001469 /**
1470 * Called by an application that is administering the device to set the length
1471 * of the password history. After setting this, the user will not be able to
1472 * enter a new password that is the same as any password in the history. Note
1473 * that the current password will remain until the user has set a new one, so
1474 * the change does not take place immediately. To prompt the user for a new
1475 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1476 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001477 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1478 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1479 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001480 *
1481 * <p>
1482 * The calling device admin must have requested
1483 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1484 * method; if it has not, a security exception will be thrown.
1485 *
1486 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1487 * with.
1488 * @param length The new desired length of password history. A value of 0
1489 * means there is no restriction.
1490 */
Robin Lee25e26452015-06-02 09:56:29 -07001491 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001492 if (mService != null) {
1493 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001494 mService.setPasswordHistoryLength(admin, length);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001495 } catch (RemoteException e) {
1496 Log.w(TAG, "Failed talking with device policy service", e);
1497 }
1498 }
1499 }
1500
1501 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001502 * Called by a device admin to set the password expiration timeout. Calling this method
1503 * will restart the countdown for password expiration for the given admin, as will changing
1504 * the device password (for all admins).
1505 *
1506 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1507 * For example, to have the password expire 5 days from now, timeout would be
1508 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1509 *
1510 * <p>To disable password expiration, a value of 0 may be used for timeout.
1511 *
Jim Millera4e28d12010-11-08 16:15:47 -08001512 * <p>The calling device admin must have requested
1513 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1514 * method; if it has not, a security exception will be thrown.
1515 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001516 * <p> Note that setting the password will automatically reset the expiration time for all
1517 * active admins. Active admins do not need to explicitly call this method in that case.
1518 *
Jim Millera4e28d12010-11-08 16:15:47 -08001519 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1520 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1521 * means there is no restriction (unlimited).
1522 */
Robin Lee25e26452015-06-02 09:56:29 -07001523 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001524 if (mService != null) {
1525 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001526 mService.setPasswordExpirationTimeout(admin, timeout);
Jim Millera4e28d12010-11-08 16:15:47 -08001527 } catch (RemoteException e) {
1528 Log.w(TAG, "Failed talking with device policy service", e);
1529 }
1530 }
1531 }
1532
1533 /**
Jim Miller6b857682011-02-16 16:27:41 -08001534 * Get the password expiration timeout for the given admin. The expiration timeout is the
1535 * recurring expiration timeout provided in the call to
1536 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001537 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001538 *
Robin Lee25e26452015-06-02 09:56:29 -07001539 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001540 * @return The timeout for the given admin or the minimum of all timeouts
1541 */
Robin Lee25e26452015-06-02 09:56:29 -07001542 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001543 if (mService != null) {
1544 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001545 return mService.getPasswordExpirationTimeout(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001546 } catch (RemoteException e) {
1547 Log.w(TAG, "Failed talking with device policy service", e);
1548 }
1549 }
1550 return 0;
1551 }
1552
1553 /**
1554 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001555 * all admins of this user and its profiles if admin is null. If the password is
1556 * expired, this will return the time since the password expired as a negative number.
1557 * If admin is null, then a composite of all expiration timeouts is returned
1558 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001559 *
Robin Lee25e26452015-06-02 09:56:29 -07001560 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001561 * @return The password expiration time, in ms.
1562 */
Robin Lee25e26452015-06-02 09:56:29 -07001563 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001564 if (mService != null) {
1565 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001566 return mService.getPasswordExpiration(admin, myUserId());
Jim Millera4e28d12010-11-08 16:15:47 -08001567 } catch (RemoteException e) {
1568 Log.w(TAG, "Failed talking with device policy service", e);
1569 }
1570 }
1571 return 0;
1572 }
1573
1574 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001575 * Retrieve the current password history length for all admins of this
1576 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001577 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001578 * all admins.
1579 * @return The length of the password history
1580 */
Robin Lee25e26452015-06-02 09:56:29 -07001581 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001582 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001583 }
1584
1585 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001586 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001587 if (mService != null) {
1588 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001589 return mService.getPasswordHistoryLength(admin, userHandle);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001590 } catch (RemoteException e) {
1591 Log.w(TAG, "Failed talking with device policy service", e);
1592 }
1593 }
1594 return 0;
1595 }
1596
Dianne Hackbornd6847842010-01-12 18:14:19 -08001597 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001598 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001599 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001600 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001601 * @return Returns the maximum length that the user can enter.
1602 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001603 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001604 // Kind-of arbitrary.
1605 return 16;
1606 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001607
Dianne Hackborn254cb442010-01-27 19:23:59 -08001608 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001609 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001610 * to meet the policy requirements (quality, minimum length) that have been
Jessica Hummel91da58d2014-04-10 17:39:43 +01001611 * requested by the admins of this user and its profiles.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001612 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001613 * <p>The calling device admin must have requested
1614 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1615 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001616 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001617 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001618 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001619 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 if (mService != null) {
1621 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001622 return mService.isActivePasswordSufficient(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 } catch (RemoteException e) {
1624 Log.w(TAG, "Failed talking with device policy service", e);
1625 }
1626 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001627 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001628 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001629
Dianne Hackbornd6847842010-01-12 18:14:19 -08001630 /**
1631 * Retrieve the number of times the user has failed at entering a
1632 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001633 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001634 * <p>The calling device admin must have requested
1635 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1636 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001637 */
1638 public int getCurrentFailedPasswordAttempts() {
1639 if (mService != null) {
1640 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001641 return mService.getCurrentFailedPasswordAttempts(myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001642 } catch (RemoteException e) {
1643 Log.w(TAG, "Failed talking with device policy service", e);
1644 }
1645 }
1646 return -1;
1647 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001648
1649 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001650 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001651 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001652 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001653 * @hide
1654 */
1655 public boolean getDoNotAskCredentialsOnBoot() {
1656 if (mService != null) {
1657 try {
1658 return mService.getDoNotAskCredentialsOnBoot();
1659 } catch (RemoteException e) {
1660 Log.w(TAG, "Failed to call getDoNotAskCredentialsOnBoot()", e);
1661 }
1662 }
1663 return false;
1664 }
1665
1666 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001667 * Setting this to a value greater than zero enables a built-in policy
1668 * that will perform a device wipe after too many incorrect
1669 * device-unlock passwords have been entered. This built-in policy combines
1670 * watching for failed passwords and wiping the device, and requires
1671 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001672 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001673 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001674 * <p>To implement any other policy (e.g. wiping data for a particular
1675 * application only, erasing or revoking credentials, or reporting the
1676 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001677 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001678 * instead. Do not use this API, because if the maximum count is reached,
1679 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001680 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001681 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001682 * @param num The number of failed password attempts at which point the
1683 * device will wipe its data.
1684 */
Robin Lee25e26452015-06-02 09:56:29 -07001685 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001686 if (mService != null) {
1687 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001688 mService.setMaximumFailedPasswordsForWipe(admin, num);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001689 } catch (RemoteException e) {
1690 Log.w(TAG, "Failed talking with device policy service", e);
1691 }
1692 }
1693 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001694
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001695 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001696 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001697 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001698 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001699 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001700 * all admins.
1701 */
Robin Lee25e26452015-06-02 09:56:29 -07001702 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001703 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001704 }
1705
1706 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001707 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001708 if (mService != null) {
1709 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001710 return mService.getMaximumFailedPasswordsForWipe(admin, userHandle);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001711 } catch (RemoteException e) {
1712 Log.w(TAG, "Failed talking with device policy service", e);
1713 }
1714 }
1715 return 0;
1716 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001717
Dianne Hackborn254cb442010-01-27 19:23:59 -08001718 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001719 * Returns the profile with the smallest maximum failed passwords for wipe,
1720 * for the given user. So for primary user, it might return the primary or
1721 * a managed profile. For a secondary user, it would be the same as the
1722 * user passed in.
1723 * @hide Used only by Keyguard
1724 */
1725 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1726 if (mService != null) {
1727 try {
1728 return mService.getProfileWithMinimumFailedPasswordsForWipe(userHandle);
1729 } catch (RemoteException e) {
1730 Log.w(TAG, "Failed talking with device policy service", e);
1731 }
1732 }
1733 return UserHandle.USER_NULL;
1734 }
1735
1736 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001737 * Flag for {@link #resetPassword}: don't allow other admins to change
1738 * the password again until the user has entered it.
1739 */
1740 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001741
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001742 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001743 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1744 * If the flag is set, the device can be booted without asking for user password.
1745 * The absence of this flag does not change the current boot requirements. This flag
1746 * can be set by the device owner only. If the app is not the device owner, the flag
1747 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1748 * device to factory defaults.
1749 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001750 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001751
1752 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001753 * Force a new device unlock password (the password needed to access the
1754 * entire device, not for individual accounts) on the user. This takes
1755 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001756 *
1757 * <p>Calling this from a managed profile that shares the password with the owner profile
1758 * will throw a security exception.
1759 *
1760 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1761 * device admins that are not device owner and not profile owner.
1762 * The password can now only be changed if there is currently no password set. Device owner
1763 * and profile owner can still do this.</em>
1764 *
1765 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001766 * current password quality and length constraints as returned by
1767 * {@link #getPasswordQuality(ComponentName)} and
1768 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1769 * these constraints, then it will be rejected and false returned. Note
1770 * that the password may be a stronger quality (containing alphanumeric
1771 * characters when the requested quality is only numeric), in which case
1772 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001773 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001774 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001775 * pattern or password if the current password constraints allow it. <em>Note: This will not
1776 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1777 * device owner and not profile owner. Once set, the password cannot be changed to null or
1778 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001779 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001780 * <p>The calling device admin must have requested
1781 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1782 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001783 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001784 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001785 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001786 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001787 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001788 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001789 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001790 public boolean resetPassword(String password, int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001791 if (mService != null) {
1792 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001793 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001794 } catch (RemoteException e) {
1795 Log.w(TAG, "Failed talking with device policy service", e);
1796 }
1797 }
1798 return false;
1799 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001800
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 /**
1802 * Called by an application that is administering the device to set the
1803 * maximum time for user activity until the device will lock. This limits
1804 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001805 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001806 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001807 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001808 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001809 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 * @param timeMs The new desired maximum time to lock in milliseconds.
1812 * A value of 0 means there is no restriction.
1813 */
Robin Lee25e26452015-06-02 09:56:29 -07001814 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001815 if (mService != null) {
1816 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001817 mService.setMaximumTimeToLock(admin, timeMs);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001818 } catch (RemoteException e) {
1819 Log.w(TAG, "Failed talking with device policy service", e);
1820 }
1821 }
1822 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001823
Dianne Hackbornd6847842010-01-12 18:14:19 -08001824 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001825 * Retrieve the current maximum time to unlock for all admins of this user
1826 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001827 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001828 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001829 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001830 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001831 */
Robin Lee25e26452015-06-02 09:56:29 -07001832 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001833 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001834 }
1835
1836 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001837 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001838 if (mService != null) {
1839 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001840 return mService.getMaximumTimeToLock(admin, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001841 } catch (RemoteException e) {
1842 Log.w(TAG, "Failed talking with device policy service", e);
1843 }
1844 }
1845 return 0;
1846 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001847
Dianne Hackbornd6847842010-01-12 18:14:19 -08001848 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001849 * Make the device lock immediately, as if the lock screen timeout has
1850 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001851 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001852 * <p>The calling device admin must have requested
1853 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
1854 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001855 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001856 public void lockNow() {
1857 if (mService != null) {
1858 try {
1859 mService.lockNow();
1860 } catch (RemoteException e) {
1861 Log.w(TAG, "Failed talking with device policy service", e);
1862 }
1863 }
1864 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001865
Dianne Hackbornd6847842010-01-12 18:14:19 -08001866 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07001867 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001868 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07001869 */
1870 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
1871
1872 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001873 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
1874 * data.
1875 *
Paul Crowley2934b262014-12-02 11:21:13 +00001876 * <p>This flag may only be set by device owner admins; if it is set by
1877 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001878 */
1879 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
1880
1881 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00001882 * Ask the user data be wiped. Wiping the primary user will cause the
1883 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001884 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001885 * <p>The calling device admin must have requested
1886 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
1887 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001888 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00001889 * @param flags Bit mask of additional options: currently supported flags
1890 * are {@link #WIPE_EXTERNAL_STORAGE} and
1891 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001892 */
1893 public void wipeData(int flags) {
1894 if (mService != null) {
1895 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08001896 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001897 } catch (RemoteException e) {
1898 Log.w(TAG, "Failed talking with device policy service", e);
1899 }
1900 }
1901 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001902
Dianne Hackbornd6847842010-01-12 18:14:19 -08001903 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07001904 * Called by an application that is administering the device to set the
1905 * global proxy and exclusion list.
1906 * <p>
1907 * The calling device admin must have requested
1908 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
1909 * this method; if it has not, a security exception will be thrown.
1910 * Only the first device admin can set the proxy. If a second admin attempts
1911 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07001912 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07001913 * be returned.
1914 * The method can be called repeatedly by the device admin alrady setting the
1915 * proxy to update the proxy and exclusion list.
1916 *
Robin Lee25e26452015-06-02 09:56:29 -07001917 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07001918 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
1919 * Pass Proxy.NO_PROXY to reset the proxy.
1920 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07001921 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
1922 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08001923 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07001924 */
Robin Lee25e26452015-06-02 09:56:29 -07001925 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07001926 List<String> exclusionList ) {
1927 if (proxySpec == null) {
1928 throw new NullPointerException();
1929 }
1930 if (mService != null) {
1931 try {
1932 String hostSpec;
1933 String exclSpec;
1934 if (proxySpec.equals(Proxy.NO_PROXY)) {
1935 hostSpec = null;
1936 exclSpec = null;
1937 } else {
1938 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
1939 throw new IllegalArgumentException();
1940 }
1941 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
1942 String hostName = sa.getHostName();
1943 int port = sa.getPort();
1944 StringBuilder hostBuilder = new StringBuilder();
1945 hostSpec = hostBuilder.append(hostName)
1946 .append(":").append(Integer.toString(port)).toString();
1947 if (exclusionList == null) {
1948 exclSpec = "";
1949 } else {
1950 StringBuilder listBuilder = new StringBuilder();
1951 boolean firstDomain = true;
1952 for (String exclDomain : exclusionList) {
1953 if (!firstDomain) {
1954 listBuilder = listBuilder.append(",");
1955 } else {
1956 firstDomain = false;
1957 }
1958 listBuilder = listBuilder.append(exclDomain.trim());
1959 }
1960 exclSpec = listBuilder.toString();
1961 }
Yuhao Zheng90704842014-02-28 17:22:45 -08001962 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
1963 != android.net.Proxy.PROXY_VALID)
1964 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07001965 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001966 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07001967 } catch (RemoteException e) {
1968 Log.w(TAG, "Failed talking with device policy service", e);
1969 }
1970 }
1971 return null;
1972 }
1973
1974 /**
Jason Monk03bc9912014-05-13 09:44:57 -04001975 * Set a network-independent global HTTP proxy. This is not normally what you want
1976 * for typical HTTP proxies - they are generally network dependent. However if you're
1977 * doing something unusual like general internal filtering this may be useful. On
1978 * a private network where the proxy is not accessible, you may break HTTP using this.
1979 *
1980 * <p>This method requires the caller to be the device owner.
1981 *
1982 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
1983 * @see ProxyInfo
1984 *
1985 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1986 * with.
1987 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
1988 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1989 */
Robin Lee25e26452015-06-02 09:56:29 -07001990 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
1991 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04001992 if (mService != null) {
1993 try {
1994 mService.setRecommendedGlobalProxy(admin, proxyInfo);
1995 } catch (RemoteException e) {
1996 Log.w(TAG, "Failed talking with device policy service", e);
1997 }
1998 }
1999 }
2000
2001 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002002 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002003 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2004 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002005 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002006 */
2007 public ComponentName getGlobalProxyAdmin() {
2008 if (mService != null) {
2009 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002010 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002011 } catch (RemoteException e) {
2012 Log.w(TAG, "Failed talking with device policy service", e);
2013 }
2014 }
2015 return null;
2016 }
2017
2018 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002019 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002020 * indicating that encryption is not supported.
2021 */
2022 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2023
2024 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002025 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002026 * indicating that encryption is supported, but is not currently active.
2027 */
2028 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2029
2030 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002031 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002032 * indicating that encryption is not currently active, but is currently
2033 * being activated. This is only reported by devices that support
2034 * encryption of data and only when the storage is currently
2035 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2036 * to become encrypted will never return this value.
2037 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002038 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002039
2040 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002041 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002042 * indicating that encryption is active.
2043 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002044 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002045
2046 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002047 * Result code for {@link #getStorageEncryptionStatus}:
2048 * indicating that encryption is active, but an encryption key has not
2049 * been set by the user.
2050 */
2051 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2052
2053 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002054 * Activity action: begin the process of encrypting data on the device. This activity should
2055 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2056 * After resuming from this activity, use {@link #getStorageEncryption}
2057 * to check encryption status. However, on some devices this activity may never return, as
2058 * it may trigger a reboot and in some cases a complete data wipe of the device.
2059 */
2060 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2061 public static final String ACTION_START_ENCRYPTION
2062 = "android.app.action.START_ENCRYPTION";
2063
2064 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002065 * Widgets are enabled in keyguard
2066 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002067 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002068
2069 /**
Jim Miller50e62182014-04-23 17:25:00 -07002070 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002071 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002072 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2073
2074 /**
2075 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2076 */
2077 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2078
2079 /**
Jim Miller50e62182014-04-23 17:25:00 -07002080 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2081 */
2082 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2083
2084 /**
2085 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2086 */
2087 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2088
2089 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002090 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002091 * (e.g. PIN/Pattern/Password).
2092 */
2093 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2094
2095 /**
Jim Miller06e34502014-07-17 14:46:05 -07002096 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2097 */
2098 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2099
2100 /**
Jim Miller35207742012-11-02 15:33:20 -07002101 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002102 */
2103 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002104
2105 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002106 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002107 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002108 *
2109 * <p>When multiple device administrators attempt to control device
2110 * encryption, the most secure, supported setting will always be
2111 * used. If any device administrator requests device encryption,
2112 * it will be enabled; Conversely, if a device administrator
2113 * attempts to disable device encryption while another
2114 * device administrator has enabled it, the call to disable will
2115 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2116 *
2117 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002118 * written to other storage areas may or may not be encrypted, and this policy does not require
2119 * or control the encryption of any other storage areas.
2120 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2121 * {@code true}, then the directory returned by
2122 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2123 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002124 *
2125 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2126 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2127 * the encryption key may not be fully secured. For maximum security, the administrator should
2128 * also require (and check for) a pattern, PIN, or password.
2129 *
2130 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2131 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002132 * @return the new request status (for all active admins) - will be one of
2133 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2134 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2135 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002136 */
Robin Lee25e26452015-06-02 09:56:29 -07002137 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002138 if (mService != null) {
2139 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002140 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002141 } catch (RemoteException e) {
2142 Log.w(TAG, "Failed talking with device policy service", e);
2143 }
2144 }
2145 return ENCRYPTION_STATUS_UNSUPPORTED;
2146 }
2147
2148 /**
2149 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002150 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002151 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002152 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2153 * this will return the requested encryption setting as an aggregate of all active
2154 * administrators.
2155 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002156 */
Robin Lee25e26452015-06-02 09:56:29 -07002157 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002158 if (mService != null) {
2159 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002160 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002161 } catch (RemoteException e) {
2162 Log.w(TAG, "Failed talking with device policy service", e);
2163 }
2164 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002165 return false;
2166 }
2167
2168 /**
2169 * Called by an application that is administering the device to
2170 * determine the current encryption status of the device.
2171 *
2172 * Depending on the returned status code, the caller may proceed in different
2173 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2174 * storage system does not support encryption. If the
2175 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2176 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002177 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2178 * storage system has enabled encryption but no password is set so further action
2179 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002180 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2181 *
Robin Lee7e678712014-07-24 16:41:31 +01002182 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002183 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002184 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2185 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002186 */
2187 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002188 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002189 }
2190
2191 /** @hide per-user version */
2192 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002193 if (mService != null) {
2194 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002195 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002196 } catch (RemoteException e) {
2197 Log.w(TAG, "Failed talking with device policy service", e);
2198 }
2199 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002200 return ENCRYPTION_STATUS_UNSUPPORTED;
2201 }
2202
2203 /**
Robin Lee7e678712014-07-24 16:41:31 +01002204 * Installs the given certificate as a user CA.
2205 *
Robin Lee25e26452015-06-02 09:56:29 -07002206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2207 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002208 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002209 *
2210 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002211 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002212 */
Robin Lee25e26452015-06-02 09:56:29 -07002213 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002214 if (mService != null) {
2215 try {
Robin Lee7e678712014-07-24 16:41:31 +01002216 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002217 } catch (RemoteException e) {
2218 Log.w(TAG, "Failed talking with device policy service", e);
2219 }
2220 }
2221 return false;
2222 }
2223
2224 /**
Robin Lee7e678712014-07-24 16:41:31 +01002225 * Uninstalls the given certificate from trusted user CAs, if present.
2226 *
Robin Lee25e26452015-06-02 09:56:29 -07002227 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2228 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002229 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002230 */
Robin Lee25e26452015-06-02 09:56:29 -07002231 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002232 if (mService != null) {
2233 try {
Robin Lee306fe082014-06-19 14:04:24 +00002234 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002235 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002236 } catch (CertificateException e) {
2237 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002238 } catch (RemoteException e) {
2239 Log.w(TAG, "Failed talking with device policy service", e);
2240 }
2241 }
2242 }
2243
2244 /**
Robin Lee7e678712014-07-24 16:41:31 +01002245 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2246 * If a user has installed any certificates by other means than device policy these will be
2247 * included too.
2248 *
Robin Lee25e26452015-06-02 09:56:29 -07002249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2250 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002251 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002252 */
Robin Lee25e26452015-06-02 09:56:29 -07002253 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002254 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002255 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002256 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002257 mService.enforceCanManageCaCerts(admin);
2258 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2259 for (String alias : certStore.userAliases()) {
2260 try {
2261 certs.add(certStore.getCertificate(alias).getEncoded());
2262 } catch (CertificateException ce) {
2263 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2264 }
2265 }
2266 } catch (RemoteException re) {
2267 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002268 }
2269 }
2270 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002271 }
2272
2273 /**
Robin Lee7e678712014-07-24 16:41:31 +01002274 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2275 * means other than device policy will also be removed, except for system CA certificates.
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 */
Robin Lee25e26452015-06-02 09:56:29 -07002280 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002281 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002282 try {
2283 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2284 .toArray(new String[0]));
2285 } catch (RemoteException re) {
2286 Log.w(TAG, "Failed talking with device policy service", re);
Robin Lee7e678712014-07-24 16:41:31 +01002287 }
2288 }
2289 }
2290
2291 /**
2292 * Returns whether this certificate is installed as a trusted CA.
2293 *
Robin Lee25e26452015-06-02 09:56:29 -07002294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2295 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002296 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002297 */
Robin Lee25e26452015-06-02 09:56:29 -07002298 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002299 if (mService != null) {
2300 try {
2301 mService.enforceCanManageCaCerts(admin);
2302 return getCaCertAlias(certBuffer) != null;
2303 } catch (RemoteException re) {
2304 Log.w(TAG, "Failed talking with device policy service", re);
2305 } catch (CertificateException ce) {
2306 Log.w(TAG, "Could not parse certificate", ce);
2307 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002308 }
2309 return false;
2310 }
2311
2312 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002313 * Called by a device or profile owner to install a certificate and private key pair. The
2314 * keypair will be visible to all apps within the profile.
2315 *
Robin Lee25e26452015-06-02 09:56:29 -07002316 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2317 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002318 * @param privKey The private key to install.
2319 * @param cert The certificate to install.
2320 * @param alias The private key alias under which to install the certificate. If a certificate
2321 * with that alias already exists, it will be overwritten.
2322 * @return {@code true} if the keys were installed, {@code false} otherwise.
2323 */
Robin Lee25e26452015-06-02 09:56:29 -07002324 public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002325 String alias) {
2326 try {
2327 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002328 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2329 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002330 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002331 } catch (RemoteException e) {
2332 Log.w(TAG, "Failed talking with device policy service", e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002333 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2334 Log.w(TAG, "Failed to obtain private key material", e);
2335 } catch (CertificateException | IOException e) {
2336 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002337 }
2338 return false;
2339 }
2340
2341 /**
Robin Lee25e26452015-06-02 09:56:29 -07002342 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002343 * doesn't exist.
2344 */
2345 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2346 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2347 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2348 new ByteArrayInputStream(certBuffer));
2349 return new TrustedCertificateStore().getCertificateAlias(cert);
2350 }
2351
2352 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002353 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002354 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002355 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002356 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002357 * <p>
2358 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2359 * it is later cleared by calling this method with a null value or uninstallling the certificate
2360 * installer.
2361 *
Robin Lee25e26452015-06-02 09:56:29 -07002362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002363 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002364 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002365 */
Robin Lee25e26452015-06-02 09:56:29 -07002366 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2367 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002368 if (mService != null) {
2369 try {
Robin Lee25e26452015-06-02 09:56:29 -07002370 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002371 } catch (RemoteException e) {
2372 Log.w(TAG, "Failed talking with device policy service", e);
2373 }
2374 }
2375 }
2376
2377 /**
2378 * Called by a profile owner or device owner to retrieve the certificate installer for the
2379 * current user. null if none is set.
2380 *
Robin Lee25e26452015-06-02 09:56:29 -07002381 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2382 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002383 * if none is set.
2384 */
Robin Lee25e26452015-06-02 09:56:29 -07002385 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002386 if (mService != null) {
2387 try {
Robin Lee25e26452015-06-02 09:56:29 -07002388 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002389 } catch (RemoteException e) {
2390 Log.w(TAG, "Failed talking with device policy service", e);
2391 }
2392 }
2393 return null;
2394 }
2395
2396 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002397 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002398 * on the device, for this user. After setting this, no applications running as this user
2399 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002400 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002401 * <p>If the caller is device owner, then the restriction will be applied to all users.
2402 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002403 * <p>The calling device admin must have requested
2404 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2405 * this method; if it has not, a security exception will be thrown.
2406 *
2407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2408 * @param disabled Whether or not the camera should be disabled.
2409 */
Robin Lee25e26452015-06-02 09:56:29 -07002410 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002411 if (mService != null) {
2412 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002413 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002414 } catch (RemoteException e) {
2415 Log.w(TAG, "Failed talking with device policy service", e);
2416 }
2417 }
2418 }
2419
2420 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002421 * Determine whether or not the device's cameras have been disabled for this user,
2422 * either by the current admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002423 * @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 -07002424 * have disabled the camera
2425 */
Robin Lee25e26452015-06-02 09:56:29 -07002426 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002427 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002428 }
2429
2430 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002431 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002432 if (mService != null) {
2433 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002434 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002435 } catch (RemoteException e) {
2436 Log.w(TAG, "Failed talking with device policy service", e);
2437 }
2438 }
2439 return false;
2440 }
2441
2442 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002443 * Determine whether or not creating a guest user has been disabled for the device
2444 *
2445 * @hide
2446 */
2447 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2448 // Currently guest users can always be created if multi-user is enabled
2449 // TODO introduce a policy for guest user creation
2450 return false;
2451 }
2452
2453 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002454 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2455 * screen capture also prevents the content from being shown on display devices that do not have
2456 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2457 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002458 *
2459 * <p>The calling device admin must be a device or profile owner. If it is not, a
2460 * security exception will be thrown.
2461 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002462 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002463 * blocks assist requests for all activities of the relevant user.
2464 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002465 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002466 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002467 */
Robin Lee25e26452015-06-02 09:56:29 -07002468 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002469 if (mService != null) {
2470 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002471 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002472 } catch (RemoteException e) {
2473 Log.w(TAG, "Failed talking with device policy service", e);
2474 }
2475 }
2476 }
2477
2478 /**
2479 * Determine whether or not screen capture has been disabled by the current
2480 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002481 * @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 +01002482 * have disabled screen capture.
2483 */
Robin Lee25e26452015-06-02 09:56:29 -07002484 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002485 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002486 }
2487
2488 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002489 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002490 if (mService != null) {
2491 try {
2492 return mService.getScreenCaptureDisabled(admin, userHandle);
2493 } catch (RemoteException e) {
2494 Log.w(TAG, "Failed talking with device policy service", e);
2495 }
2496 }
2497 return false;
2498 }
2499
2500 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002501 * Called by a device owner to set whether auto time is required. If auto time is
2502 * required the user cannot set the date and time, but has to use network date and time.
2503 *
2504 * <p>Note: if auto time is required the user can still manually set the time zone.
2505 *
2506 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2507 * be thrown.
2508 *
2509 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2510 * @param required Whether auto time is set required or not.
2511 */
Robin Lee25e26452015-06-02 09:56:29 -07002512 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002513 if (mService != null) {
2514 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002515 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002516 } catch (RemoteException e) {
2517 Log.w(TAG, "Failed talking with device policy service", e);
2518 }
2519 }
2520 }
2521
2522 /**
2523 * @return true if auto time is required.
2524 */
2525 public boolean getAutoTimeRequired() {
2526 if (mService != null) {
2527 try {
2528 return mService.getAutoTimeRequired();
2529 } catch (RemoteException e) {
2530 Log.w(TAG, "Failed talking with device policy service", e);
2531 }
2532 }
2533 return false;
2534 }
2535
2536 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002537 * Called by an application that is administering the device to disable keyguard customizations,
2538 * such as widgets. After setting this, keyguard features will be disabled according to the
2539 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002540 *
2541 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002542 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002543 * this method; if it has not, a security exception will be thrown.
2544 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002545 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002546 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002547 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002548 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002549 * <ul>
2550 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2551 * these will affect the profile's parent user.
2552 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2553 * generated by applications in the managed profile.
2554 * </ul>
2555 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2556 * can check which features have been disabled by calling
2557 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002558 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002559 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002560 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2561 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002562 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002563 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2564 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002565 */
Robin Lee25e26452015-06-02 09:56:29 -07002566 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002567 if (mService != null) {
2568 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002569 mService.setKeyguardDisabledFeatures(admin, which);
Jim Millerb8ec4702012-08-31 17:19:10 -07002570 } catch (RemoteException e) {
2571 Log.w(TAG, "Failed talking with device policy service", e);
2572 }
2573 }
2574 }
2575
2576 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002577 * Determine whether or not features have been disabled in keyguard either by the current
Jim Millerb8ec4702012-08-31 17:19:10 -07002578 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002579 * @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 -07002580 * have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002581 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2582 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002583 */
Robin Lee25e26452015-06-02 09:56:29 -07002584 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002585 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002586 }
2587
2588 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002589 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002590 if (mService != null) {
2591 try {
Jim Miller48b9b0d2012-09-19 23:16:50 -07002592 return mService.getKeyguardDisabledFeatures(admin, userHandle);
Jim Millerb8ec4702012-08-31 17:19:10 -07002593 } catch (RemoteException e) {
2594 Log.w(TAG, "Failed talking with device policy service", e);
2595 }
2596 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002597 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002598 }
2599
2600 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002601 * @hide
2602 */
Robin Lee25e26452015-06-02 09:56:29 -07002603 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2604 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002605 if (mService != null) {
2606 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002607 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002608 } catch (RemoteException e) {
2609 Log.w(TAG, "Failed talking with device policy service", e);
2610 }
2611 }
2612 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002613
Dianne Hackbornd6847842010-01-12 18:14:19 -08002614 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002615 * @hide
2616 */
Robin Lee25e26452015-06-02 09:56:29 -07002617 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002618 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002619 }
2620
2621 /**
Robin Lee25e26452015-06-02 09:56:29 -07002622 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002623 * @hide
2624 */
Robin Lee25e26452015-06-02 09:56:29 -07002625 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002626 ActivityInfo ai;
2627 try {
2628 ai = mContext.getPackageManager().getReceiverInfo(cn,
2629 PackageManager.GET_META_DATA);
2630 } catch (PackageManager.NameNotFoundException e) {
2631 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2632 return null;
2633 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002634
Dianne Hackbornd6847842010-01-12 18:14:19 -08002635 ResolveInfo ri = new ResolveInfo();
2636 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002637
Dianne Hackbornd6847842010-01-12 18:14:19 -08002638 try {
2639 return new DeviceAdminInfo(mContext, ri);
2640 } catch (XmlPullParserException e) {
2641 Log.w(TAG, "Unable to parse device policy " + cn, e);
2642 return null;
2643 } catch (IOException e) {
2644 Log.w(TAG, "Unable to parse device policy " + cn, e);
2645 return null;
2646 }
2647 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002648
Dianne Hackbornd6847842010-01-12 18:14:19 -08002649 /**
2650 * @hide
2651 */
Robin Lee25e26452015-06-02 09:56:29 -07002652 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002653 if (mService != null) {
2654 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002655 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002656 } catch (RemoteException e) {
2657 Log.w(TAG, "Failed talking with device policy service", e);
2658 }
2659 }
2660 }
2661
2662 /**
2663 * @hide
2664 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002665 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002666 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002667 if (mService != null) {
2668 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002669 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002670 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002671 } catch (RemoteException e) {
2672 Log.w(TAG, "Failed talking with device policy service", e);
2673 }
2674 }
2675 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002676
Dianne Hackbornd6847842010-01-12 18:14:19 -08002677 /**
2678 * @hide
2679 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002680 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002681 if (mService != null) {
2682 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002683 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002684 } catch (RemoteException e) {
2685 Log.w(TAG, "Failed talking with device policy service", e);
2686 }
2687 }
2688 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002689
Dianne Hackbornd6847842010-01-12 18:14:19 -08002690 /**
2691 * @hide
2692 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002693 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002694 if (mService != null) {
2695 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002696 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002697 } catch (RemoteException e) {
2698 Log.w(TAG, "Failed talking with device policy service", e);
2699 }
2700 }
2701 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002702
2703 /**
2704 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002705 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07002706 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
2707 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002708 * @return whether the package was successfully registered as the device owner.
2709 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002710 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002711 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002712 public boolean setDeviceOwner(ComponentName who) {
2713 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002714 }
2715
2716 /**
2717 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07002718 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002719 public boolean setDeviceOwner(ComponentName who, int userId) {
2720 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002721 }
2722
2723 /**
2724 * @hide
2725 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002726 public boolean setDeviceOwner(ComponentName who, String ownerName) {
2727 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07002728 }
2729
2730 /**
2731 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00002732 * Sets the given package as the device owner. The package must already be installed. There
2733 * must not already be a device owner.
2734 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2735 * this method.
2736 * Calling this after the setup phase of the primary user has completed is allowed only if
2737 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07002738 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002739 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07002740 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002741 * @return whether the package was successfully registered as the device owner.
2742 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00002743 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002744 */
Makoto Onukia52562c2015-10-01 16:12:31 -07002745 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002746 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002747 if (mService != null) {
2748 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002749 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07002750 } catch (RemoteException re) {
2751 Log.w(TAG, "Failed to set device owner");
2752 }
2753 }
2754 return false;
2755 }
2756
2757 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002758 * Used to determine if a particular package has been registered as a Device Owner app.
2759 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07002760 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002761 * package is currently registered as the device owner app, pass in the package name from
2762 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07002763 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002764 * exact mechanism by which a device admin app is registered as a device owner app is defined by
2765 * the setup process.
2766 * @param packageName the package name of the app, to compare with the registered device owner
2767 * app, if any.
Makoto Onukia52562c2015-10-01 16:12:31 -07002768 * @return whether or not the package is registered as the device owner app. Note this method
2769 * does *not* check weather the device owner is actually running on the current user.
Amith Yamasani71e6c692013-03-24 17:39:28 -07002770 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002771 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002772 if (packageName == null) {
2773 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07002774 }
Makoto Onuki70f929e2015-11-11 12:40:15 -08002775 final ComponentName deviceOwner = getDeviceOwnerComponent();
2776 if (deviceOwner == null) {
2777 return false;
2778 }
2779 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07002780 }
2781
Amith Yamasani3b458ad2013-04-18 18:40:07 -07002782 /**
2783 * @hide
2784 * Redirect to isDeviceOwnerApp.
2785 */
2786 public boolean isDeviceOwner(String packageName) {
2787 return isDeviceOwnerApp(packageName);
2788 }
2789
Jason Monkb0dced82014-06-06 14:36:20 -04002790 /**
Makoto Onukia52562c2015-10-01 16:12:31 -07002791 * Check whether a given component is registered as a device owner.
2792 * Note this method does *not* check weather the device owner is actually running on the current
2793 * user.
2794 *
2795 * @hide
2796 */
2797 public boolean isDeviceOwner(ComponentName who) {
2798 return (who != null) && who.equals(getDeviceOwner());
2799 }
2800
2801 /**
Jason Monkb0dced82014-06-06 14:36:20 -04002802 * Clears the current device owner. The caller must be the device owner.
2803 *
2804 * This function should be used cautiously as once it is called it cannot
2805 * be undone. The device owner can only be set as a part of device setup
2806 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04002807 *
2808 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04002809 */
Jason Monk94d2cf92014-06-18 09:53:34 -04002810 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04002811 if (mService != null) {
2812 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04002813 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04002814 } catch (RemoteException re) {
2815 Log.w(TAG, "Failed to clear device owner");
2816 }
2817 }
2818 }
2819
Makoto Onukia52562c2015-10-01 16:12:31 -07002820 /**
2821 * Returns the device owner package name. Note this method will still return the device owner
2822 * package name even if it's running on a different user.
2823 *
2824 * @hide
2825 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01002826 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07002827 public String getDeviceOwner() {
Makoto Onukia52562c2015-10-01 16:12:31 -07002828 final ComponentName componentName = getDeviceOwnerComponent();
2829 return componentName == null ? null : componentName.getPackageName();
2830 }
2831
2832 /**
2833 * Returns the device owner name. Note this method will still return the device owner
2834 * name even if it's running on a different user.
2835 *
2836 * @hide
2837 */
2838 public String getDeviceOwnerName() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07002839 if (mService != null) {
2840 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002841 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07002842 } catch (RemoteException re) {
2843 Log.w(TAG, "Failed to get device owner");
2844 }
2845 }
2846 return null;
2847 }
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002848
Makoto Onukia52562c2015-10-01 16:12:31 -07002849 /**
2850 * Returns the device owner component name. Note this method will still return the device owner
2851 * component name even if it's running on a different user.
2852 *
2853 * @hide
2854 */
2855 public ComponentName getDeviceOwnerComponent() {
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002856 if (mService != null) {
2857 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07002858 return mService.getDeviceOwner();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04002859 } catch (RemoteException re) {
2860 Log.w(TAG, "Failed to get device owner");
2861 }
2862 }
2863 return null;
2864 }
Adam Connors776c5552014-01-09 10:42:56 +00002865
2866 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04002867 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002868 * @deprecated Do not use
2869 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05002870 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002871 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05002872 @SystemApi
2873 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05002874 return null;
2875 }
2876
2877 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002878 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002879 * @deprecated Do not use
2880 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002881 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04002882 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002883 @SystemApi
2884 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04002885 return null;
2886 }
2887
Julia Reynolds20118f12015-02-11 12:34:08 -05002888 /**
Adam Connors776c5552014-01-09 10:42:56 +00002889 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002890 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302891 * Sets the given component as an active admin and registers the package as the profile
2892 * owner for this user. The package must already be installed and there shouldn't be
2893 * an existing profile owner registered for this user. Also, this method must be called
2894 * before the user setup has been completed.
2895 * <p>
2896 * This method can only be called by system apps that hold MANAGE_USERS permission and
2897 * MANAGE_DEVICE_ADMINS permission.
2898 * @param admin The component to register as an active admin and profile owner.
2899 * @param ownerName The user-visible name of the entity that is managing this user.
2900 * @return whether the admin was successfully registered as the profile owner.
2901 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
2902 * the user has already been set up.
2903 */
Justin Morey80440cc2014-07-24 09:16:35 -05002904 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002905 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302906 throws IllegalArgumentException {
2907 if (mService != null) {
2908 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002909 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302910 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002911 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05302912 } catch (RemoteException re) {
2913 Log.w(TAG, "Failed to set profile owner " + re);
2914 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2915 }
2916 }
2917 return false;
2918 }
2919
2920 /**
2921 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002922 * Clears the active profile owner and removes all user restrictions. The caller must
2923 * be from the same package as the active profile owner for this user, otherwise a
2924 * SecurityException will be thrown.
2925 *
2926 * @param admin The component to remove as the profile owner.
2927 * @return
2928 */
2929 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07002930 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002931 if (mService != null) {
2932 try {
2933 mService.clearProfileOwner(admin);
2934 } catch (RemoteException re) {
2935 Log.w(TAG, "Failed to clear profile owner " + admin + re);
2936 }
2937 }
2938 }
2939
2940 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05002941 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07002942 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002943 */
2944 public boolean hasUserSetupCompleted() {
2945 if (mService != null) {
2946 try {
2947 return mService.hasUserSetupCompleted();
2948 } catch (RemoteException re) {
Robin Lee25e26452015-06-02 09:56:29 -07002949 Log.w(TAG, "Failed to check whether user setup has completed");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002950 }
2951 }
2952 return true;
2953 }
2954
2955 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002956 * @hide
2957 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00002958 * already be installed. There must not already be a profile owner for this user.
2959 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
2960 * this method.
2961 * Calling this after the setup phase of the specified user has completed is allowed only if:
2962 * - the caller is SYSTEM_UID.
2963 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002964 * @param admin the component name to be registered as profile owner.
2965 * @param ownerName the human readable name of the organisation associated with this DPM.
2966 * @param userHandle the userId to set the profile owner for.
2967 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00002968 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
2969 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002970 */
Robin Lee25e26452015-06-02 09:56:29 -07002971 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01002972 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00002973 if (mService != null) {
2974 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07002975 if (ownerName == null) {
2976 ownerName = "";
2977 }
2978 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00002979 } catch (RemoteException re) {
2980 Log.w(TAG, "Failed to set profile owner", re);
2981 throw new IllegalArgumentException("Couldn't set profile owner.", re);
2982 }
2983 }
2984 return false;
2985 }
2986
2987 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00002988 * Sets the device owner information to be shown on the lock screen.
2989 *
2990 * <p>If the device owner information is {@code null} or empty then the device owner info is
2991 * cleared and the user owner info is shown on the lock screen if it is set.
2992 *
2993 * @param admin The name of the admin component to check.
2994 * @param info Device owner information which will be displayed instead of the user
2995 * owner info.
2996 * @return Whether the device owner information has been set.
2997 */
2998 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
2999 if (mService != null) {
3000 try {
3001 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3002 } catch (RemoteException re) {
3003 Log.w(TAG, "Failed talking with device policy service", re);
3004 }
3005 }
3006 return false;
3007 }
3008
3009 /**
3010 * @return The device owner information. If it is not set returns {@code null}.
3011 */
3012 public String getDeviceOwnerLockScreenInfo() {
3013 if (mService != null) {
3014 try {
3015 return mService.getDeviceOwnerLockScreenInfo();
3016 } catch (RemoteException re) {
3017 Log.w(TAG, "Failed talking with device policy service", re);
3018 }
3019 }
3020 return null;
3021 }
3022
3023 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003024 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3025 * be used. Only the profile owner can call this.
3026 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003027 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003028 *
3029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3030 */
Robin Lee25e26452015-06-02 09:56:29 -07003031 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003032 if (mService != null) {
3033 try {
3034 mService.setProfileEnabled(admin);
3035 } catch (RemoteException e) {
3036 Log.w(TAG, "Failed talking with device policy service", e);
3037 }
3038 }
3039 }
3040
3041 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003042 * Sets the name of the profile. In the device owner case it sets the name of the user
3043 * 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 +01003044 * never called by the profile or device owner, the name will be set to default values.
3045 *
3046 * @see #isProfileOwnerApp
3047 * @see #isDeviceOwnerApp
3048 *
Robin Lee25e26452015-06-02 09:56:29 -07003049 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003050 * @param profileName The name of the profile.
3051 */
Robin Lee25e26452015-06-02 09:56:29 -07003052 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003053 if (mService != null) {
3054 try {
Robin Lee25e26452015-06-02 09:56:29 -07003055 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003056 } catch (RemoteException e) {
3057 Log.w(TAG, "Failed talking with device policy service", e);
3058 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003059 }
3060 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003061
3062 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003063 * Used to determine if a particular package is registered as the profile owner for the
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003064 * current user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003065 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003066 *
3067 * @param packageName The package name of the app to compare with the registered profile owner.
3068 * @return Whether or not the package is registered as the profile owner.
3069 */
3070 public boolean isProfileOwnerApp(String packageName) {
3071 if (mService != null) {
3072 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003073 ComponentName profileOwner = mService.getProfileOwner(
3074 Process.myUserHandle().getIdentifier());
3075 return profileOwner != null
3076 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003077 } catch (RemoteException re) {
3078 Log.w(TAG, "Failed to check profile owner");
3079 }
3080 }
3081 return false;
3082 }
3083
3084 /**
3085 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003086 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003087 * owner has been set for that user.
3088 * @throws IllegalArgumentException if the userId is invalid.
3089 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003090 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003091 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003092 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3093 }
3094
3095 /**
3096 * @see #getProfileOwner()
3097 * @hide
3098 */
3099 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003100 if (mService != null) {
3101 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003102 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003103 } catch (RemoteException re) {
3104 Log.w(TAG, "Failed to get profile owner");
3105 throw new IllegalArgumentException(
3106 "Requested profile owner for invalid userId", re);
3107 }
3108 }
3109 return null;
3110 }
3111
3112 /**
3113 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003114 * @return the human readable name of the organisation associated with this DPM or {@code null}
3115 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003116 * @throws IllegalArgumentException if the userId is invalid.
3117 */
3118 public String getProfileOwnerName() throws IllegalArgumentException {
3119 if (mService != null) {
3120 try {
3121 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3122 } catch (RemoteException re) {
3123 Log.w(TAG, "Failed to get profile owner");
3124 throw new IllegalArgumentException(
3125 "Requested profile owner for invalid userId", re);
3126 }
3127 }
3128 return null;
3129 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003130
3131 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003132 * @hide
Makoto Onuki219bbaf2015-11-12 01:38:47 +00003133 * @param user The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003134 * @return the human readable name of the organisation associated with this profile owner or
3135 * null if one is not set.
3136 * @throws IllegalArgumentException if the userId is invalid.
3137 */
3138 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003139 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003140 if (mService != null) {
3141 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003142 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003143 } catch (RemoteException re) {
3144 Log.w(TAG, "Failed to get profile owner");
3145 throw new IllegalArgumentException(
3146 "Requested profile owner for invalid userId", re);
3147 }
3148 }
3149 return null;
3150 }
3151
3152 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003153 * Called by a profile owner or device owner to add a default intent handler activity for
3154 * intents that match a certain intent filter. This activity will remain the default intent
3155 * handler even if the set of potential event handlers for the intent filter changes and if
3156 * the intent preferences are reset.
3157 *
3158 * <p>The default disambiguation mechanism takes over if the activity is not installed
3159 * (anymore). When the activity is (re)installed, it is automatically reset as default
3160 * intent handler for the filter.
3161 *
3162 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3163 * security exception will be thrown.
3164 *
3165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3166 * @param filter The IntentFilter for which a default handler is added.
3167 * @param activity The Activity that is added as default intent handler.
3168 */
Robin Lee25e26452015-06-02 09:56:29 -07003169 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3170 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003171 if (mService != null) {
3172 try {
3173 mService.addPersistentPreferredActivity(admin, filter, activity);
3174 } catch (RemoteException e) {
3175 Log.w(TAG, "Failed talking with device policy service", e);
3176 }
3177 }
3178 }
3179
3180 /**
3181 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003182 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003183 *
3184 * <p>The calling device admin must be a profile owner. If it is not, a security
3185 * exception will be thrown.
3186 *
3187 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3188 * @param packageName The name of the package for which preferences are removed.
3189 */
Robin Lee25e26452015-06-02 09:56:29 -07003190 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003191 String packageName) {
3192 if (mService != null) {
3193 try {
3194 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3195 } catch (RemoteException e) {
3196 Log.w(TAG, "Failed talking with device policy service", e);
3197 }
3198 }
3199 }
Robin Lee66e5d962014-04-09 16:44:21 +01003200
3201 /**
3202 * Called by a profile or device owner to set the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003203 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003204 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003205 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3206 * <ul>
3207 * <li>{@code boolean}
3208 * <li>{@code int}
3209 * <li>{@code String} or {@code String[]}
3210 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3211 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003212 *
3213 * <p>The application restrictions are only made visible to the target application and the
3214 * profile or device owner.
3215 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003216 * <p>If the restrictions are not available yet, but may be applied in the near future,
3217 * the admin can notify the target application of that by adding
3218 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3219 *
Robin Lee66e5d962014-04-09 16:44:21 +01003220 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3221 * exception will be thrown.
3222 *
3223 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3224 * @param packageName The name of the package to update restricted settings for.
3225 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3226 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003227 *
3228 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003229 */
Robin Lee25e26452015-06-02 09:56:29 -07003230 public void setApplicationRestrictions(@NonNull ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003231 Bundle settings) {
3232 if (mService != null) {
3233 try {
3234 mService.setApplicationRestrictions(admin, packageName, settings);
3235 } catch (RemoteException e) {
3236 Log.w(TAG, "Failed talking with device policy service", e);
3237 }
3238 }
3239 }
3240
3241 /**
Jim Millere303bf42014-08-26 17:12:29 -07003242 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3243 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3244 * trust agents but those enabled by this function call. If flag
3245 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003246 *
3247 * <p>The calling device admin must have requested
3248 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003249 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003250 *
3251 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003252 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003253 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003254 * will be strictly disabled according to the state of the
3255 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3256 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3257 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3258 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003259 */
Robin Lee25e26452015-06-02 09:56:29 -07003260 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3261 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003262 if (mService != null) {
3263 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003264 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003265 } catch (RemoteException e) {
3266 Log.w(TAG, "Failed talking with device policy service", e);
3267 }
3268 }
3269 }
3270
3271 /**
Jim Millere303bf42014-08-26 17:12:29 -07003272 * Gets configuration for the given trust agent based on aggregating all calls to
3273 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3274 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003275 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3277 * this function returns a list of configurations for all admins that declare
3278 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3279 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3280 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3281 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003282 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003283 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003284 */
Robin Lee25e26452015-06-02 09:56:29 -07003285 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3286 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003287 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003288 }
3289
3290 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003291 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3292 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003293 if (mService != null) {
3294 try {
Jim Millere303bf42014-08-26 17:12:29 -07003295 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003296 } catch (RemoteException e) {
3297 Log.w(TAG, "Failed talking with device policy service", e);
3298 }
3299 }
Jim Millere303bf42014-08-26 17:12:29 -07003300 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003301 }
3302
3303 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003304 * Called by a profile owner of a managed profile to set whether caller-Id information from
3305 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003306 *
3307 * <p>The calling device admin must be a profile owner. If it is not, a
3308 * security exception will be thrown.
3309 *
Robin Lee25e26452015-06-02 09:56:29 -07003310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003311 * @param disabled If true caller-Id information in the managed profile is not displayed.
3312 */
Robin Lee25e26452015-06-02 09:56:29 -07003313 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003314 if (mService != null) {
3315 try {
Robin Lee25e26452015-06-02 09:56:29 -07003316 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003317 } catch (RemoteException e) {
3318 Log.w(TAG, "Failed talking with device policy service", e);
3319 }
3320 }
3321 }
3322
3323 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003324 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3325 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003326 *
3327 * <p>The calling device admin must be a profile owner. If it is not, a
3328 * security exception will be thrown.
3329 *
Robin Lee25e26452015-06-02 09:56:29 -07003330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003331 */
Robin Lee25e26452015-06-02 09:56:29 -07003332 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003333 if (mService != null) {
3334 try {
Robin Lee25e26452015-06-02 09:56:29 -07003335 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003336 } catch (RemoteException e) {
3337 Log.w(TAG, "Failed talking with device policy service", e);
3338 }
3339 }
3340 return false;
3341 }
3342
3343 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003344 * Determine whether or not caller-Id information has been disabled.
3345 *
3346 * @param userHandle The user for whom to check the caller-id permission
3347 * @hide
3348 */
3349 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3350 if (mService != null) {
3351 try {
3352 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3353 } catch (RemoteException e) {
3354 Log.w(TAG, "Failed talking with device policy service", e);
3355 }
3356 }
3357 return false;
3358 }
3359
3360 /**
Makoto Onuki1040da12015-03-19 11:24:00 -07003361 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3362 * @hide
3363 */
3364 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Ricky Wai494b95d2015-11-20 16:07:15 +00003365 long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003366 if (mService != null) {
3367 try {
3368 mService.startManagedQuickContact(
Ricky Wai494b95d2015-11-20 16:07:15 +00003369 actualLookupKey, actualContactId, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003370 } catch (RemoteException e) {
3371 Log.w(TAG, "Failed talking with device policy service", e);
3372 }
3373 }
3374 }
3375
3376 /**
Ricky Wai494b95d2015-11-20 16:07:15 +00003377 * Start Quick Contact on the managed profile for the current user, if the policy allows.
3378 * @hide
3379 */
3380 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3381 Intent originalIntent) {
3382 startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT,
3383 originalIntent);
3384 }
3385
3386 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003387 * Called by a profile owner of a managed profile to set whether bluetooth
3388 * devices can access enterprise contacts.
3389 * <p>
3390 * The calling device admin must be a profile owner. If it is not, a
3391 * security exception will be thrown.
3392 * <p>
3393 * This API works on managed profile only.
3394 *
Robin Lee25e26452015-06-02 09:56:29 -07003395 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003396 * with.
3397 * @param disabled If true, bluetooth devices cannot access enterprise
3398 * contacts.
3399 */
Robin Lee25e26452015-06-02 09:56:29 -07003400 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003401 if (mService != null) {
3402 try {
Robin Lee25e26452015-06-02 09:56:29 -07003403 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003404 } catch (RemoteException e) {
3405 Log.w(TAG, "Failed talking with device policy service", e);
3406 }
3407 }
3408 }
3409
3410 /**
3411 * Called by a profile owner of a managed profile to determine whether or
3412 * not Bluetooth devices cannot access enterprise contacts.
3413 * <p>
3414 * The calling device admin must be a profile owner. If it is not, a
3415 * security exception will be thrown.
3416 * <p>
3417 * This API works on managed profile only.
3418 *
Robin Lee25e26452015-06-02 09:56:29 -07003419 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003420 * with.
3421 */
Robin Lee25e26452015-06-02 09:56:29 -07003422 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003423 if (mService != null) {
3424 try {
Robin Lee25e26452015-06-02 09:56:29 -07003425 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003426 } catch (RemoteException e) {
3427 Log.w(TAG, "Failed talking with device policy service", e);
3428 }
3429 }
3430 return true;
3431 }
3432
3433 /**
3434 * Determine whether or not Bluetooth devices cannot access contacts.
3435 * <p>
3436 * This API works on managed profile UserHandle only.
3437 *
3438 * @param userHandle The user for whom to check the caller-id permission
3439 * @hide
3440 */
3441 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3442 if (mService != null) {
3443 try {
3444 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3445 .getIdentifier());
3446 } catch (RemoteException e) {
3447 Log.w(TAG, "Failed talking with device policy service", e);
3448 }
3449 }
3450 return true;
3451 }
3452
3453 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003454 * Called by the profile owner of a managed profile so that some intents sent in the managed
3455 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003456 * Only activity intents are supported.
3457 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003458 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003459 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3460 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003461 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3462 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003463 */
Robin Lee25e26452015-06-02 09:56:29 -07003464 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003465 if (mService != null) {
3466 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003467 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003468 } catch (RemoteException e) {
3469 Log.w(TAG, "Failed talking with device policy service", e);
3470 }
3471 }
3472 }
3473
3474 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003475 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
3476 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01003477 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003478 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3479 */
Robin Lee25e26452015-06-02 09:56:29 -07003480 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003481 if (mService != null) {
3482 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003483 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003484 } catch (RemoteException e) {
3485 Log.w(TAG, "Failed talking with device policy service", e);
3486 }
3487 }
3488 }
3489
3490 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003491 * Called by a profile or device owner to set the permitted accessibility services. When
3492 * set by a device owner or profile owner the restriction applies to all profiles of the
3493 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07003494 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003495 * By default the user can use any accessiblity service. When zero or more packages have
3496 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07003497 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003498 *
3499 * <p> Calling with a null value for the list disables the restriction so that all services
3500 * can be used, calling with an empty list only allows the builtin system's services.
3501 *
3502 * <p> System accesibility services are always available to the user the list can't modify
3503 * this.
3504 *
3505 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3506 * @param packageNames List of accessibility service package names.
3507 *
3508 * @return true if setting the restriction succeeded. It fail if there is
3509 * one or more non-system accessibility services enabled, that are not in the list.
3510 */
Robin Lee25e26452015-06-02 09:56:29 -07003511 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003512 List<String> packageNames) {
3513 if (mService != null) {
3514 try {
3515 return mService.setPermittedAccessibilityServices(admin, packageNames);
3516 } catch (RemoteException e) {
3517 Log.w(TAG, "Failed talking with device policy service", e);
3518 }
3519 }
3520 return false;
3521 }
3522
3523 /**
3524 * Returns the list of permitted accessibility services set by this device or profile owner.
3525 *
3526 * <p>An empty list means no accessibility services except system services are allowed.
3527 * Null means all accessibility services are allowed.
3528 *
3529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3530 * @return List of accessiblity service package names.
3531 */
Robin Lee25e26452015-06-02 09:56:29 -07003532 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003533 if (mService != null) {
3534 try {
3535 return mService.getPermittedAccessibilityServices(admin);
3536 } catch (RemoteException e) {
3537 Log.w(TAG, "Failed talking with device policy service", e);
3538 }
3539 }
3540 return null;
3541 }
3542
3543 /**
3544 * Returns the list of accessibility services permitted by the device or profiles
3545 * owners of this user.
3546 *
3547 * <p>Null means all accessibility services are allowed, if a non-null list is returned
3548 * it will contain the intersection of the permitted lists for any device or profile
3549 * owners that apply to this user. It will also include any system accessibility services.
3550 *
3551 * @param userId which user to check for.
3552 * @return List of accessiblity service package names.
3553 * @hide
3554 */
3555 @SystemApi
3556 public List<String> getPermittedAccessibilityServices(int userId) {
3557 if (mService != null) {
3558 try {
3559 return mService.getPermittedAccessibilityServicesForUser(userId);
3560 } catch (RemoteException e) {
3561 Log.w(TAG, "Failed talking with device policy service", e);
3562 }
3563 }
3564 return null;
3565 }
3566
3567 /**
3568 * Called by a profile or device owner to set the permitted input methods services. When
3569 * set by a device owner or profile owner the restriction applies to all profiles of the
3570 * user the device owner or profile owner is an admin for.
3571 *
3572 * By default the user can use any input method. When zero or more packages have
3573 * been added, input method that are not in the list and not part of the system
3574 * can not be enabled by the user.
3575 *
3576 * This method will fail if it is called for a admin that is not for the foreground user
3577 * or a profile of the foreground user.
3578 *
3579 * <p> Calling with a null value for the list disables the restriction so that all input methods
3580 * can be used, calling with an empty list disables all but the system's own input methods.
3581 *
3582 * <p> System input methods are always available to the user this method can't modify this.
3583 *
3584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3585 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00003586 * @return true if setting the restriction succeeded. It will fail if there are
3587 * one or more non-system input methods currently enabled that are not in
3588 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003589 */
Robin Lee25e26452015-06-02 09:56:29 -07003590 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003591 if (mService != null) {
3592 try {
3593 return mService.setPermittedInputMethods(admin, packageNames);
3594 } catch (RemoteException e) {
3595 Log.w(TAG, "Failed talking with device policy service", e);
3596 }
3597 }
3598 return false;
3599 }
3600
3601
3602 /**
3603 * Returns the list of permitted input methods set by this device or profile owner.
3604 *
3605 * <p>An empty list means no input methods except system input methods are allowed.
3606 * Null means all input methods are allowed.
3607 *
3608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3609 * @return List of input method package names.
3610 */
Robin Lee25e26452015-06-02 09:56:29 -07003611 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01003612 if (mService != null) {
3613 try {
3614 return mService.getPermittedInputMethods(admin);
3615 } catch (RemoteException e) {
3616 Log.w(TAG, "Failed talking with device policy service", e);
3617 }
3618 }
3619 return null;
3620 }
3621
3622 /**
3623 * Returns the list of input methods permitted by the device or profiles
3624 * owners of the current user.
3625 *
3626 * <p>Null means all input methods are allowed, if a non-null list is returned
3627 * it will contain the intersection of the permitted lists for any device or profile
3628 * owners that apply to this user. It will also include any system input methods.
3629 *
3630 * @return List of input method package names.
3631 * @hide
3632 */
3633 @SystemApi
3634 public List<String> getPermittedInputMethodsForCurrentUser() {
3635 if (mService != null) {
3636 try {
3637 return mService.getPermittedInputMethodsForCurrentUser();
3638 } catch (RemoteException e) {
3639 Log.w(TAG, "Failed talking with device policy service", e);
3640 }
3641 }
3642 return null;
3643 }
3644
3645 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08003646 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
3647 * currently installed it.
3648 *
3649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3650 *
3651 * @return List of package names to keep cached.
3652 * @hide
3653 */
3654 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
3655 if (mService != null) {
3656 try {
3657 return mService.getKeepUninstalledPackages(admin);
3658 } catch (RemoteException e) {
3659 Log.w(TAG, "Failed talking with device policy service", e);
3660 }
3661 }
3662 return null;
3663 }
3664
3665 /**
3666 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
3667 * currently installed it.
3668 *
3669 * <p>Please note that setting this policy does not imply that specified apps will be
3670 * automatically pre-cached.</p>
3671 *
3672 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3673 * @param packageNames List of package names to keep cached.
3674 * @hide
3675 */
3676 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
3677 @NonNull List<String> packageNames) {
3678 if (mService != null) {
3679 try {
3680 mService.setKeepUninstalledPackages(admin, packageNames);
3681 } catch (RemoteException e) {
3682 Log.w(TAG, "Failed talking with device policy service", e);
3683 }
3684 }
3685 }
3686
3687 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003688 * Called by a device owner to create a user with the specified name. The UserHandle returned
3689 * by this method should not be persisted as user handles are recycled as users are removed and
3690 * created. If you need to persist an identifier for this user, use
3691 * {@link UserManager#getSerialNumberForUser}.
3692 *
3693 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3694 * @param name the user's name
3695 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003696 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3697 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003698 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003699 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04003700 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003701 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003702 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003703 try {
3704 return mService.createUser(admin, name);
3705 } catch (RemoteException re) {
3706 Log.w(TAG, "Could not create a user", re);
3707 }
3708 return null;
3709 }
3710
3711 /**
Jason Monk03978a42014-06-10 15:05:30 -04003712 * Called by a device owner to create a user with the specified name. The UserHandle returned
3713 * by this method should not be persisted as user handles are recycled as users are removed and
3714 * created. If you need to persist an identifier for this user, use
3715 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
3716 * immediately.
3717 *
3718 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
3719 * as registered as an active admin on the new user. The profile owner package will be
3720 * installed on the new user if it already is installed on the device.
3721 *
3722 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
3723 * profileOwnerComponent when onEnable is called.
3724 *
3725 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3726 * @param name the user's name
3727 * @param ownerName the human readable name of the organisation associated with this DPM.
3728 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
3729 * the user.
3730 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
3731 * on the new user.
3732 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07003733 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
3734 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01003735 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07003736 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04003737 */
Kenny Guy14f48e52015-06-29 15:12:36 +01003738 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07003739 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
3740 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04003741 try {
3742 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
3743 adminExtras);
3744 } catch (RemoteException re) {
3745 Log.w(TAG, "Could not create a user", re);
3746 }
3747 return null;
3748 }
3749
3750 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04003751 * Called by a device owner to remove a user and all associated data. The primary user can
3752 * not be removed.
3753 *
3754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3755 * @param userHandle the user to remove.
3756 * @return {@code true} if the user was removed, {@code false} otherwise.
3757 */
Robin Lee25e26452015-06-02 09:56:29 -07003758 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04003759 try {
3760 return mService.removeUser(admin, userHandle);
3761 } catch (RemoteException re) {
3762 Log.w(TAG, "Could not remove user ", re);
3763 return false;
3764 }
3765 }
3766
3767 /**
Jason Monk582d9112014-07-09 19:57:08 -04003768 * Called by a device owner to switch the specified user to the foreground.
3769 *
3770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3771 * @param userHandle the user to switch to; null will switch to primary.
3772 * @return {@code true} if the switch was successful, {@code false} otherwise.
3773 *
3774 * @see Intent#ACTION_USER_FOREGROUND
3775 */
Robin Lee25e26452015-06-02 09:56:29 -07003776 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04003777 try {
3778 return mService.switchUser(admin, userHandle);
3779 } catch (RemoteException re) {
3780 Log.w(TAG, "Could not switch user ", re);
3781 return false;
3782 }
3783 }
3784
3785 /**
Robin Lee66e5d962014-04-09 16:44:21 +01003786 * Called by a profile or device owner to get the application restrictions for a given target
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003787 * application running in the profile.
Robin Lee66e5d962014-04-09 16:44:21 +01003788 *
3789 * <p>The calling device admin must be a profile or device owner; if it is not, a security
3790 * exception will be thrown.
3791 *
3792 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3793 * @param packageName The name of the package to fetch restricted settings of.
3794 * @return {@link Bundle} of settings corresponding to what was set last time
3795 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
3796 * if no restrictions have been set.
3797 */
Robin Lee25e26452015-06-02 09:56:29 -07003798 public Bundle getApplicationRestrictions(@NonNull ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01003799 if (mService != null) {
3800 try {
3801 return mService.getApplicationRestrictions(admin, packageName);
3802 } catch (RemoteException e) {
3803 Log.w(TAG, "Failed talking with device policy service", e);
3804 }
3805 }
3806 return null;
3807 }
Amith Yamasanibe465322014-04-24 13:45:17 -07003808
3809 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003810 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003811 * <p>
3812 * The calling device admin must be a profile or device owner; if it is not,
3813 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003814 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003815 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3816 * with.
3817 * @param key The key of the restriction. See the constants in
3818 * {@link android.os.UserManager} for the list of keys.
3819 */
Robin Lee25e26452015-06-02 09:56:29 -07003820 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003821 if (mService != null) {
3822 try {
3823 mService.setUserRestriction(admin, key, true);
3824 } catch (RemoteException e) {
3825 Log.w(TAG, "Failed talking with device policy service", e);
3826 }
3827 }
3828 }
3829
3830 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003831 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07003832 * <p>
3833 * The calling device admin must be a profile or device owner; if it is not,
3834 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07003835 *
Amith Yamasanibe465322014-04-24 13:45:17 -07003836 * @param admin Which {@link DeviceAdminReceiver} this request is associated
3837 * with.
3838 * @param key The key of the restriction. See the constants in
3839 * {@link android.os.UserManager} for the list of keys.
3840 */
Robin Lee25e26452015-06-02 09:56:29 -07003841 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07003842 if (mService != null) {
3843 try {
3844 mService.setUserRestriction(admin, key, false);
3845 } catch (RemoteException e) {
3846 Log.w(TAG, "Failed talking with device policy service", e);
3847 }
3848 }
3849 }
Adam Connors010cfd42014-04-16 12:48:13 +01003850
3851 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003852 * Called by a profile or device owner to get user restrictions set with
3853 * {@link #addUserRestriction(ComponentName, String)}.
3854 * <p>
3855 * The target user may have more restrictions set by the system or other device owner / profile
3856 * owner. To get all the user restrictions currently set, use
3857 * {@link UserManager#getUserRestrictions()}.
3858 *
3859 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003860 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003861 */
3862 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003863 return getUserRestrictions(admin, myUserId());
3864 }
3865
3866 /** @hide per-user version */
3867 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003868 Bundle ret = null;
3869 if (mService != null) {
3870 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00003871 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07003872 } catch (RemoteException e) {
3873 Log.w(TAG, "Failed talking with device policy service", e);
3874 }
3875 }
3876 return ret == null ? new Bundle() : ret;
3877 }
3878
3879 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003880 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04003881 * is unavailable for use, but the data and actual package file remain.
3882 *
3883 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003884 * @param packageName The name of the package to hide or unhide.
3885 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
3886 * unhidden.
3887 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04003888 */
Robin Lee25e26452015-06-02 09:56:29 -07003889 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003890 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003891 if (mService != null) {
3892 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003893 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04003894 } catch (RemoteException e) {
3895 Log.w(TAG, "Failed talking with device policy service", e);
3896 }
3897 }
3898 return false;
3899 }
3900
3901 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003902 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04003903 *
3904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003905 * @param packageName The name of the package to retrieve the hidden status of.
3906 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04003907 */
Robin Lee25e26452015-06-02 09:56:29 -07003908 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04003909 if (mService != null) {
3910 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07003911 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04003912 } catch (RemoteException e) {
3913 Log.w(TAG, "Failed talking with device policy service", e);
3914 }
3915 }
3916 return false;
3917 }
3918
3919 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003920 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003921 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003922 *
3923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3924 * @param packageName The package to be re-enabled in the current profile.
3925 */
Robin Lee25e26452015-06-02 09:56:29 -07003926 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00003927 if (mService != null) {
3928 try {
3929 mService.enableSystemApp(admin, packageName);
3930 } catch (RemoteException e) {
3931 Log.w(TAG, "Failed to install package: " + packageName);
3932 }
3933 }
3934 }
3935
3936 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05003937 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003938 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00003939 *
3940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3941 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
3942 * intent will be re-enabled in the current profile.
3943 * @return int The number of activities that matched the intent and were installed.
3944 */
Robin Lee25e26452015-06-02 09:56:29 -07003945 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00003946 if (mService != null) {
3947 try {
3948 return mService.enableSystemAppWithIntent(admin, intent);
3949 } catch (RemoteException e) {
3950 Log.w(TAG, "Failed to install packages matching filter: " + intent);
3951 }
3952 }
3953 return 0;
3954 }
3955
3956 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00003957 * Called by a device owner or profile owner to disable account management for a specific type
3958 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01003959 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00003960 * <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 +01003961 * security exception will be thrown.
3962 *
3963 * <p>When account management is disabled for an account type, adding or removing an account
3964 * of that type will not be possible.
3965 *
3966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3967 * @param accountType For which account management is disabled or enabled.
3968 * @param disabled The boolean indicating that account management will be disabled (true) or
3969 * enabled (false).
3970 */
Robin Lee25e26452015-06-02 09:56:29 -07003971 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01003972 boolean disabled) {
3973 if (mService != null) {
3974 try {
3975 mService.setAccountManagementDisabled(admin, accountType, disabled);
3976 } catch (RemoteException e) {
3977 Log.w(TAG, "Failed talking with device policy service", e);
3978 }
3979 }
3980 }
3981
3982 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01003983 * Gets the array of accounts for which account management is disabled by the profile owner.
3984 *
3985 * <p> Account management can be disabled/enabled by calling
3986 * {@link #setAccountManagementDisabled}.
3987 *
3988 * @return a list of account types for which account management has been disabled.
3989 *
3990 * @see #setAccountManagementDisabled
3991 */
3992 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003993 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01003994 }
3995
3996 /**
3997 * @see #getAccountTypesWithManagementDisabled()
3998 * @hide
3999 */
4000 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004001 if (mService != null) {
4002 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004003 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004004 } catch (RemoteException e) {
4005 Log.w(TAG, "Failed talking with device policy service", e);
4006 }
4007 }
4008
4009 return null;
4010 }
justinzhang511e0d82014-03-24 16:09:24 -04004011
4012 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004013 * Sets which packages may enter lock task mode.
4014 *
4015 * <p>Any packages that shares uid with an allowed package will also be allowed
4016 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004017 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004018 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004019 * package list results in locked tasks belonging to those packages to be finished.
4020 *
Jason Monkc5185f22014-06-24 11:12:42 -04004021 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004022 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004024 *
4025 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004026 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4027 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004028 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004029 */
Robin Lee25e26452015-06-02 09:56:29 -07004030 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004031 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004032 if (mService != null) {
4033 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004034 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004035 } catch (RemoteException e) {
4036 Log.w(TAG, "Failed talking with device policy service", e);
4037 }
4038 }
4039 }
4040
4041 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004042 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004043 *
4044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004045 * @hide
4046 */
Robin Lee25e26452015-06-02 09:56:29 -07004047 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004048 if (mService != null) {
4049 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004050 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004051 } catch (RemoteException e) {
4052 Log.w(TAG, "Failed talking with device policy service", e);
4053 }
4054 }
4055 return null;
4056 }
4057
4058 /**
4059 * This function lets the caller know whether the given component is allowed to start the
4060 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004061 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004062 */
Jason Monkd7b86212014-06-16 13:15:38 -04004063 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004064 if (mService != null) {
4065 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004066 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004067 } catch (RemoteException e) {
4068 Log.w(TAG, "Failed talking with device policy service", e);
4069 }
4070 }
4071 return false;
4072 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004073
4074 /**
4075 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4076 * 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 -04004077 * <p>The settings that can be updated with this method are:
4078 * <ul>
4079 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4080 * <li>{@link Settings.Global#AUTO_TIME}</li>
4081 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004082 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004083 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004084 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004085 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004086 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004087 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004088 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004089 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004090 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004091 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004092 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004093 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004094 * <ul>
4095 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4096 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4097 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4098 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4099 * <li>{@link Settings.Global#MODE_RINGER}.
4100 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4101 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4102 * <li>{@link Settings.Global#WIFI_ON}.
4103 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4104 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004105 *
4106 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4107 * @param setting The name of the setting to update.
4108 * @param value The value to update the setting to.
4109 */
Robin Lee25e26452015-06-02 09:56:29 -07004110 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004111 if (mService != null) {
4112 try {
4113 mService.setGlobalSetting(admin, setting, value);
4114 } catch (RemoteException e) {
4115 Log.w(TAG, "Failed talking with device policy service", e);
4116 }
4117 }
4118 }
4119
4120 /**
4121 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4122 * that the value of the setting is in the correct form for the setting type should be performed
4123 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004124 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004125 * <ul>
4126 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004127 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004128 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4129 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004130 * <p>A device owner can additionally update the following settings:
4131 * <ul>
4132 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4133 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004134 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4135 * @param setting The name of the setting to update.
4136 * @param value The value to update the setting to.
4137 */
Robin Lee25e26452015-06-02 09:56:29 -07004138 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004139 if (mService != null) {
4140 try {
4141 mService.setSecureSetting(admin, setting, value);
4142 } catch (RemoteException e) {
4143 Log.w(TAG, "Failed talking with device policy service", e);
4144 }
4145 }
4146 }
4147
Amith Yamasanif20d6402014-05-24 15:34:37 -07004148 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004149 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004150 * making permission requests of a local or remote administrator of the user.
4151 * <p/>
4152 * Only a profile owner can designate the restrictions provider.
4153 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004154 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004155 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004156 * it removes the restrictions provider previously assigned.
4157 */
Robin Lee25e26452015-06-02 09:56:29 -07004158 public void setRestrictionsProvider(@NonNull ComponentName admin,
4159 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004160 if (mService != null) {
4161 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004162 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004163 } catch (RemoteException re) {
4164 Log.w(TAG, "Failed to set permission provider on device policy service");
4165 }
4166 }
4167 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004168
4169 /**
4170 * Called by profile or device owners to set the master volume mute on or off.
4171 *
4172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4173 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4174 */
Robin Lee25e26452015-06-02 09:56:29 -07004175 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004176 if (mService != null) {
4177 try {
4178 mService.setMasterVolumeMuted(admin, on);
4179 } catch (RemoteException re) {
4180 Log.w(TAG, "Failed to setMasterMute on device policy service");
4181 }
4182 }
4183 }
4184
4185 /**
4186 * Called by profile or device owners to check whether the master volume mute is on or off.
4187 *
4188 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4189 * @return {@code true} if master volume is muted, {@code false} if it's not.
4190 */
Robin Lee25e26452015-06-02 09:56:29 -07004191 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004192 if (mService != null) {
4193 try {
4194 return mService.isMasterVolumeMuted(admin);
4195 } catch (RemoteException re) {
4196 Log.w(TAG, "Failed to get isMasterMute on device policy service");
4197 }
4198 }
4199 return false;
4200 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004201
4202 /**
4203 * Called by profile or device owners to change whether a user can uninstall
4204 * a package.
4205 *
4206 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4207 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004208 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004209 */
Robin Lee25e26452015-06-02 09:56:29 -07004210 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004211 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004212 if (mService != null) {
4213 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004214 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004215 } catch (RemoteException re) {
4216 Log.w(TAG, "Failed to call block uninstall on device policy service");
4217 }
4218 }
4219 }
4220
4221 /**
Rubin Xua97855b2014-11-07 05:41:00 +00004222 * Check whether the current user has been blocked by device policy from uninstalling a package.
4223 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004224 * <p>
4225 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004226 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004227 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004228 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004229 *
Robin Lee25e26452015-06-02 09:56:29 -07004230 * @param admin The name of the admin component whose blocking policy will be checked, or
4231 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004232 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004233 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004234 */
Robin Lee25e26452015-06-02 09:56:29 -07004235 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004236 if (mService != null) {
4237 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004238 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004239 } catch (RemoteException re) {
4240 Log.w(TAG, "Failed to call block uninstall on device policy service");
4241 }
4242 }
4243 return false;
4244 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004245
4246 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004247 * Called by the profile owner of a managed profile to enable widget providers from a
4248 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004249 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004250 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004251 * a package may have zero or more provider components, where each component
4252 * provides a different widget type.
4253 * <p>
4254 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004255 *
4256 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4257 * @param packageName The package from which widget providers are white-listed.
4258 * @return Whether the package was added.
4259 *
4260 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4261 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4262 */
Robin Lee25e26452015-06-02 09:56:29 -07004263 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004264 if (mService != null) {
4265 try {
4266 return mService.addCrossProfileWidgetProvider(admin, packageName);
4267 } catch (RemoteException re) {
4268 Log.w(TAG, "Error calling addCrossProfileWidgetProvider", re);
4269 }
4270 }
4271 return false;
4272 }
4273
4274 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004275 * Called by the profile owner of a managed profile to disable widget providers from a given
4276 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004277 * package should have been added via {@link #addCrossProfileWidgetProvider(
4278 * android.content.ComponentName, String)}.
4279 * <p>
4280 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004281 *
4282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4283 * @param packageName The package from which widget providers are no longer
4284 * white-listed.
4285 * @return Whether the package was removed.
4286 *
4287 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4288 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4289 */
Robin Lee25e26452015-06-02 09:56:29 -07004290 public boolean removeCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004291 if (mService != null) {
4292 try {
4293 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4294 } catch (RemoteException re) {
4295 Log.w(TAG, "Error calling removeCrossProfileWidgetProvider", re);
4296 }
4297 }
4298 return false;
4299 }
4300
4301 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004302 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004303 * available in the parent profile.
4304 *
4305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4306 * @return The white-listed package list.
4307 *
4308 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4309 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4310 */
Robin Lee25e26452015-06-02 09:56:29 -07004311 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004312 if (mService != null) {
4313 try {
4314 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4315 if (providers != null) {
4316 return providers;
4317 }
4318 } catch (RemoteException re) {
4319 Log.w(TAG, "Error calling getCrossProfileWidgetProviders", re);
4320 }
4321 }
4322 return Collections.emptyList();
4323 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004324
4325 /**
4326 * Called by profile or device owners to set the current user's photo.
4327 *
4328 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4329 * @param icon the bitmap to set as the photo.
4330 */
Robin Lee25e26452015-06-02 09:56:29 -07004331 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004332 try {
4333 mService.setUserIcon(admin, icon);
4334 } catch (RemoteException re) {
4335 Log.w(TAG, "Could not set the user icon ", re);
4336 }
4337 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004338
4339 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004340 * Called by device owners to set a local system update policy. When a new policy is set,
4341 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004342 *
Robin Lee25e26452015-06-02 09:56:29 -07004343 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4344 * components in the device owner package can set system update policies and the
4345 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004346 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004347 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004348 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004349 */
Robin Lee25e26452015-06-02 09:56:29 -07004350 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004351 if (mService != null) {
4352 try {
Robin Lee25e26452015-06-02 09:56:29 -07004353 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004354 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004355 Log.w(TAG, "Error calling setSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004356 }
4357 }
4358 }
4359
4360 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004361 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004362 *
Robin Lee25e26452015-06-02 09:56:29 -07004363 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004364 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004365 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004366 if (mService != null) {
4367 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01004368 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00004369 } catch (RemoteException re) {
Rubin Xu5faad8e2015-04-20 17:43:48 +01004370 Log.w(TAG, "Error calling getSystemUpdatePolicy", re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004371 }
4372 }
4373 return null;
4374 }
Benjamin Franze36087e2015-04-07 16:40:34 +01004375
4376 /**
4377 * Called by a device owner to disable the keyguard altogether.
4378 *
4379 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
4380 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
4381 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
4382 * being disabled.
4383 *
4384 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004385 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01004386 *
4387 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01004388 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01004389 */
Robin Lee25e26452015-06-02 09:56:29 -07004390 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01004391 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004392 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01004393 } catch (RemoteException re) {
4394 Log.w(TAG, "Failed talking with device policy service", re);
4395 return false;
4396 }
4397 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00004398
4399 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01004400 * Called by device owner to disable the status bar. Disabling the status bar blocks
4401 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00004402 * a single use device.
4403 *
4404 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01004405 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
4406 *
4407 * @return {@code false} if attempting to disable the status bar failed.
4408 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00004409 */
Robin Lee25e26452015-06-02 09:56:29 -07004410 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00004411 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01004412 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00004413 } catch (RemoteException re) {
4414 Log.w(TAG, "Failed talking with device policy service", re);
Benjamin Franzbece8062015-05-06 12:14:31 +01004415 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00004416 }
4417 }
Rubin Xudc105cc2015-04-14 23:38:01 +01004418
4419 /**
4420 * Callable by the system update service to notify device owners about pending updates.
4421 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
4422 * permission.
4423 *
4424 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
4425 * when the current pending update was first available. -1 if no update is available.
4426 * @hide
4427 */
4428 @SystemApi
4429 public void notifyPendingSystemUpdate(long updateReceivedTime) {
4430 if (mService != null) {
4431 try {
4432 mService.notifyPendingSystemUpdate(updateReceivedTime);
4433 } catch (RemoteException re) {
4434 Log.w(TAG, "Could not notify device owner about pending system update", re);
4435 }
4436 }
4437 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04004438
4439 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07004440 * Called by profile or device owners to set the default response for future runtime permission
4441 * requests by applications. The policy can allow for normal operation which prompts the
4442 * user to grant a permission, or can allow automatic granting or denying of runtime
4443 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01004444 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
4445 * the permission grant state via {@link #setPermissionGrantState}.
4446 *
4447 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004448 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004449 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004450 * @param admin Which profile or device owner this request is associated with.
4451 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
4452 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01004453 *
4454 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07004455 */
Robin Lee25e26452015-06-02 09:56:29 -07004456 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004457 try {
4458 mService.setPermissionPolicy(admin, policy);
4459 } catch (RemoteException re) {
4460 Log.w(TAG, "Failed talking with device policy service", re);
4461 }
4462 }
4463
4464 /**
4465 * Returns the current runtime permission policy set by the device or profile owner. The
4466 * default is {@link #PERMISSION_POLICY_PROMPT}.
4467 * @param admin Which profile or device owner this request is associated with.
4468 * @return the current policy for future permission requests.
4469 */
Esteban Talavera28b95702015-06-24 15:23:42 +01004470 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004471 try {
4472 return mService.getPermissionPolicy(admin);
4473 } catch (RemoteException re) {
4474 return PERMISSION_POLICY_PROMPT;
4475 }
4476 }
4477
4478 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004479 * Sets the grant state of a runtime permission for a specific application. The state
4480 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
4481 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
4482 * is denied and the user cannot manage it through the UI, and {@link
4483 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
4484 * user cannot manage it through the UI. This might affect all permissions in a
4485 * group that the runtime permission belongs to. This method can only be called
4486 * by a profile or device owner.
4487 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004488 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
4489 * revoke the permission. It retains the previous grant, if any.
4490 *
4491 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004492 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07004493 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07004494 * @param admin Which profile or device owner this request is associated with.
4495 * @param packageName The application to grant or revoke a permission to.
4496 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004497 * @param grantState The permission grant state which is one of {@link
4498 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
4499 * {@link #PERMISSION_GRANT_STATE_GRANTED},
4500 * @return whether the permission was successfully granted or revoked.
4501 *
4502 * @see #PERMISSION_GRANT_STATE_DENIED
4503 * @see #PERMISSION_GRANT_STATE_DEFAULT
4504 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07004505 */
Robin Lee25e26452015-06-02 09:56:29 -07004506 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004507 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07004508 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07004509 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07004510 } catch (RemoteException re) {
4511 Log.w(TAG, "Failed talking with device policy service", re);
4512 return false;
4513 }
4514 }
Amith Yamasani184b3752015-05-22 13:00:51 -07004515
4516 /**
4517 * Returns the current grant state of a runtime permission for a specific application.
4518 *
4519 * @param admin Which profile or device owner this request is associated with.
4520 * @param packageName The application to check the grant state for.
4521 * @param permission The permission to check for.
4522 * @return the current grant state specified by device policy. If the profile or device owner
4523 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
4524 * This does not indicate whether or not the permission is currently granted for the package.
4525 *
4526 * <p/>If a grant state was set by the profile or device owner, then the return value will
4527 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
4528 * which indicates if the permission is currently denied or granted.
4529 *
4530 * @see #setPermissionGrantState(ComponentName, String, String, int)
4531 * @see PackageManager#checkPermission(String, String)
4532 */
Robin Lee25e26452015-06-02 09:56:29 -07004533 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07004534 String permission) {
4535 try {
4536 return mService.getPermissionGrantState(admin, packageName, permission);
4537 } catch (RemoteException re) {
4538 Log.w(TAG, "Failed talking with device policy service", re);
4539 return PERMISSION_GRANT_STATE_DEFAULT;
4540 }
4541 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00004542
4543 /**
4544 * Returns if provisioning a managed profile or device is possible or not.
4545 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
4546 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
4547 * Note that even if this method returns true, there is a slight possibility that the
4548 * provisioning will not be allowed when it is actually initiated because some event has
4549 * happened in between.
4550 * @return if provisioning a managed profile or device is possible or not.
4551 * @throws IllegalArgumentException if the supplied action is not valid.
4552 */
4553 public boolean isProvisioningAllowed(String action) {
4554 try {
4555 return mService.isProvisioningAllowed(action);
4556 } catch (RemoteException re) {
4557 Log.w(TAG, "Failed talking with device policy service", re);
4558 return false;
4559 }
4560 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00004561
4562 /**
4563 * @hide
4564 * Return if this user is a managed profile of another user. An admin can become the profile
4565 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
4566 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
4567 * @param admin Which profile owner this request is associated with.
4568 * @return if this user is a managed profile of another user.
4569 */
4570 public boolean isManagedProfile(@NonNull ComponentName admin) {
4571 try {
4572 return mService.isManagedProfile(admin);
4573 } catch (RemoteException re) {
4574 Log.w(TAG, "Failed talking with device policy service", re);
4575 return false;
4576 }
4577 }
4578
4579 /**
4580 * @hide
4581 * Return if this user is a system-only user. An admin can manage a device from a system only
4582 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
4583 * @param admin Which device owner this request is associated with.
4584 * @return if this user is a system-only user.
4585 */
4586 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
4587 try {
4588 return mService.isSystemOnlyUser(admin);
4589 } catch (RemoteException re) {
4590 Log.w(TAG, "Failed talking with device policy service", re);
4591 return false;
4592 }
4593 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08004594}