blob: 6c8010d7e2940fd932145fd60936adfceb329716 [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
Alan Treadwayafad8782016-01-19 15:15:08 +000019import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080022import android.annotation.SdkConstant;
23import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050024import android.annotation.SystemApi;
Jason Monkd7b86212014-06-16 13:15:38 -040025import android.app.Activity;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000026import android.auditing.SecurityLog;
27import android.auditing.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080028import android.content.ComponentName;
29import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010030import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000031import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.content.pm.ActivityInfo;
33import android.content.pm.PackageManager;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000034import android.content.pm.ParceledListSlice;
Dianne Hackbornd6847842010-01-12 18:14:19 -080035import android.content.pm.ResolveInfo;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000036import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050037import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040038import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000039import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010040import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070041import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000042import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080043import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.os.RemoteException;
45import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070046import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040047import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000048import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000049import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010050import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070051import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080052import android.util.Log;
53
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070054import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040055import com.android.org.conscrypt.TrustedCertificateStore;
56
Jessica Hummel91da58d2014-04-10 17:39:43 +010057import org.xmlpull.v1.XmlPullParserException;
58
Maggie Benthallda51e682013-08-08 22:35:44 -040059import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080060import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000061import java.lang.annotation.Retention;
62import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070063import java.net.InetSocketAddress;
64import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010065import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000066import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010067import java.security.PrivateKey;
68import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040069import java.security.cert.CertificateException;
70import java.security.cert.CertificateFactory;
71import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010072import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000073import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070074import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070075import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080076import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010077import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080078
79/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000080 * Public interface for managing policies enforced on a device. Most clients of this class must be
81 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000082 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000083 * a device administrator may be registered as either a profile or device owner. A given method is
84 * accessible to all device administrators unless the documentation for that method specifies that
85 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080086 *
87 * <div class="special reference">
88 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000089 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080090 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070091 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080092 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080093 */
94public class DevicePolicyManager {
95 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080096
97 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080098 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +000099 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700100
Makoto Onukic8a5a552015-11-19 14:29:12 -0800101 private static final String REMOTE_EXCEPTION_MESSAGE =
102 "Failed to talk with device policy manager service";
103
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000104 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000105 this(context,
106 IDevicePolicyManager.Stub.asInterface(
107 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
108 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800109 }
110
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800111 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700112 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000113 protected DevicePolicyManager(
114 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 mContext = context;
116 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000117 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 }
119
120 /** @hide */
121 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000122 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800123 return me.mService != null ? me : null;
124 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700125
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700126 /** @hide test will override it. */
127 @VisibleForTesting
128 protected int myUserId() {
129 return UserHandle.myUserId();
130 }
131
Dianne Hackbornd6847842010-01-12 18:14:19 -0800132 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000134 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100135 * <p>A managed profile allows data separation for example for the usage of a
136 * device as a personal and corporate device. The user which provisioning is started from and
137 * the managed profile share a launcher.
138 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800139 * <p>This intent will typically be sent by a mobile device management application (MDM).
140 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
141 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100142 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000143 * <p>It is possible to check if provisioning is allowed or not by querying the method
144 * {@link #isProvisioningAllowed(String)}.
145 *
146 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000147 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700148 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000149 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
150 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000151 *
152 * <p> The intent may also contain the following extras:
153 * <ul>
154 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
155 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
156 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000157 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000158 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
159 * in the provisioning intent. The
160 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
161 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
162 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100163 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100164 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
165 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100166 *
167 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
168 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
169 * the provisioning flow was successful, although this doesn't guarantee the full flow will
170 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
171 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000172 */
173 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
174 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100175 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000176
177 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000178 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000179 * Activity action: Starts the provisioning flow which sets up a managed user.
180 *
181 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800182 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000183 * owner who has full control over the user. Provisioning can only happen before user setup has
184 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
185 * allowed.
186 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000187 * <p>This intent should contain the extra
188 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000189 *
190 * <p> If provisioning fails, the device returns to its previous state.
191 *
192 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
193 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
194 * the provisioning flow was successful, although this doesn't guarantee the full flow will
195 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
196 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000197 */
198 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
199 public static final String ACTION_PROVISION_MANAGED_USER
200 = "android.app.action.PROVISION_MANAGED_USER";
201
202 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100203 * Activity action: Starts the provisioning flow which sets up a managed device.
204 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
205 *
206 * <p> During device owner provisioning a device admin app is set as the owner of the device.
207 * A device owner has full control over the device. The device owner can not be modified by the
208 * user.
209 *
210 * <p> A typical use case would be a device that is owned by a company, but used by either an
211 * employee or client.
212 *
213 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000214 * It is possible to check if provisioning is allowed or not by querying the method
215 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100216 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000217 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100218 * <ul>
219 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
220 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
221 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100222 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000223 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000224 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100225 * </ul>
226 *
227 * <p> When device owner provisioning has completed, an intent of the type
228 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
229 * device owner.
230 *
231 * <p> If provisioning fails, the device is factory reset.
232 *
Alan Treadway4582f812015-07-28 11:49:35 +0100233 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
234 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
235 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
236 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 */
238 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
239 public static final String ACTION_PROVISION_MANAGED_DEVICE
240 = "android.app.action.PROVISION_MANAGED_DEVICE";
241
242 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000243 * Activity action: Starts the provisioning flow which sets up a managed device.
244 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
245 *
246 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
247 * management state that is distinct from that reached by
248 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
249 * user, and only has control over device-wide policies, not individual users and their data.
250 * The primary benefit is that multiple non-system users are supported when provisioning using
251 * this form of device management.
252 *
253 * <p> During device owner provisioning a device admin app is set as the owner of the device.
254 * A device owner has full control over the device. The device owner can not be modified by the
255 * user.
256 *
257 * <p> A typical use case would be a device that is owned by a company, but used by either an
258 * employee or client.
259 *
260 * <p> An intent with this action can be sent only on an unprovisioned device.
261 * It is possible to check if provisioning is allowed or not by querying the method
262 * {@link #isProvisioningAllowed(String)}.
263 *
264 * <p>The intent contains the following extras:
265 * <ul>
266 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
267 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
270 * </ul>
271 *
272 * <p> When device owner provisioning has completed, an intent of the type
273 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
274 * device owner.
275 *
276 * <p> If provisioning fails, the device is factory reset.
277 *
278 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
279 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
280 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
281 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
282 *
283 * @hide
284 */
285 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
286 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
287 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
288
289 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000290 * Activity action: Finalizes management provisioning, should be used after user-setup
291 * has been completed and {@link #getUserProvisioningState()} returns one of:
292 * <ul>
293 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
294 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
295 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
296 * </ul>
297 *
298 * @hide
299 */
300 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
301 public static final String ACTION_PROVISION_FINALIZATION
302 = "android.app.action.PROVISION_FINALIZATION";
303
304 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100305 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100306 * allows a mobile device management application or NFC programmer application which starts
307 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100308 * <p>
309 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
310 * sends the intent to pass data to itself on the newly created profile.
311 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
312 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100313 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
314 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
315 * message should contain a stringified {@link java.util.Properties} instance, whose string
316 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
317 * management application after provisioning.
318 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100319 * <p>
320 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700321 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
322 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100323 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100324 */
325 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100326 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100327
328 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100329 * A String extra holding the package name of the mobile device management application that
330 * will be set as the profile owner or device owner.
331 *
332 * <p>If an application starts provisioning directly via an intent with action
333 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
334 * application that started provisioning. The package will be set as profile owner in that case.
335 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000336 * <p>This package is set as device owner when device owner provisioning is started by an NFC
337 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000338 *
339 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700340 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000341
342 * @see DeviceAdminReceiver
343 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100344 * supported, but only if there is only one device admin receiver in the package that requires
345 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000346 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000347 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000348 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100349 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000350
351 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000352 * A ComponentName extra indicating the device admin receiver of the mobile device management
353 * application that will be set as the profile owner or device owner and active admin.
354 *
355 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100356 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
357 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
358 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000359 *
360 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100361 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
362 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400363 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000364 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000365 *
366 * @see DeviceAdminReceiver
367 */
368 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
369 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
370
371 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000372 * An {@link android.accounts.Account} extra holding the account to migrate during managed
373 * profile provisioning. If the account supplied is present in the primary user, it will be
374 * copied, along with its credentials to the managed profile and removed from the primary user.
375 *
376 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
377 */
378
379 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
380 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
381
382 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100383 * A String extra that, holds the email address of the account which a managed profile is
384 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
385 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100386 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100387 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
388 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100389 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
390 * contains this extra, it is forwarded in the
391 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
392 * device management application that was set as the profile owner during provisioning.
393 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100394 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100395 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
396 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100397
398 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000399 * A integer extra indicating the predominant color to show during the provisioning.
400 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000401 *
402 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
403 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
404 */
405 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
406 "android.app.extra.PROVISIONING_MAIN_COLOR";
407
408 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000409 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700410 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000411 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100412 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
413 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000414 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000415 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
416 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000417
418 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100419 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
420 * will be set to.
421 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000422 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
423 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100424 */
425 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100426 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100427
428 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100429 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
430 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100431 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000432 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
433 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100434 */
435 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100436 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100437
438 /**
439 * A String extra holding the {@link java.util.Locale} that the device will be set to.
440 * Format: xx_yy, where xx is the language code, and yy the country code.
441 *
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_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100446 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100447
448 /**
449 * A String extra holding the ssid of the wifi network that should be used during nfc device
450 * owner provisioning for downloading the mobile device management application.
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_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100456 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100457
458 /**
459 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
460 * is hidden or not.
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_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100466 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100467
468 /**
469 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100470 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
471 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100472 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000473 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
474 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100475 */
476 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100477 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100478
479 /**
480 * A String extra holding the password of the wifi network in
481 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
482 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000483 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
484 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100485 */
486 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100487 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100488
489 /**
490 * A String extra holding the proxy host for the wifi network in
491 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
492 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000493 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
494 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100495 */
496 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100497 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100498
499 /**
500 * An int extra holding the proxy port for the wifi network in
501 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
502 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000503 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
504 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100505 */
506 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100507 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100508
509 /**
510 * A String extra holding the proxy bypass for the wifi network in
511 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
512 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000513 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
514 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100515 */
516 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100517 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100518
519 /**
520 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
521 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
522 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000523 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
524 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100525 */
526 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100527 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100528
529 /**
530 * A String extra holding a url that specifies the download location of the device admin
531 * package. When not provided it is assumed that the device admin package is already installed.
532 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000533 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
534 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100535 */
536 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100537 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100538
539 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400540 * An int extra holding a minimum required version code for the device admin package. If the
541 * device admin is already installed on the device, it will only be re-downloaded from
542 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
543 * installed package is less than this version code.
544 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400546 * provisioning via an NFC bump.
547 */
548 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
549 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
550
551 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100552 * A String extra holding a http cookie header which should be used in the http request to the
553 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
554 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000555 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
556 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100557 */
558 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100559 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100560
561 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100562 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
563 * the file at download location specified in
564 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100565 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100566 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100567 * present. The provided checksum should match the checksum of the file at the download
568 * location. If the checksum doesn't match an error will be shown to the user and the user will
569 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000571 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
572 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100573 *
574 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
575 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700576 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100577 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578 */
579 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100580 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581
582 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100583 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100584 * android package archive at the download location specified in {@link
585 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
586 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100587 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100588 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
589 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
590 *
591 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100592 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100593 * the download location. If the checksum does not match an error will be shown to the user and
594 * the user will be asked to factory reset the device.
595 *
596 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
597 * provisioning via an NFC bump.
598 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100599 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
600 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100601
602 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000603 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
604 * has completed successfully.
605 *
606 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700607 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000608 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800609 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000610 * corresponds to the account requested to be migrated at provisioning time, if any.
611 */
612 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
613 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
614 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
615
616 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400617 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500618 * provisioning.
619 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400620 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100621 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500622 */
623 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
624 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
625
626 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000627 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
628 * provisioning. If this extra is not passed, a default image will be shown.
629 * <h5>The following URI schemes are accepted:</h5>
630 * <ul>
631 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
632 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
633 * </ul>
634 *
635 * <p> It is the responsability of the caller to provide an image with a reasonable
636 * pixed density for the device.
637 *
638 * <p> If a content: URI is passed, the intent should have the flag
639 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
640 * {@link android.content.ClipData} of the intent too.
641 *
642 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
643 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
644 */
645 public static final String EXTRA_PROVISIONING_LOGO_URI =
646 "android.app.extra.PROVISIONING_LOGO_URI";
647
648 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000649 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
650 * during setup-wizard.
651 *
652 * <p>If unspecified, defaults to {@code true} to match the behavior in
653 * {@link android.os.Build.VERSION_CODES#M} and earlier.
654 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000655 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
656 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000657 *
658 * @hide
659 */
660 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
661 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
662
663 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400664 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100665 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400666 * <p>During device owner provisioning a device admin app is set as the owner of the device.
667 * A device owner has full control over the device. The device owner can not be modified by the
668 * user and the only way of resetting the device is if the device owner app calls a factory
669 * reset.
670 *
671 * <p> A typical use case would be a device that is owned by a company, but used by either an
672 * employee or client.
673 *
674 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100675 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000676 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100677 * contains the following properties:
678 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400679 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
680 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100681 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400682 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100683 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
684 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
685 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
686 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
687 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
688 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
689 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
690 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
691 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
692 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100693 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
694 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
695 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100696 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000697 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700698 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400699 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
700 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
701 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400702 */
703 public static final String MIME_TYPE_PROVISIONING_NFC
704 = "application/com.android.managedprovisioning";
705
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100706 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800707 * Activity action: ask the user to add a new device administrator to the system.
708 * The desired policy is the ComponentName of the policy in the
709 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
710 * bring the user through adding the device administrator to the system (or
711 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700712 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800713 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
714 * field to provide the user with additional explanation (in addition
715 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800716 *
717 * <p>If your administrator is already active, this will ordinarily return immediately (without
718 * user intervention). However, if your administrator has been updated and is requesting
719 * additional uses-policy flags, the user will be presented with the new list. New policies
720 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800721 */
722 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
723 public static final String ACTION_ADD_DEVICE_ADMIN
724 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700725
Dianne Hackbornd6847842010-01-12 18:14:19 -0800726 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700727 * @hide
728 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700729 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700730 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700731 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
732 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700733 * to remotely control restrictions on the user.
734 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800735 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700736 * result of whether or not the user approved the action. If approved, the result will
737 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
738 * as a profile owner.
739 *
740 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
741 * field to provide the user with additional explanation (in addition
742 * to your component's description) about what is being added.
743 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700744 * <p>If there is already a profile owner active or the caller is not a system app, the
745 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700746 */
747 @SystemApi
748 public static final String ACTION_SET_PROFILE_OWNER
749 = "android.app.action.SET_PROFILE_OWNER";
750
751 /**
752 * @hide
753 * Name of the profile owner admin that controls the user.
754 */
755 @SystemApi
756 public static final String EXTRA_PROFILE_OWNER_NAME
757 = "android.app.extra.PROFILE_OWNER_NAME";
758
759 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100760 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700761 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700762 *
Jim Miller284b62e2010-06-08 14:27:42 -0700763 * @hide
764 */
765 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
766 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
767
768 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100769 * Broadcast action: sent when the device owner is set or changed.
770 *
771 * This broadcast is sent only to the primary user.
772 * @see #ACTION_PROVISION_MANAGED_DEVICE
773 */
774 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
775 public static final String ACTION_DEVICE_OWNER_CHANGED
776 = "android.app.action.DEVICE_OWNER_CHANGED";
777
778 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800779 * The ComponentName of the administrator component.
780 *
781 * @see #ACTION_ADD_DEVICE_ADMIN
782 */
783 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700784
Dianne Hackbornd6847842010-01-12 18:14:19 -0800785 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800786 * An optional CharSequence providing additional explanation for why the
787 * admin is being added.
788 *
789 * @see #ACTION_ADD_DEVICE_ADMIN
790 */
791 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700792
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800793 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700794 * Activity action: have the user enter a new password. This activity should
795 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
796 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
797 * enter a new password that meets the current requirements. You can use
798 * {@link #isActivePasswordSufficient()} to determine whether you need to
799 * have the user select a new password in order to meet the current
800 * constraints. Upon being resumed from this activity, you can check the new
801 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000802 *
803 * If the intent is launched from within a managed profile with a profile
804 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
805 * this will trigger entering a new password for the parent of the profile.
806 * For all other cases it will trigger entering a new password for the user
807 * or profile it is launched from.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800808 */
809 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
810 public static final String ACTION_SET_NEW_PASSWORD
811 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700812
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000813 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000814 * Activity action: have the user enter a new password for the parent profile.
815 * If the intent is launched from within a managed profile, this will trigger
816 * entering a new password for the parent of the profile. In all other cases
817 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
818 */
819 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
820 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
821 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
822
823 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000824 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
825 * the parent profile to access intents sent from the managed profile.
826 * That is, when an app in the managed profile calls
827 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
828 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000829 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100830 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000831
832 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000833 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
834 * the managed profile to access intents sent from the parent profile.
835 * That is, when an app in the parent profile calls
836 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
837 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000838 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100839 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700840
Dianne Hackbornd6847842010-01-12 18:14:19 -0800841 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100842 * Broadcast action: notify that a new local system update policy has been set by the device
843 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000844 */
845 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100846 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
847 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000848
Amith Yamasanid49489b2015-04-28 14:00:26 -0700849 /**
850 * Permission policy to prompt user for new permission requests for runtime permissions.
851 * Already granted or denied permissions are not affected by this.
852 */
853 public static final int PERMISSION_POLICY_PROMPT = 0;
854
855 /**
856 * Permission policy to always grant new permission requests for runtime permissions.
857 * Already granted or denied permissions are not affected by this.
858 */
859 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
860
861 /**
862 * Permission policy to always deny new permission requests for runtime permissions.
863 * Already granted or denied permissions are not affected by this.
864 */
865 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
866
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700867 /**
868 * Runtime permission state: The user can manage the permission
869 * through the UI.
870 */
871 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
872
873 /**
874 * Runtime permission state: The permission is granted to the app
875 * and the user cannot manage the permission through the UI.
876 */
877 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
878
879 /**
880 * Runtime permission state: The permission is denied to the app
881 * and the user cannot manage the permission through the UI.
882 */
883 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000884
885 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000886 * No management for current user in-effect. This is the default.
887 * @hide
888 */
889 public static final int STATE_USER_UNMANAGED = 0;
890
891 /**
892 * Management partially setup, user setup needs to be completed.
893 * @hide
894 */
895 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
896
897 /**
898 * Management partially setup, user setup completed.
899 * @hide
900 */
901 public static final int STATE_USER_SETUP_COMPLETE = 2;
902
903 /**
904 * Management setup and active on current user.
905 * @hide
906 */
907 public static final int STATE_USER_SETUP_FINALIZED = 3;
908
909 /**
910 * Management partially setup on a managed profile.
911 * @hide
912 */
913 public static final int STATE_USER_PROFILE_COMPLETE = 4;
914
915 /**
916 * @hide
917 */
918 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
919 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
920 @Retention(RetentionPolicy.SOURCE)
921 public @interface UserProvisioningState {}
922
923 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800924 * Return true if the given administrator component is currently
925 * active (enabled) in the system.
926 */
Robin Lee25e26452015-06-02 09:56:29 -0700927 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700928 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100929 }
930
931 /**
932 * @see #isAdminActive(ComponentName)
933 * @hide
934 */
Robin Lee25e26452015-06-02 09:56:29 -0700935 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800936 if (mService != null) {
937 try {
Robin Lee25e26452015-06-02 09:56:29 -0700938 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800939 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800941 }
942 }
943 return false;
944 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800945 /**
946 * Return true if the given administrator component is currently being removed
947 * for the user.
948 * @hide
949 */
Robin Lee25e26452015-06-02 09:56:29 -0700950 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800951 if (mService != null) {
952 try {
Robin Lee25e26452015-06-02 09:56:29 -0700953 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800954 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800955 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800956 }
957 }
958 return false;
959 }
960
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700961
Dianne Hackbornd6847842010-01-12 18:14:19 -0800962 /**
Robin Lee25e26452015-06-02 09:56:29 -0700963 * Return a list of all currently active device administrators' component
964 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800965 * returned.
966 */
967 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700968 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100969 }
970
971 /**
972 * @see #getActiveAdmins()
973 * @hide
974 */
975 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800976 if (mService != null) {
977 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100978 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800979 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800980 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800981 }
982 }
983 return null;
984 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700985
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -0800986 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -0700987 * Used by package administration code to determine if a package can be stopped
988 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800989 * @hide
990 */
991 public boolean packageHasActiveAdmins(String packageName) {
992 if (mService != null) {
993 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700994 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800995 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800996 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800997 }
998 }
999 return false;
1000 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001001
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001002 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001003 * Remove a current administration component. This can only be called
1004 * by the application that owns the administration component; if you
1005 * try to remove someone else's component, a security exception will be
1006 * thrown.
1007 */
Robin Lee25e26452015-06-02 09:56:29 -07001008 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001009 if (mService != null) {
1010 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001011 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001012 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001013 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001014 }
1015 }
1016 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001017
Dianne Hackbornd6847842010-01-12 18:14:19 -08001018 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001019 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001020 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001021 * but requires additional policies after an upgrade.
1022 *
1023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1024 * an active administrator, or an exception will be thrown.
1025 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1026 */
Robin Lee25e26452015-06-02 09:56:29 -07001027 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001028 if (mService != null) {
1029 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001030 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001031 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001032 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001033 }
1034 }
1035 return false;
1036 }
1037
1038 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001039 * Returns true if the Profile Challenge is available to use for the given profile user.
1040 *
1041 * @hide
1042 */
1043 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1044 if (mService != null) {
1045 try {
1046 return mService.isSeparateProfileChallengeAllowed(userHandle);
1047 } catch (RemoteException e) {
1048 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1049 }
1050 }
1051 return false;
1052 }
1053
1054 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001055 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1056 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001057 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001058 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001059 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001060
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001062 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1063 * recognition technology. This implies technologies that can recognize the identity of
1064 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1065 * Note that quality constants are ordered so that higher values are more restrictive.
1066 */
1067 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1068
1069 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001070 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001071 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001072 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001074 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001075
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001076 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001077 * Constant for {@link #setPasswordQuality}: the user must have entered a
1078 * password containing at least numeric characters. Note that quality
1079 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001080 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001081 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001082
Dianne Hackbornd6847842010-01-12 18:14:19 -08001083 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001084 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001085 * password containing at least numeric characters with no repeating (4444)
1086 * or ordered (1234, 4321, 2468) sequences. Note that quality
1087 * constants are ordered so that higher values are more restrictive.
1088 */
1089 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1090
1091 /**
1092 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001093 * password containing at least alphabetic (or other symbol) characters.
1094 * Note that quality constants are ordered so that higher values are more
1095 * restrictive.
1096 */
1097 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001098
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001099 /**
1100 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001101 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001102 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001103 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001104 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001105 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001106
Dianne Hackbornd6847842010-01-12 18:14:19 -08001107 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001108 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001109 * password containing at least a letter, a numerical digit and a special
1110 * symbol, by default. With this password quality, passwords can be
1111 * restricted to contain various sets of characters, like at least an
1112 * uppercase letter, etc. These are specified using various methods,
1113 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1114 * that quality constants are ordered so that higher values are more
1115 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001116 */
1117 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1118
1119 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001120 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1121 * modify password. In case this password quality is set, the password is
1122 * managed by a profile owner. The profile owner can set any password,
1123 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1124 * that quality constants are ordered so that higher values are more
1125 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1126 * the highest.
1127 * @hide
1128 */
1129 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1130
1131 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001132 * Called by an application that is administering the device to set the
1133 * password restrictions it is imposing. After setting this, the user
1134 * will not be able to enter a new password that is not at least as
1135 * restrictive as what has been set. Note that the current password
1136 * will remain until the user has set a new one, so the change does not
1137 * take place immediately. To prompt the user for a new password, use
1138 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001139 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001140 * <p>Quality constants are ordered so that higher values are more restrictive;
1141 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001142 * the user's preference, and any other considerations) is the one that
1143 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001144 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001145 * <p>The calling device admin must have requested
1146 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1147 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001148 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001150 * @param quality The new desired quality. One of
1151 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001152 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1153 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1154 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001155 */
Robin Lee25e26452015-06-02 09:56:29 -07001156 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001157 if (mService != null) {
1158 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001159 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001160 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001161 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001162 }
1163 }
1164 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001165
Dianne Hackbornd6847842010-01-12 18:14:19 -08001166 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001167 * Retrieve the current minimum password quality for all admins of this user
1168 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001169 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001170 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001171 */
Robin Lee25e26452015-06-02 09:56:29 -07001172 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001173 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001174 }
1175
1176 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001177 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001178 if (mService != null) {
1179 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001180 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001181 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001182 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001183 }
1184 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001185 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001186 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001187
Dianne Hackbornd6847842010-01-12 18:14:19 -08001188 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001189 * Called by an application that is administering the device to set the
1190 * minimum allowed password length. After setting this, the user
1191 * will not be able to enter a new password that is not at least as
1192 * restrictive as what has been set. Note that the current password
1193 * will remain until the user has set a new one, so the change does not
1194 * take place immediately. To prompt the user for a new password, use
1195 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1196 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001197 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1198 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1199 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001200 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001201 * <p>The calling device admin must have requested
1202 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1203 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001204 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001205 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001206 * @param length The new desired minimum password length. A value of 0
1207 * means there is no restriction.
1208 */
Robin Lee25e26452015-06-02 09:56:29 -07001209 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001210 if (mService != null) {
1211 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001212 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001213 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001214 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 }
1216 }
1217 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001218
Dianne Hackbornd6847842010-01-12 18:14:19 -08001219 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001220 * Retrieve the current minimum password length for all admins of this
1221 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001222 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001223 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001224 */
Robin Lee25e26452015-06-02 09:56:29 -07001225 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001226 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001227 }
1228
1229 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001230 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001231 if (mService != null) {
1232 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001233 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001235 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001236 }
1237 }
1238 return 0;
1239 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001240
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001241 /**
1242 * Called by an application that is administering the device to set the
1243 * minimum number of upper case letters required in the password. After
1244 * setting this, the user will not be able to enter a new password that is
1245 * not at least as restrictive as what has been set. Note that the current
1246 * password will remain until the user has set a new one, so the change does
1247 * not take place immediately. To prompt the user for a new password, use
1248 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1249 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001250 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1251 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001252 * <p>
1253 * The calling device admin must have requested
1254 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1255 * this method; if it has not, a security exception will be thrown.
1256 *
1257 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1258 * with.
1259 * @param length The new desired minimum number of upper case letters
1260 * required in the password. A value of 0 means there is no
1261 * restriction.
1262 */
Robin Lee25e26452015-06-02 09:56:29 -07001263 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001264 if (mService != null) {
1265 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001266 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001267 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001268 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001269 }
1270 }
1271 }
1272
1273 /**
1274 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001275 * password for all admins of this user and its profiles or a particular one.
1276 * This is the same value as set by
1277 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001278 * and only applies when the password quality is
1279 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001280 *
Robin Lee25e26452015-06-02 09:56:29 -07001281 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001282 * aggregate all admins.
1283 * @return The minimum number of upper case letters required in the
1284 * password.
1285 */
Robin Lee25e26452015-06-02 09:56:29 -07001286 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001287 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001288 }
1289
1290 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001291 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001292 if (mService != null) {
1293 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001294 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001295 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001296 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001297 }
1298 }
1299 return 0;
1300 }
1301
1302 /**
1303 * Called by an application that is administering the device to set the
1304 * minimum number of lower case letters required in the password. After
1305 * setting this, the user will not be able to enter a new password that is
1306 * not at least as restrictive as what has been set. Note that the current
1307 * password will remain until the user has set a new one, so the change does
1308 * not take place immediately. To prompt the user for a new password, use
1309 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1310 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001311 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1312 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001313 * <p>
1314 * The calling device admin must have requested
1315 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1316 * this method; if it has not, a security exception will be thrown.
1317 *
1318 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1319 * with.
1320 * @param length The new desired minimum number of lower case letters
1321 * required in the password. A value of 0 means there is no
1322 * restriction.
1323 */
Robin Lee25e26452015-06-02 09:56:29 -07001324 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 if (mService != null) {
1326 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001327 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001328 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001329 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001330 }
1331 }
1332 }
1333
1334 /**
1335 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001336 * password for all admins of this user and its profiles or a particular one.
1337 * This is the same value as set by
1338 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001339 * and only applies when the password quality is
1340 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001341 *
Robin Lee25e26452015-06-02 09:56:29 -07001342 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001343 * aggregate all admins.
1344 * @return The minimum number of lower case letters required in the
1345 * password.
1346 */
Robin Lee25e26452015-06-02 09:56:29 -07001347 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001348 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001349 }
1350
1351 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001352 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001353 if (mService != null) {
1354 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001355 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001356 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001357 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001358 }
1359 }
1360 return 0;
1361 }
1362
1363 /**
1364 * Called by an application that is administering the device to set the
1365 * minimum number of letters required in the password. After setting this,
1366 * the user will not be able to enter a new password that is not at least as
1367 * restrictive as what has been set. Note that the current password will
1368 * remain until the user has set a new one, so the change does not take
1369 * place immediately. To prompt the user for a new password, use
1370 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1371 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001372 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1373 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001374 * <p>
1375 * The calling device admin must have requested
1376 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1377 * this method; if it has not, a security exception will be thrown.
1378 *
1379 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1380 * with.
1381 * @param length The new desired minimum number of letters required in the
1382 * password. A value of 0 means there is no restriction.
1383 */
Robin Lee25e26452015-06-02 09:56:29 -07001384 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001385 if (mService != null) {
1386 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001387 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001388 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001389 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001390 }
1391 }
1392 }
1393
1394 /**
1395 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001396 * admins or a particular one. This is the same value as
1397 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1398 * and only applies when the password quality is
1399 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 *
Robin Lee25e26452015-06-02 09:56:29 -07001401 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001402 * aggregate all admins.
1403 * @return The minimum number of letters required in the password.
1404 */
Robin Lee25e26452015-06-02 09:56:29 -07001405 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001406 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001407 }
1408
1409 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001410 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001411 if (mService != null) {
1412 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001413 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001414 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001415 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001416 }
1417 }
1418 return 0;
1419 }
1420
1421 /**
1422 * Called by an application that is administering the device to set the
1423 * minimum number of numerical digits required in the password. After
1424 * setting this, the user will not be able to enter a new password that is
1425 * not at least as restrictive as what has been set. Note that the current
1426 * password will remain until the user has set a new one, so the change does
1427 * not take place immediately. To prompt the user for a new password, use
1428 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1429 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001430 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1431 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001432 * <p>
1433 * The calling device admin must have requested
1434 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1435 * this method; if it has not, a security exception will be thrown.
1436 *
1437 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1438 * with.
1439 * @param length The new desired minimum number of numerical digits required
1440 * in the password. A value of 0 means there is no restriction.
1441 */
Robin Lee25e26452015-06-02 09:56:29 -07001442 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 if (mService != null) {
1444 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001445 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001446 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001447 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001448 }
1449 }
1450 }
1451
1452 /**
1453 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001454 * for all admins of this user and its profiles or a particular one.
1455 * This is the same value as set by
1456 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001457 * and only applies when the password quality is
1458 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001459 *
Robin Lee25e26452015-06-02 09:56:29 -07001460 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001461 * aggregate all admins.
1462 * @return The minimum number of numerical digits required in the password.
1463 */
Robin Lee25e26452015-06-02 09:56:29 -07001464 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001465 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001466 }
1467
1468 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001469 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001470 if (mService != null) {
1471 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001472 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001473 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001474 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001475 }
1476 }
1477 return 0;
1478 }
1479
1480 /**
1481 * Called by an application that is administering the device to set the
1482 * minimum number of symbols required in the password. After setting this,
1483 * the user will not be able to enter a new password that is not at least as
1484 * restrictive as what has been set. Note that the current password will
1485 * remain until the user has set a new one, so the change does not take
1486 * place immediately. To prompt the user for a new password, use
1487 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1488 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001489 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1490 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001491 * <p>
1492 * The calling device admin must have requested
1493 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1494 * this method; if it has not, a security exception will be thrown.
1495 *
1496 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1497 * with.
1498 * @param length The new desired minimum number of symbols required in the
1499 * password. A value of 0 means there is no restriction.
1500 */
Robin Lee25e26452015-06-02 09:56:29 -07001501 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001502 if (mService != null) {
1503 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001504 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001505 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001506 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001507 }
1508 }
1509 }
1510
1511 /**
1512 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001513 * admins or a particular one. This is the same value as
1514 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1515 * and only applies when the password quality is
1516 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001517 *
Robin Lee25e26452015-06-02 09:56:29 -07001518 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001519 * aggregate all admins.
1520 * @return The minimum number of symbols required in the password.
1521 */
Robin Lee25e26452015-06-02 09:56:29 -07001522 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001523 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001524 }
1525
1526 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001527 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001528 if (mService != null) {
1529 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001530 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001531 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001532 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001533 }
1534 }
1535 return 0;
1536 }
1537
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001538 /**
1539 * Called by an application that is administering the device to set the
1540 * minimum number of non-letter characters (numerical digits or symbols)
1541 * required in the password. After setting this, the user will not be able
1542 * to enter a new password that is not at least as restrictive as what has
1543 * been set. Note that the current password will remain until the user has
1544 * set a new one, so the change does not take place immediately. To prompt
1545 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1546 * setting this value. This constraint is only imposed if the administrator
1547 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1548 * {@link #setPasswordQuality}. The default value is 0.
1549 * <p>
1550 * The calling device admin must have requested
1551 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1552 * this method; if it has not, a security exception will be thrown.
1553 *
1554 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1555 * with.
1556 * @param length The new desired minimum number of letters required in the
1557 * password. A value of 0 means there is no restriction.
1558 */
Robin Lee25e26452015-06-02 09:56:29 -07001559 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001560 if (mService != null) {
1561 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001562 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001563 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001564 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001565 }
1566 }
1567 }
1568
1569 /**
1570 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001571 * password for all admins of this user and its profiles or a particular one.
1572 * This is the same value as set by
1573 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001574 * and only applies when the password quality is
1575 * {@link #PASSWORD_QUALITY_COMPLEX}.
1576 *
Robin Lee25e26452015-06-02 09:56:29 -07001577 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001578 * aggregate all admins.
1579 * @return The minimum number of letters required in the password.
1580 */
Robin Lee25e26452015-06-02 09:56:29 -07001581 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001582 return getPasswordMinimumNonLetter(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 getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001587 if (mService != null) {
1588 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001589 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001590 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001591 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001592 }
1593 }
1594 return 0;
1595 }
1596
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001597 /**
1598 * Called by an application that is administering the device to set the length
1599 * of the password history. After setting this, the user will not be able to
1600 * enter a new password that is the same as any password in the history. Note
1601 * that the current password will remain until the user has set a new one, so
1602 * the change does not take place immediately. To prompt the user for a new
1603 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1604 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001605 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1606 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1607 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001608 *
1609 * <p>
1610 * The calling device admin must have requested
1611 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1612 * method; if it has not, a security exception will be thrown.
1613 *
1614 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1615 * with.
1616 * @param length The new desired length of password history. A value of 0
1617 * means there is no restriction.
1618 */
Robin Lee25e26452015-06-02 09:56:29 -07001619 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001620 if (mService != null) {
1621 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001622 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001623 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001624 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001625 }
1626 }
1627 }
1628
1629 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001630 * Called by a device admin to set the password expiration timeout. Calling this method
1631 * will restart the countdown for password expiration for the given admin, as will changing
1632 * the device password (for all admins).
1633 *
1634 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1635 * For example, to have the password expire 5 days from now, timeout would be
1636 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1637 *
1638 * <p>To disable password expiration, a value of 0 may be used for timeout.
1639 *
Jim Millera4e28d12010-11-08 16:15:47 -08001640 * <p>The calling device admin must have requested
1641 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1642 * method; if it has not, a security exception will be thrown.
1643 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001644 * <p> Note that setting the password will automatically reset the expiration time for all
1645 * active admins. Active admins do not need to explicitly call this method in that case.
1646 *
Jim Millera4e28d12010-11-08 16:15:47 -08001647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1648 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1649 * means there is no restriction (unlimited).
1650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001652 if (mService != null) {
1653 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001654 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001655 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001656 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001657 }
1658 }
1659 }
1660
1661 /**
Jim Miller6b857682011-02-16 16:27:41 -08001662 * Get the password expiration timeout for the given admin. The expiration timeout is the
1663 * recurring expiration timeout provided in the call to
1664 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001665 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001666 *
Robin Lee25e26452015-06-02 09:56:29 -07001667 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001668 * @return The timeout for the given admin or the minimum of all timeouts
1669 */
Robin Lee25e26452015-06-02 09:56:29 -07001670 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001671 if (mService != null) {
1672 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001673 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001674 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001675 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001676 }
1677 }
1678 return 0;
1679 }
1680
1681 /**
1682 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001683 * all admins of this user and its profiles if admin is null. If the password is
1684 * expired, this will return the time since the password expired as a negative number.
1685 * If admin is null, then a composite of all expiration timeouts is returned
1686 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001687 *
Robin Lee25e26452015-06-02 09:56:29 -07001688 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001689 * @return The password expiration time, in ms.
1690 */
Robin Lee25e26452015-06-02 09:56:29 -07001691 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001692 if (mService != null) {
1693 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001694 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001695 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001696 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001697 }
1698 }
1699 return 0;
1700 }
1701
1702 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001703 * Retrieve the current password history length for all admins of this
1704 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001705 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001706 * all admins.
1707 * @return The length of the password history
1708 */
Robin Lee25e26452015-06-02 09:56:29 -07001709 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001710 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001711 }
1712
1713 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001714 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001715 if (mService != null) {
1716 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001717 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001718 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001719 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001720 }
1721 }
1722 return 0;
1723 }
1724
Dianne Hackbornd6847842010-01-12 18:14:19 -08001725 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001726 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001727 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001728 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001729 * @return Returns the maximum length that the user can enter.
1730 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001731 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001732 // Kind-of arbitrary.
1733 return 16;
1734 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001735
Dianne Hackborn254cb442010-01-27 19:23:59 -08001736 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001737 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001738 * to meet the policy requirements (quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001739 * requested by the admins of this user and its profiles that don't have a separate challenge.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001740 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001741 * <p>The calling device admin must have requested
1742 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1743 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001744 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001745 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001746 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001747 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001748 if (mService != null) {
1749 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001750 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001751 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001752 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001753 }
1754 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001755 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001756 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001757
Dianne Hackbornd6847842010-01-12 18:14:19 -08001758 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001759 * Determine whether the current profile password the user has set is sufficient
1760 * to meet the policy requirements (quality, minimum length) that have been
1761 * requested by the admins of the parent user and its profiles.
1762 *
1763 * @param userHandle the userId of the profile to check the password for.
1764 * @return Returns true if the password would meet the current requirements, else false.
1765 * @hide
1766 */
1767 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1768 if (mService != null) {
1769 try {
1770 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1771 } catch (RemoteException e) {
1772 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1773 }
1774 }
1775 return false;
1776 }
1777
1778 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001779 * Retrieve the number of times the user has failed at entering a
1780 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001781 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001782 * <p>The calling device admin must have requested
1783 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1784 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001785 */
1786 public int getCurrentFailedPasswordAttempts() {
1787 if (mService != null) {
1788 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001789 return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001790 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001791 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001792 }
1793 }
1794 return -1;
1795 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001796
1797 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001798 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001799 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001800 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001801 * @hide
1802 */
1803 public boolean getDoNotAskCredentialsOnBoot() {
1804 if (mService != null) {
1805 try {
1806 return mService.getDoNotAskCredentialsOnBoot();
1807 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001808 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001809 }
1810 }
1811 return false;
1812 }
1813
1814 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001815 * Setting this to a value greater than zero enables a built-in policy
1816 * that will perform a device wipe after too many incorrect
1817 * device-unlock passwords have been entered. This built-in policy combines
1818 * watching for failed passwords and wiping the device, and requires
1819 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001820 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001821 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001822 * <p>To implement any other policy (e.g. wiping data for a particular
1823 * application only, erasing or revoking credentials, or reporting the
1824 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001825 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001826 * instead. Do not use this API, because if the maximum count is reached,
1827 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001828 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001829 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001830 * @param num The number of failed password attempts at which point the
1831 * device will wipe its data.
1832 */
Robin Lee25e26452015-06-02 09:56:29 -07001833 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001834 if (mService != null) {
1835 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001836 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001837 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001838 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001839 }
1840 }
1841 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001842
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001843 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001844 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001845 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001846 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001847 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001848 * all admins.
1849 */
Robin Lee25e26452015-06-02 09:56:29 -07001850 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001851 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001852 }
1853
1854 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001855 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001856 if (mService != null) {
1857 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001858 return mService.getMaximumFailedPasswordsForWipe(
1859 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001860 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001861 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001862 }
1863 }
1864 return 0;
1865 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001866
Dianne Hackborn254cb442010-01-27 19:23:59 -08001867 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001868 * Returns the profile with the smallest maximum failed passwords for wipe,
1869 * for the given user. So for primary user, it might return the primary or
1870 * a managed profile. For a secondary user, it would be the same as the
1871 * user passed in.
1872 * @hide Used only by Keyguard
1873 */
1874 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1875 if (mService != null) {
1876 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001877 return mService.getProfileWithMinimumFailedPasswordsForWipe(
1878 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001879 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001880 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001881 }
1882 }
1883 return UserHandle.USER_NULL;
1884 }
1885
1886 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001887 * Flag for {@link #resetPassword}: don't allow other admins to change
1888 * the password again until the user has entered it.
1889 */
1890 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001891
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001892 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001893 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1894 * If the flag is set, the device can be booted without asking for user password.
1895 * The absence of this flag does not change the current boot requirements. This flag
1896 * can be set by the device owner only. If the app is not the device owner, the flag
1897 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1898 * device to factory defaults.
1899 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001900 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001901
1902 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001903 * Force a new device unlock password (the password needed to access the
1904 * entire device, not for individual accounts) on the user. This takes
1905 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001906 *
1907 * <p>Calling this from a managed profile that shares the password with the owner profile
1908 * will throw a security exception.
1909 *
1910 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1911 * device admins that are not device owner and not profile owner.
1912 * The password can now only be changed if there is currently no password set. Device owner
1913 * and profile owner can still do this.</em>
1914 *
1915 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001916 * current password quality and length constraints as returned by
1917 * {@link #getPasswordQuality(ComponentName)} and
1918 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1919 * these constraints, then it will be rejected and false returned. Note
1920 * that the password may be a stronger quality (containing alphanumeric
1921 * characters when the requested quality is only numeric), in which case
1922 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001923 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001924 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001925 * pattern or password if the current password constraints allow it. <em>Note: This will not
1926 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1927 * device owner and not profile owner. Once set, the password cannot be changed to null or
1928 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001929 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001930 * <p>The calling device admin must have requested
1931 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1932 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001933 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001934 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001935 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001936 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001937 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001938 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001939 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001940 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001941 if (mParentInstance) {
1942 throw new SecurityException("Reset password does not work across profiles.");
1943 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001944 if (mService != null) {
1945 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001946 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001947 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001948 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001949 }
1950 }
1951 return false;
1952 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001953
Dianne Hackbornd6847842010-01-12 18:14:19 -08001954 /**
1955 * Called by an application that is administering the device to set the
1956 * maximum time for user activity until the device will lock. This limits
1957 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001958 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001959 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08001960 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001961 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001962 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001963 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001964 * @param timeMs The new desired maximum time to lock in milliseconds.
1965 * A value of 0 means there is no restriction.
1966 */
Robin Lee25e26452015-06-02 09:56:29 -07001967 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001968 if (mService != null) {
1969 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001970 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001971 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001972 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001973 }
1974 }
1975 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001976
Dianne Hackbornd6847842010-01-12 18:14:19 -08001977 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001978 * Retrieve the current maximum time to unlock for all admins of this user
1979 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001980 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001981 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07001982 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07001983 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001984 */
Robin Lee25e26452015-06-02 09:56:29 -07001985 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001986 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001987 }
1988
1989 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001990 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001991 if (mService != null) {
1992 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001993 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001994 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001995 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001996 }
1997 }
1998 return 0;
1999 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002000
Dianne Hackbornd6847842010-01-12 18:14:19 -08002001 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002002 * Make the device lock immediately, as if the lock screen timeout has
2003 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002004 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002005 * <p>The calling device admin must have requested
2006 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2007 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002008 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002009 public void lockNow() {
2010 if (mService != null) {
2011 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002012 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002013 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002014 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002015 }
2016 }
2017 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018
Dianne Hackbornd6847842010-01-12 18:14:19 -08002019 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002020 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002021 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002022 */
2023 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2024
2025 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002026 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2027 * data.
2028 *
Paul Crowley2934b262014-12-02 11:21:13 +00002029 * <p>This flag may only be set by device owner admins; if it is set by
2030 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002031 */
2032 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2033
2034 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002035 * Ask the user data be wiped. Wiping the primary user will cause the
2036 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002037 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002038 * <p>The calling device admin must have requested
2039 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2040 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002041 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002042 * @param flags Bit mask of additional options: currently supported flags
2043 * are {@link #WIPE_EXTERNAL_STORAGE} and
2044 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002045 */
2046 public void wipeData(int flags) {
2047 if (mService != null) {
2048 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002049 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002050 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002052 }
2053 }
2054 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002055
Dianne Hackbornd6847842010-01-12 18:14:19 -08002056 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002057 * Called by an application that is administering the device to set the
2058 * global proxy and exclusion list.
2059 * <p>
2060 * The calling device admin must have requested
2061 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2062 * this method; if it has not, a security exception will be thrown.
2063 * Only the first device admin can set the proxy. If a second admin attempts
2064 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002065 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002066 * be returned.
2067 * The method can be called repeatedly by the device admin alrady setting the
2068 * proxy to update the proxy and exclusion list.
2069 *
Robin Lee25e26452015-06-02 09:56:29 -07002070 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002071 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2072 * Pass Proxy.NO_PROXY to reset the proxy.
2073 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002074 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2075 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002076 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002077 */
Robin Lee25e26452015-06-02 09:56:29 -07002078 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002079 List<String> exclusionList ) {
2080 if (proxySpec == null) {
2081 throw new NullPointerException();
2082 }
2083 if (mService != null) {
2084 try {
2085 String hostSpec;
2086 String exclSpec;
2087 if (proxySpec.equals(Proxy.NO_PROXY)) {
2088 hostSpec = null;
2089 exclSpec = null;
2090 } else {
2091 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2092 throw new IllegalArgumentException();
2093 }
2094 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2095 String hostName = sa.getHostName();
2096 int port = sa.getPort();
2097 StringBuilder hostBuilder = new StringBuilder();
2098 hostSpec = hostBuilder.append(hostName)
2099 .append(":").append(Integer.toString(port)).toString();
2100 if (exclusionList == null) {
2101 exclSpec = "";
2102 } else {
2103 StringBuilder listBuilder = new StringBuilder();
2104 boolean firstDomain = true;
2105 for (String exclDomain : exclusionList) {
2106 if (!firstDomain) {
2107 listBuilder = listBuilder.append(",");
2108 } else {
2109 firstDomain = false;
2110 }
2111 listBuilder = listBuilder.append(exclDomain.trim());
2112 }
2113 exclSpec = listBuilder.toString();
2114 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002115 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2116 != android.net.Proxy.PROXY_VALID)
2117 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002118 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002119 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002120 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002121 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002122 }
2123 }
2124 return null;
2125 }
2126
2127 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002128 * Set a network-independent global HTTP proxy. This is not normally what you want
2129 * for typical HTTP proxies - they are generally network dependent. However if you're
2130 * doing something unusual like general internal filtering this may be useful. On
2131 * a private network where the proxy is not accessible, you may break HTTP using this.
2132 *
2133 * <p>This method requires the caller to be the device owner.
2134 *
2135 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2136 * @see ProxyInfo
2137 *
2138 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2139 * with.
2140 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2141 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2142 */
Robin Lee25e26452015-06-02 09:56:29 -07002143 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2144 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002145 if (mService != null) {
2146 try {
2147 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2148 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002149 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002150 }
2151 }
2152 }
2153
2154 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002155 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002156 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2157 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002158 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002159 */
2160 public ComponentName getGlobalProxyAdmin() {
2161 if (mService != null) {
2162 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002163 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002164 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002165 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002166 }
2167 }
2168 return null;
2169 }
2170
2171 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002172 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002173 * indicating that encryption is not supported.
2174 */
2175 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2176
2177 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002178 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002179 * indicating that encryption is supported, but is not currently active.
2180 */
2181 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2182
2183 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002184 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002185 * indicating that encryption is not currently active, but is currently
2186 * being activated. This is only reported by devices that support
2187 * encryption of data and only when the storage is currently
2188 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2189 * to become encrypted will never return this value.
2190 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002191 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002192
2193 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002194 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002195 * indicating that encryption is active.
2196 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002197 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002198
2199 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002200 * Result code for {@link #getStorageEncryptionStatus}:
2201 * indicating that encryption is active, but an encryption key has not
2202 * been set by the user.
2203 */
2204 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2205
2206 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002207 * Activity action: begin the process of encrypting data on the device. This activity should
2208 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2209 * After resuming from this activity, use {@link #getStorageEncryption}
2210 * to check encryption status. However, on some devices this activity may never return, as
2211 * it may trigger a reboot and in some cases a complete data wipe of the device.
2212 */
2213 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2214 public static final String ACTION_START_ENCRYPTION
2215 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002216 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002217 * Widgets are enabled in keyguard
2218 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002219 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002220
2221 /**
Jim Miller50e62182014-04-23 17:25:00 -07002222 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002223 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002224 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2225
2226 /**
2227 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2228 */
2229 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2230
2231 /**
Jim Miller50e62182014-04-23 17:25:00 -07002232 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2233 */
2234 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2235
2236 /**
2237 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2238 */
2239 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2240
2241 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002242 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002243 * (e.g. PIN/Pattern/Password).
2244 */
2245 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2246
2247 /**
Jim Miller06e34502014-07-17 14:46:05 -07002248 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2249 */
2250 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2251
2252 /**
Jim Miller35207742012-11-02 15:33:20 -07002253 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002254 */
2255 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002256
2257 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002258 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002259 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002260 *
2261 * <p>When multiple device administrators attempt to control device
2262 * encryption, the most secure, supported setting will always be
2263 * used. If any device administrator requests device encryption,
2264 * it will be enabled; Conversely, if a device administrator
2265 * attempts to disable device encryption while another
2266 * device administrator has enabled it, the call to disable will
2267 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2268 *
2269 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002270 * written to other storage areas may or may not be encrypted, and this policy does not require
2271 * or control the encryption of any other storage areas.
2272 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2273 * {@code true}, then the directory returned by
2274 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2275 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002276 *
2277 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2278 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2279 * the encryption key may not be fully secured. For maximum security, the administrator should
2280 * also require (and check for) a pattern, PIN, or password.
2281 *
2282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2283 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002284 * @return the new request status (for all active admins) - will be one of
2285 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2286 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2287 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002288 */
Robin Lee25e26452015-06-02 09:56:29 -07002289 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002290 if (mService != null) {
2291 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002292 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002293 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002294 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002295 }
2296 }
2297 return ENCRYPTION_STATUS_UNSUPPORTED;
2298 }
2299
2300 /**
2301 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002302 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002303 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2305 * this will return the requested encryption setting as an aggregate of all active
2306 * administrators.
2307 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002308 */
Robin Lee25e26452015-06-02 09:56:29 -07002309 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002310 if (mService != null) {
2311 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002312 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002313 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002314 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002315 }
2316 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002317 return false;
2318 }
2319
2320 /**
2321 * Called by an application that is administering the device to
2322 * determine the current encryption status of the device.
2323 *
2324 * Depending on the returned status code, the caller may proceed in different
2325 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2326 * storage system does not support encryption. If the
2327 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2328 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002329 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2330 * storage system has enabled encryption but no password is set so further action
2331 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002332 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2333 *
Robin Lee7e678712014-07-24 16:41:31 +01002334 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002335 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002336 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2337 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002338 */
2339 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002340 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002341 }
2342
2343 /** @hide per-user version */
2344 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002345 if (mService != null) {
2346 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002347 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002348 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002349 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002350 }
2351 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002352 return ENCRYPTION_STATUS_UNSUPPORTED;
2353 }
2354
2355 /**
Robin Lee7e678712014-07-24 16:41:31 +01002356 * Installs the given certificate as a user CA.
2357 *
Robin Lee25e26452015-06-02 09:56:29 -07002358 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2359 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002360 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002361 *
2362 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002363 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002364 */
Robin Lee25e26452015-06-02 09:56:29 -07002365 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002366 if (mService != null) {
2367 try {
Robin Lee7e678712014-07-24 16:41:31 +01002368 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002369 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002370 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002371 }
2372 }
2373 return false;
2374 }
2375
2376 /**
Robin Lee7e678712014-07-24 16:41:31 +01002377 * Uninstalls the given certificate from trusted user CAs, if present.
2378 *
Robin Lee25e26452015-06-02 09:56:29 -07002379 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2380 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002381 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002382 */
Robin Lee25e26452015-06-02 09:56:29 -07002383 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002384 if (mService != null) {
2385 try {
Robin Lee306fe082014-06-19 14:04:24 +00002386 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002387 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002388 } catch (CertificateException e) {
2389 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002390 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002391 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002392 }
2393 }
2394 }
2395
2396 /**
Robin Lee7e678712014-07-24 16:41:31 +01002397 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2398 * If a user has installed any certificates by other means than device policy these will be
2399 * included too.
2400 *
Robin Lee25e26452015-06-02 09:56:29 -07002401 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2402 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002403 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002404 */
Robin Lee25e26452015-06-02 09:56:29 -07002405 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002406 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002407 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002408 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002409 mService.enforceCanManageCaCerts(admin);
2410 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2411 for (String alias : certStore.userAliases()) {
2412 try {
2413 certs.add(certStore.getCertificate(alias).getEncoded());
2414 } catch (CertificateException ce) {
2415 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2416 }
2417 }
2418 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002419 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002420 }
2421 }
2422 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002423 }
2424
2425 /**
Robin Lee7e678712014-07-24 16:41:31 +01002426 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2427 * means other than device policy will also be removed, except for system CA certificates.
2428 *
Robin Lee25e26452015-06-02 09:56:29 -07002429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2430 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002431 */
Robin Lee25e26452015-06-02 09:56:29 -07002432 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002433 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002434 try {
2435 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2436 .toArray(new String[0]));
2437 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002438 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002439 }
2440 }
2441 }
2442
2443 /**
2444 * Returns whether this certificate is installed as a trusted CA.
2445 *
Robin Lee25e26452015-06-02 09:56:29 -07002446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2447 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002448 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002449 */
Robin Lee25e26452015-06-02 09:56:29 -07002450 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002451 if (mService != null) {
2452 try {
2453 mService.enforceCanManageCaCerts(admin);
2454 return getCaCertAlias(certBuffer) != null;
2455 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002456 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002457 } catch (CertificateException ce) {
2458 Log.w(TAG, "Could not parse certificate", ce);
2459 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002460 }
2461 return false;
2462 }
2463
2464 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002465 * Called by a device or profile owner to install a certificate and private key pair. The
2466 * keypair will be visible to all apps within the profile.
2467 *
Robin Lee25e26452015-06-02 09:56:29 -07002468 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2469 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002470 * @param privKey The private key to install.
2471 * @param cert The certificate to install.
2472 * @param alias The private key alias under which to install the certificate. If a certificate
2473 * with that alias already exists, it will be overwritten.
2474 * @return {@code true} if the keys were installed, {@code false} otherwise.
2475 */
Robin Leefbc65642015-08-03 16:21:22 +01002476 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2477 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002478 try {
2479 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002480 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2481 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002482 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002483 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002484 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002485 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2486 Log.w(TAG, "Failed to obtain private key material", e);
2487 } catch (CertificateException | IOException e) {
2488 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002489 }
2490 return false;
2491 }
2492
2493 /**
Robin Leefbc65642015-08-03 16:21:22 +01002494 * Called by a device or profile owner to remove all user credentials installed under a given
2495 * alias.
2496 *
2497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2498 * {@code null} if calling from a delegated certificate installer.
2499 * @param alias The private key alias under which the certificate is installed.
2500 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2501 */
2502 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2503 try {
2504 return mService.removeKeyPair(admin, alias);
2505 } catch (RemoteException e) {
2506 Log.w(TAG, "Failed talking with device policy service", e);
2507 }
2508 return false;
2509 }
2510
2511 /**
Robin Lee25e26452015-06-02 09:56:29 -07002512 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002513 * doesn't exist.
2514 */
2515 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2516 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2517 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2518 new ByteArrayInputStream(certBuffer));
2519 return new TrustedCertificateStore().getCertificateAlias(cert);
2520 }
2521
2522 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002523 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002524 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002525 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002526 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002527 * <p>
2528 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2529 * it is later cleared by calling this method with a null value or uninstallling the certificate
2530 * installer.
2531 *
Robin Lee25e26452015-06-02 09:56:29 -07002532 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002533 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002534 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002535 */
Robin Lee25e26452015-06-02 09:56:29 -07002536 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2537 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002538 if (mService != null) {
2539 try {
Robin Lee25e26452015-06-02 09:56:29 -07002540 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002541 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002542 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002543 }
2544 }
2545 }
2546
2547 /**
2548 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002549 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002550 *
Robin Lee25e26452015-06-02 09:56:29 -07002551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2552 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002553 * if none is set.
2554 */
Robin Lee25e26452015-06-02 09:56:29 -07002555 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002556 if (mService != null) {
2557 try {
Robin Lee25e26452015-06-02 09:56:29 -07002558 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002559 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002560 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002561 }
2562 }
2563 return null;
2564 }
2565
2566 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002567 * Called by a device or profile owner to configure an always-on VPN connection through a
2568 * specific application for the current user.
2569 * This connection is automatically granted and persisted after a reboot.
2570 *
2571 * <p>The designated package should declare a {@link android.net.VpnService} in its
2572 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2573 * otherwise the call will fail.
2574 *
2575 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2576 * to remove an existing always-on VPN configuration.
2577 *
2578 * @return {@code true} if the package is set as always-on VPN controller;
2579 * {@code false} otherwise.
2580 */
2581 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2582 @Nullable String vpnPackage) {
2583 if (mService != null) {
2584 try {
2585 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2586 } catch (RemoteException e) {
2587 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2588 }
2589 }
2590 return false;
2591 }
2592
2593 /**
2594 * Called by a device or profile owner to read the name of the package administering an
2595 * always-on VPN connection for the current user.
2596 * If there is no such package, or the always-on VPN is provided by the system instead
2597 * of by an application, {@code null} will be returned.
2598 *
2599 * @return Package name of VPN controller responsible for always-on VPN,
2600 * or {@code null} if none is set.
2601 */
2602 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2603 if (mService != null) {
2604 try {
2605 return mService.getAlwaysOnVpnPackage(admin);
2606 } catch (RemoteException e) {
2607 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2608 }
2609 }
2610 return null;
2611 }
2612
2613 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002614 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002615 * on the device, for this user. After setting this, no applications running as this user
2616 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002617 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002618 * <p>If the caller is device owner, then the restriction will be applied to all users.
2619 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002620 * <p>The calling device admin must have requested
2621 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2622 * this method; if it has not, a security exception will be thrown.
2623 *
2624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2625 * @param disabled Whether or not the camera should be disabled.
2626 */
Robin Lee25e26452015-06-02 09:56:29 -07002627 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002628 if (mService != null) {
2629 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002630 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002631 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002632 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002633 }
2634 }
2635 }
2636
2637 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002638 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002639 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002640 * @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 -07002641 * have disabled the camera
2642 */
Robin Lee25e26452015-06-02 09:56:29 -07002643 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002644 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002645 }
2646
2647 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002648 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002649 if (mService != null) {
2650 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002651 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002652 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002653 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002654 }
2655 }
2656 return false;
2657 }
2658
2659 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002660 * Called by a device owner to request a bugreport.
2661 *
2662 * <p>There must be only one user on the device, managed by the device owner.
2663 * Otherwise a security exception will be thrown.
2664 *
2665 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2666 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2667 * if it wasn't triggered because a previous bugreport operation is still active
2668 * (either the bugreport is still running or waiting for the user to share or decline)
2669 */
2670 public boolean requestBugreport(@NonNull ComponentName admin) {
2671 if (mService != null) {
2672 try {
2673 return mService.requestBugreport(admin);
2674 } catch (RemoteException e) {
2675 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2676 }
2677 }
2678 return false;
2679 }
2680
2681 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002682 * Determine whether or not creating a guest user has been disabled for the device
2683 *
2684 * @hide
2685 */
2686 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2687 // Currently guest users can always be created if multi-user is enabled
2688 // TODO introduce a policy for guest user creation
2689 return false;
2690 }
2691
2692 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002693 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2694 * screen capture also prevents the content from being shown on display devices that do not have
2695 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2696 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002697 *
2698 * <p>The calling device admin must be a device or profile owner. If it is not, a
2699 * security exception will be thrown.
2700 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002701 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002702 * blocks assist requests for all activities of the relevant user.
2703 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002704 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002705 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002706 */
Robin Lee25e26452015-06-02 09:56:29 -07002707 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002708 if (mService != null) {
2709 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002710 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002711 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002712 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002713 }
2714 }
2715 }
2716
2717 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002718 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002719 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002720 * @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 +01002721 * have disabled screen capture.
2722 */
Robin Lee25e26452015-06-02 09:56:29 -07002723 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002724 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002725 }
2726
2727 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002728 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002729 if (mService != null) {
2730 try {
2731 return mService.getScreenCaptureDisabled(admin, userHandle);
2732 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002733 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002734 }
2735 }
2736 return false;
2737 }
2738
2739 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002740 * Called by a device owner to set whether auto time is required. If auto time is
2741 * required the user cannot set the date and time, but has to use network date and time.
2742 *
2743 * <p>Note: if auto time is required the user can still manually set the time zone.
2744 *
2745 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2746 * be thrown.
2747 *
2748 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2749 * @param required Whether auto time is set required or not.
2750 */
Robin Lee25e26452015-06-02 09:56:29 -07002751 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002752 if (mService != null) {
2753 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002754 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002755 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002756 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002757 }
2758 }
2759 }
2760
2761 /**
2762 * @return true if auto time is required.
2763 */
2764 public boolean getAutoTimeRequired() {
2765 if (mService != null) {
2766 try {
2767 return mService.getAutoTimeRequired();
2768 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002769 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002770 }
2771 }
2772 return false;
2773 }
2774
2775 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01002776 * Called by a device owner to set whether all users created on the device should be ephemeral.
2777 *
2778 * <p>The system user is exempt from this policy - it is never ephemeral.
2779 *
2780 * <p>The calling device admin must be the device owner. If it is not, a security exception will
2781 * be thrown.
2782 *
2783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2784 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
2785 * subsequently created users will be ephemeral.
2786 * @hide
2787 */
2788 public void setForceEphemeralUsers(
2789 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
2790 if (mService != null) {
2791 try {
2792 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
2793 } catch (RemoteException e) {
2794 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2795 }
2796 }
2797 }
2798
2799 /**
2800 * @return true if all users are created ephemeral.
2801 * @hide
2802 */
2803 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
2804 if (mService != null) {
2805 try {
2806 return mService.getForceEphemeralUsers(admin);
2807 } catch (RemoteException e) {
2808 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2809 }
2810 }
2811 return false;
2812 }
2813
2814 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002815 * Called by an application that is administering the device to disable keyguard customizations,
2816 * such as widgets. After setting this, keyguard features will be disabled according to the
2817 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002818 *
2819 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002820 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002821 * this method; if it has not, a security exception will be thrown.
2822 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002823 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002824 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002825 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002826 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002827 * <ul>
2828 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2829 * these will affect the profile's parent user.
2830 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2831 * generated by applications in the managed profile.
2832 * </ul>
2833 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2834 * can check which features have been disabled by calling
2835 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002836 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002838 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2839 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002840 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002841 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2842 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002843 */
Robin Lee25e26452015-06-02 09:56:29 -07002844 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002845 if (mService != null) {
2846 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002847 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002848 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002849 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002850 }
2851 }
2852 }
2853
2854 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002855 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002856 * admin, if specified, or all admins.
Esteban Talavera62399912016-01-11 15:37:55 +00002857 * @param admin The name of the admin component to check, or {@code null} to check whether any
2858 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002859 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2860 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002861 */
Robin Lee25e26452015-06-02 09:56:29 -07002862 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002863 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002864 }
2865
2866 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002867 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002868 if (mService != null) {
2869 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002870 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002871 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002872 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002873 }
2874 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002875 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002876 }
2877
2878 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002879 * @hide
2880 */
Robin Lee25e26452015-06-02 09:56:29 -07002881 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2882 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002883 if (mService != null) {
2884 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002885 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002886 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002887 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002888 }
2889 }
2890 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002891
Dianne Hackbornd6847842010-01-12 18:14:19 -08002892 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002893 * @hide
2894 */
Robin Lee25e26452015-06-02 09:56:29 -07002895 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002896 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002897 }
2898
2899 /**
Robin Lee25e26452015-06-02 09:56:29 -07002900 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002901 * @hide
2902 */
Robin Lee25e26452015-06-02 09:56:29 -07002903 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002904 ActivityInfo ai;
2905 try {
2906 ai = mContext.getPackageManager().getReceiverInfo(cn,
2907 PackageManager.GET_META_DATA);
2908 } catch (PackageManager.NameNotFoundException e) {
2909 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2910 return null;
2911 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002912
Dianne Hackbornd6847842010-01-12 18:14:19 -08002913 ResolveInfo ri = new ResolveInfo();
2914 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002915
Dianne Hackbornd6847842010-01-12 18:14:19 -08002916 try {
2917 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002918 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002919 Log.w(TAG, "Unable to parse device policy " + cn, e);
2920 return null;
2921 }
2922 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002923
Dianne Hackbornd6847842010-01-12 18:14:19 -08002924 /**
2925 * @hide
2926 */
Robin Lee25e26452015-06-02 09:56:29 -07002927 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002928 if (mService != null) {
2929 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002930 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002931 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002932 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002933 }
2934 }
2935 }
2936
2937 /**
2938 * @hide
2939 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002940 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002941 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002942 if (mService != null) {
2943 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002944 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002945 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002946 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002947 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002948 }
2949 }
2950 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002951
Dianne Hackbornd6847842010-01-12 18:14:19 -08002952 /**
2953 * @hide
2954 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002955 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002956 if (mService != null) {
2957 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002958 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002959 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002960 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002961 }
2962 }
2963 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002964
Dianne Hackbornd6847842010-01-12 18:14:19 -08002965 /**
2966 * @hide
2967 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002968 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002969 if (mService != null) {
2970 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002971 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002972 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002973 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002974 }
2975 }
2976 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07002977
2978 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00002979 * Should be called when keyguard has been dismissed.
2980 * @hide
2981 */
2982 public void reportKeyguardDismissed() {
2983 if (mService != null) {
2984 try {
2985 mService.reportKeyguardDismissed();
2986 } catch (RemoteException e) {
2987 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2988 }
2989 }
2990 }
2991
2992 /**
2993 * Should be called when keyguard view has been shown to the user.
2994 * @hide
2995 */
2996 public void reportKeyguardSecured() {
2997 if (mService != null) {
2998 try {
2999 mService.reportKeyguardSecured();
3000 } catch (RemoteException e) {
3001 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3002 }
3003 }
3004 }
3005
3006 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003007 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003008 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003009 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3010 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003011 * @return whether the package was successfully registered as the device owner.
3012 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003013 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003014 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003015 public boolean setDeviceOwner(ComponentName who) {
3016 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003017 }
3018
3019 /**
3020 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003021 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003022 public boolean setDeviceOwner(ComponentName who, int userId) {
3023 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003024 }
3025
3026 /**
3027 * @hide
3028 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003029 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3030 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003031 }
3032
3033 /**
3034 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003035 * Sets the given package as the device owner. The package must already be installed. There
3036 * must not already be a device owner.
3037 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3038 * this method.
3039 * Calling this after the setup phase of the primary user has completed is allowed only if
3040 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003041 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003042 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003043 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003044 * @return whether the package was successfully registered as the device owner.
3045 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003046 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003047 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003048 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003049 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003050 if (mService != null) {
3051 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003052 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003053 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003054 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003055 }
3056 }
3057 return false;
3058 }
3059
3060 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003061 * Used to determine if a particular package has been registered as a Device Owner app.
3062 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003063 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003064 * package is currently registered as the device owner app, pass in the package name from
3065 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003066 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003067 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3068 * the setup process.
3069 * @param packageName the package name of the app, to compare with the registered device owner
3070 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003071 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003072 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003073 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003074 return isDeviceOwnerAppOnCallingUser(packageName);
3075 }
3076
3077 /**
3078 * @return true if a package is registered as device owner, only when it's running on the
3079 * calling user.
3080 *
3081 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3082 * @hide
3083 */
3084 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3085 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3086 }
3087
3088 /**
3089 * @return true if a package is registered as device owner, even if it's running on a different
3090 * user.
3091 *
3092 * <p>Requires the MANAGE_USERS permission.
3093 *
3094 * @hide
3095 */
3096 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3097 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3098 }
3099
3100 /**
3101 * @return device owner component name, only when it's running on the calling user.
3102 *
3103 * @hide
3104 */
3105 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3106 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3107 }
3108
3109 /**
3110 * @return device owner component name, even if it's running on a different user.
3111 *
3112 * <p>Requires the MANAGE_USERS permission.
3113 *
3114 * @hide
3115 */
3116 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3117 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3118 }
3119
3120 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003121 if (packageName == null) {
3122 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003123 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003124 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003125 if (deviceOwner == null) {
3126 return false;
3127 }
3128 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003129 }
3130
Makoto Onukic8a5a552015-11-19 14:29:12 -08003131 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3132 if (mService != null) {
3133 try {
3134 return mService.getDeviceOwnerComponent(callingUserOnly);
3135 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003136 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003137 }
3138 }
3139 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003140 }
3141
Jason Monkb0dced82014-06-06 14:36:20 -04003142 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003143 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3144 * no device owner.
3145 *
3146 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003147 *
3148 * @hide
3149 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003150 public int getDeviceOwnerUserId() {
3151 if (mService != null) {
3152 try {
3153 return mService.getDeviceOwnerUserId();
3154 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003155 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003156 }
3157 }
3158 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003159 }
3160
3161 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003162 * Clears the current device owner. The caller must be the device owner.
3163 *
3164 * This function should be used cautiously as once it is called it cannot
3165 * be undone. The device owner can only be set as a part of device setup
3166 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003167 *
3168 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003169 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003170 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003171 if (mService != null) {
3172 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003173 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003174 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003175 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003176 }
3177 }
3178 }
3179
Makoto Onukia52562c2015-10-01 16:12:31 -07003180 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003181 * Returns the device owner package name, only if it's running on the calling user.
3182 *
3183 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003184 *
3185 * @hide
3186 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003187 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003188 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003189 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3190 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003191 }
3192
3193 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003194 * @return true if the device is managed by any device owner.
3195 *
3196 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003197 *
3198 * @hide
3199 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003200 public boolean isDeviceManaged() {
3201 return getDeviceOwnerComponentOnAnyUser() != null;
3202 }
3203
3204 /**
3205 * Returns the device owner name. Note this method *will* return the device owner
3206 * name when it's running on a different user.
3207 *
3208 * <p>Requires the MANAGE_USERS permission.
3209 *
3210 * @hide
3211 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003212 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003213 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003214 if (mService != null) {
3215 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003216 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003217 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003218 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003219 }
3220 }
3221 return null;
3222 }
Adam Connors776c5552014-01-09 10:42:56 +00003223
3224 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003225 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003226 * @deprecated Do not use
3227 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003228 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003229 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003230 @SystemApi
3231 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003232 return null;
3233 }
3234
3235 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003236 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003237 * @deprecated Do not use
3238 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003239 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003240 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003241 @SystemApi
3242 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003243 return null;
3244 }
3245
Julia Reynolds20118f12015-02-11 12:34:08 -05003246 /**
Adam Connors776c5552014-01-09 10:42:56 +00003247 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003248 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303249 * Sets the given component as an active admin and registers the package as the profile
3250 * owner for this user. The package must already be installed and there shouldn't be
3251 * an existing profile owner registered for this user. Also, this method must be called
3252 * before the user setup has been completed.
3253 * <p>
3254 * This method can only be called by system apps that hold MANAGE_USERS permission and
3255 * MANAGE_DEVICE_ADMINS permission.
3256 * @param admin The component to register as an active admin and profile owner.
3257 * @param ownerName The user-visible name of the entity that is managing this user.
3258 * @return whether the admin was successfully registered as the profile owner.
3259 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3260 * the user has already been set up.
3261 */
Justin Morey80440cc2014-07-24 09:16:35 -05003262 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003263 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303264 throws IllegalArgumentException {
3265 if (mService != null) {
3266 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003267 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303268 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003269 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303270 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303271 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3272 }
3273 }
3274 return false;
3275 }
3276
3277 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003278 * Clears the active profile owner and removes all user restrictions. The caller must
3279 * be from the same package as the active profile owner for this user, otherwise a
3280 * SecurityException will be thrown.
3281 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003282 * <p>This doesn't work for managed profile owners.
3283 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003284 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003285 */
Robin Lee25e26452015-06-02 09:56:29 -07003286 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003287 if (mService != null) {
3288 try {
3289 mService.clearProfileOwner(admin);
3290 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003291 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003292 }
3293 }
3294 }
3295
3296 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003297 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003298 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003299 */
3300 public boolean hasUserSetupCompleted() {
3301 if (mService != null) {
3302 try {
3303 return mService.hasUserSetupCompleted();
3304 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003305 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003306 }
3307 }
3308 return true;
3309 }
3310
3311 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003312 * @hide
3313 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003314 * already be installed. There must not already be a profile owner for this user.
3315 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3316 * this method.
3317 * Calling this after the setup phase of the specified user has completed is allowed only if:
3318 * - the caller is SYSTEM_UID.
3319 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003320 * @param admin the component name to be registered as profile owner.
3321 * @param ownerName the human readable name of the organisation associated with this DPM.
3322 * @param userHandle the userId to set the profile owner for.
3323 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003324 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3325 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003326 */
Robin Lee25e26452015-06-02 09:56:29 -07003327 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003328 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003329 if (mService != null) {
3330 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003331 if (ownerName == null) {
3332 ownerName = "";
3333 }
3334 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003335 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003336 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003337 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3338 }
3339 }
3340 return false;
3341 }
3342
3343 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003344 * Sets the device owner information to be shown on the lock screen.
3345 *
3346 * <p>If the device owner information is {@code null} or empty then the device owner info is
3347 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003348 * <p>If the device owner information contains only whitespaces then the message on the lock
3349 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003350 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003351 * <p>If the device owner information needs to be localized, it is the responsibility of the
3352 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3353 * and set a new version of this string accordingly.
3354 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003355 * @param admin The name of the admin component to check.
3356 * @param info Device owner information which will be displayed instead of the user
3357 * owner info.
3358 * @return Whether the device owner information has been set.
3359 */
3360 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3361 if (mService != null) {
3362 try {
3363 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3364 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003365 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003366 }
3367 }
3368 return false;
3369 }
3370
3371 /**
3372 * @return The device owner information. If it is not set returns {@code null}.
3373 */
3374 public String getDeviceOwnerLockScreenInfo() {
3375 if (mService != null) {
3376 try {
3377 return mService.getDeviceOwnerLockScreenInfo();
3378 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003379 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003380 }
3381 }
3382 return null;
3383 }
3384
3385 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003386 * Called by device or profile owners for setting the package suspended for this user.
3387 * A suspended package will not be started by the package manager, its notifications will
3388 * be hidden and it will not show up in recents. The package must already be installed.
3389 *
3390 * @param admin The name of the admin component to check.
3391 * @param packageName The package name of the app to suspend or unsuspend.
3392 * @param suspended If set to {@code true} than the package will be suspended, if set to
3393 * {@code false} the package will be unsuspended.
3394 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3395 * otherwise.
3396 */
3397 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3398 boolean suspended) {
3399 if (mService != null) {
3400 try {
3401 return mService.setPackageSuspended(admin, packageName, suspended);
3402 } catch (RemoteException re) {
3403 Log.w(TAG, "Failed talking with device policy service", re);
3404 }
3405 }
3406 return false;
3407 }
3408
3409 /**
3410 * Called by device or profile owners to determine if a package is suspended.
3411 *
3412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3413 * @param packageName The name of the package to retrieve the suspended status of.
3414 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3415 */
3416 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3417 if (mService != null) {
3418 try {
3419 return mService.getPackageSuspended(admin, packageName);
3420 } catch (RemoteException e) {
3421 Log.w(TAG, "Failed talking with device policy service", e);
3422 }
3423 }
3424 return false;
3425 }
3426
3427 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003428 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3429 * be used. Only the profile owner can call this.
3430 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003431 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003432 *
3433 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3434 */
Robin Lee25e26452015-06-02 09:56:29 -07003435 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003436 if (mService != null) {
3437 try {
3438 mService.setProfileEnabled(admin);
3439 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003440 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003441 }
3442 }
3443 }
3444
3445 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003446 * Sets the name of the profile. In the device owner case it sets the name of the user
3447 * 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 +01003448 * never called by the profile or device owner, the name will be set to default values.
3449 *
3450 * @see #isProfileOwnerApp
3451 * @see #isDeviceOwnerApp
3452 *
Robin Lee25e26452015-06-02 09:56:29 -07003453 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003454 * @param profileName The name of the profile.
3455 */
Robin Lee25e26452015-06-02 09:56:29 -07003456 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003457 if (mService != null) {
3458 try {
Robin Lee25e26452015-06-02 09:56:29 -07003459 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003460 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003461 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003462 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003463 }
3464 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003465
3466 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003467 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003468 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003469 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003470 *
3471 * @param packageName The package name of the app to compare with the registered profile owner.
3472 * @return Whether or not the package is registered as the profile owner.
3473 */
3474 public boolean isProfileOwnerApp(String packageName) {
3475 if (mService != null) {
3476 try {
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003477 ComponentName profileOwner = mService.getProfileOwner(
3478 Process.myUserHandle().getIdentifier());
3479 return profileOwner != null
3480 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003481 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003482 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003483 }
3484 }
3485 return false;
3486 }
3487
3488 /**
3489 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003490 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003491 * owner has been set for that user.
3492 * @throws IllegalArgumentException if the userId is invalid.
3493 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003494 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003495 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003496 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3497 }
3498
3499 /**
3500 * @see #getProfileOwner()
3501 * @hide
3502 */
3503 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003504 if (mService != null) {
3505 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003506 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003507 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003508 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003509 throw new IllegalArgumentException(
3510 "Requested profile owner for invalid userId", re);
3511 }
3512 }
3513 return null;
3514 }
3515
3516 /**
3517 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003518 * @return the human readable name of the organisation associated with this DPM or {@code null}
3519 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003520 * @throws IllegalArgumentException if the userId is invalid.
3521 */
3522 public String getProfileOwnerName() throws IllegalArgumentException {
3523 if (mService != null) {
3524 try {
3525 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3526 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003527 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003528 throw new IllegalArgumentException(
3529 "Requested profile owner for invalid userId", re);
3530 }
3531 }
3532 return null;
3533 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003534
3535 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003536 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003537 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003538 * @return the human readable name of the organisation associated with this profile owner or
3539 * null if one is not set.
3540 * @throws IllegalArgumentException if the userId is invalid.
3541 */
3542 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003543 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003544 if (mService != null) {
3545 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003546 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003547 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003548 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003549 throw new IllegalArgumentException(
3550 "Requested profile owner for invalid userId", re);
3551 }
3552 }
3553 return null;
3554 }
3555
3556 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003557 * Called by a profile owner or device owner to add a default intent handler activity for
3558 * intents that match a certain intent filter. This activity will remain the default intent
3559 * handler even if the set of potential event handlers for the intent filter changes and if
3560 * the intent preferences are reset.
3561 *
3562 * <p>The default disambiguation mechanism takes over if the activity is not installed
3563 * (anymore). When the activity is (re)installed, it is automatically reset as default
3564 * intent handler for the filter.
3565 *
3566 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3567 * security exception will be thrown.
3568 *
3569 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3570 * @param filter The IntentFilter for which a default handler is added.
3571 * @param activity The Activity that is added as default intent handler.
3572 */
Robin Lee25e26452015-06-02 09:56:29 -07003573 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3574 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003575 if (mService != null) {
3576 try {
3577 mService.addPersistentPreferredActivity(admin, filter, activity);
3578 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003579 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003580 }
3581 }
3582 }
3583
3584 /**
3585 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003586 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003587 *
3588 * <p>The calling device admin must be a profile owner. If it is not, a security
3589 * exception will be thrown.
3590 *
3591 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3592 * @param packageName The name of the package for which preferences are removed.
3593 */
Robin Lee25e26452015-06-02 09:56:29 -07003594 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003595 String packageName) {
3596 if (mService != null) {
3597 try {
3598 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3599 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003600 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003601 }
3602 }
3603 }
Robin Lee66e5d962014-04-09 16:44:21 +01003604
3605 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003606 * Called by a profile owner or device owner to grant permission to a package to manage
3607 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3608 * {@link #getApplicationRestrictions}.
3609 * <p>
3610 * This permission is persistent until it is later cleared by calling this method with a
3611 * {@code null} value or uninstalling the managing package.
3612 *
3613 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3614 * @param packageName The package name which will be given access to application restrictions
3615 * APIs. If {@code null} is given the current package will be cleared.
3616 */
3617 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3618 @Nullable String packageName) {
3619 if (mService != null) {
3620 try {
3621 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3622 } catch (RemoteException e) {
3623 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3624 }
3625 }
3626 }
3627
3628 /**
3629 * Called by a profile owner or device owner to retrieve the application restrictions managing
3630 * package for the current user, or {@code null} if none is set.
3631 *
3632 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3633 * @return The package name allowed to manage application restrictions on the current user, or
3634 * {@code null} if none is set.
3635 */
3636 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3637 if (mService != null) {
3638 try {
3639 return mService.getApplicationRestrictionsManagingPackage(admin);
3640 } catch (RemoteException e) {
3641 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3642 }
3643 }
3644 return null;
3645 }
3646
3647 /**
3648 * Returns {@code true} if the calling package has been granted permission via
3649 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3650 * restrictions for the calling user.
3651 */
3652 public boolean isCallerApplicationRestrictionsManagingPackage() {
3653 if (mService != null) {
3654 try {
3655 return mService.isCallerApplicationRestrictionsManagingPackage();
3656 } catch (RemoteException e) {
3657 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3658 }
3659 }
3660 return false;
3661 }
3662
3663 /**
3664 * Sets the application restrictions for a given target application running in the calling user.
3665 *
3666 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3667 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3668 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003669 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003670 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3671 * <ul>
3672 * <li>{@code boolean}
3673 * <li>{@code int}
3674 * <li>{@code String} or {@code String[]}
3675 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3676 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003677 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003678 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003679 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003680 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3681 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003682 * <p>The application restrictions are only made visible to the target application via
3683 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3684 * device owner, and the application restrictions managing package via
3685 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003686 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3688 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003689 * @param packageName The name of the package to update restricted settings for.
3690 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3691 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003692 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003693 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003694 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003695 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003696 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003697 Bundle settings) {
3698 if (mService != null) {
3699 try {
3700 mService.setApplicationRestrictions(admin, packageName, settings);
3701 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003702 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003703 }
3704 }
3705 }
3706
3707 /**
Jim Millere303bf42014-08-26 17:12:29 -07003708 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3709 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3710 * trust agents but those enabled by this function call. If flag
3711 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003712 *
3713 * <p>The calling device admin must have requested
3714 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003715 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003716 *
3717 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003718 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003719 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003720 * will be strictly disabled according to the state of the
3721 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3722 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3723 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3724 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003725 */
Robin Lee25e26452015-06-02 09:56:29 -07003726 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3727 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003728 if (mService != null) {
3729 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003730 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003731 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003732 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003733 }
3734 }
3735 }
3736
3737 /**
Jim Millere303bf42014-08-26 17:12:29 -07003738 * Gets configuration for the given trust agent based on aggregating all calls to
3739 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3740 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003741 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3743 * this function returns a list of configurations for all admins that declare
3744 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3745 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3746 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3747 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003748 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003749 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003750 */
Robin Lee25e26452015-06-02 09:56:29 -07003751 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3752 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003753 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003754 }
3755
3756 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003757 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3758 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003759 if (mService != null) {
3760 try {
Jim Millere303bf42014-08-26 17:12:29 -07003761 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003762 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003763 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003764 }
3765 }
Jim Millere303bf42014-08-26 17:12:29 -07003766 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003767 }
3768
3769 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003770 * Called by a profile owner of a managed profile to set whether caller-Id information from
3771 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003772 *
3773 * <p>The calling device admin must be a profile owner. If it is not, a
3774 * security exception will be thrown.
3775 *
Robin Lee25e26452015-06-02 09:56:29 -07003776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003777 * @param disabled If true caller-Id information in the managed profile is not displayed.
3778 */
Robin Lee25e26452015-06-02 09:56:29 -07003779 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003780 if (mService != null) {
3781 try {
Robin Lee25e26452015-06-02 09:56:29 -07003782 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003783 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003784 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003785 }
3786 }
3787 }
3788
3789 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003790 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3791 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003792 *
3793 * <p>The calling device admin must be a profile owner. If it is not, a
3794 * security exception will be thrown.
3795 *
Robin Lee25e26452015-06-02 09:56:29 -07003796 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003797 */
Robin Lee25e26452015-06-02 09:56:29 -07003798 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003799 if (mService != null) {
3800 try {
Robin Lee25e26452015-06-02 09:56:29 -07003801 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003802 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003803 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003804 }
3805 }
3806 return false;
3807 }
3808
3809 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003810 * Determine whether or not caller-Id information has been disabled.
3811 *
3812 * @param userHandle The user for whom to check the caller-id permission
3813 * @hide
3814 */
3815 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3816 if (mService != null) {
3817 try {
3818 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3819 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003820 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003821 }
3822 }
3823 return false;
3824 }
3825
3826 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003827 * Called by a profile owner of a managed profile to set whether contacts search from
3828 * the managed profile will be shown in the parent profile, for incoming calls.
3829 *
3830 * <p>The calling device admin must be a profile owner. If it is not, a
3831 * security exception will be thrown.
3832 *
3833 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3834 * @param disabled If true contacts search in the managed profile is not displayed.
3835 */
3836 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3837 boolean disabled) {
3838 if (mService != null) {
3839 try {
3840 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3841 } catch (RemoteException e) {
3842 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3843 }
3844 }
3845 }
3846
3847 /**
3848 * Called by a profile owner of a managed profile to determine whether or not contacts search
3849 * has been disabled.
3850 *
3851 * <p>The calling device admin must be a profile owner. If it is not, a
3852 * security exception will be thrown.
3853 *
3854 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3855 */
3856 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3857 if (mService != null) {
3858 try {
3859 return mService.getCrossProfileContactsSearchDisabled(admin);
3860 } catch (RemoteException e) {
3861 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3862 }
3863 }
3864 return false;
3865 }
3866
3867
3868 /**
3869 * Determine whether or not contacts search has been disabled.
3870 *
3871 * @param userHandle The user for whom to check the contacts search permission
3872 * @hide
3873 */
3874 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3875 if (mService != null) {
3876 try {
3877 return mService
3878 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3879 } catch (RemoteException e) {
3880 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3881 }
3882 }
3883 return false;
3884 }
3885
3886 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003887 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00003888 *
Makoto Onuki1040da12015-03-19 11:24:00 -07003889 * @hide
3890 */
3891 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00003892 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003893 if (mService != null) {
3894 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00003895 mService.startManagedQuickContact(actualLookupKey, actualContactId,
3896 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003897 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003898 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003899 }
3900 }
3901 }
3902
3903 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003904 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003905 * @hide
3906 */
3907 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3908 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00003909 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00003910 originalIntent);
3911 }
3912
3913 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003914 * Called by a profile owner of a managed profile to set whether bluetooth
3915 * devices can access enterprise contacts.
3916 * <p>
3917 * The calling device admin must be a profile owner. If it is not, a
3918 * security exception will be thrown.
3919 * <p>
3920 * This API works on managed profile only.
3921 *
Robin Lee25e26452015-06-02 09:56:29 -07003922 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003923 * with.
3924 * @param disabled If true, bluetooth devices cannot access enterprise
3925 * contacts.
3926 */
Robin Lee25e26452015-06-02 09:56:29 -07003927 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003928 if (mService != null) {
3929 try {
Robin Lee25e26452015-06-02 09:56:29 -07003930 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003931 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003932 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003933 }
3934 }
3935 }
3936
3937 /**
3938 * Called by a profile owner of a managed profile to determine whether or
3939 * not Bluetooth devices cannot access enterprise contacts.
3940 * <p>
3941 * The calling device admin must be a profile owner. If it is not, a
3942 * security exception will be thrown.
3943 * <p>
3944 * This API works on managed profile only.
3945 *
Robin Lee25e26452015-06-02 09:56:29 -07003946 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003947 * with.
3948 */
Robin Lee25e26452015-06-02 09:56:29 -07003949 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003950 if (mService != null) {
3951 try {
Robin Lee25e26452015-06-02 09:56:29 -07003952 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003953 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003954 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003955 }
3956 }
3957 return true;
3958 }
3959
3960 /**
3961 * Determine whether or not Bluetooth devices cannot access contacts.
3962 * <p>
3963 * This API works on managed profile UserHandle only.
3964 *
3965 * @param userHandle The user for whom to check the caller-id permission
3966 * @hide
3967 */
3968 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
3969 if (mService != null) {
3970 try {
3971 return mService.getBluetoothContactSharingDisabledForUser(userHandle
3972 .getIdentifier());
3973 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003974 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003975 }
3976 }
3977 return true;
3978 }
3979
3980 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003981 * Called by the profile owner of a managed profile so that some intents sent in the managed
3982 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00003983 * Only activity intents are supported.
3984 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003985 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01003986 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
3987 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01003988 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
3989 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003990 */
Robin Lee25e26452015-06-02 09:56:29 -07003991 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003992 if (mService != null) {
3993 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01003994 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003995 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003996 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00003997 }
3998 }
3999 }
4000
4001 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004002 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4003 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004004 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4006 */
Robin Lee25e26452015-06-02 09:56:29 -07004007 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004008 if (mService != null) {
4009 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004010 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004011 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004012 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004013 }
4014 }
4015 }
4016
4017 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004018 * Called by a profile or device owner to set the permitted accessibility services. When
4019 * set by a device owner or profile owner the restriction applies to all profiles of the
4020 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004021 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004022 * By default the user can use any accessiblity service. When zero or more packages have
4023 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004024 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004025 *
4026 * <p> Calling with a null value for the list disables the restriction so that all services
4027 * can be used, calling with an empty list only allows the builtin system's services.
4028 *
4029 * <p> System accesibility services are always available to the user the list can't modify
4030 * this.
4031 *
4032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4033 * @param packageNames List of accessibility service package names.
4034 *
4035 * @return true if setting the restriction succeeded. It fail if there is
4036 * one or more non-system accessibility services enabled, that are not in the list.
4037 */
Robin Lee25e26452015-06-02 09:56:29 -07004038 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004039 List<String> packageNames) {
4040 if (mService != null) {
4041 try {
4042 return mService.setPermittedAccessibilityServices(admin, packageNames);
4043 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004044 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004045 }
4046 }
4047 return false;
4048 }
4049
4050 /**
4051 * Returns the list of permitted accessibility services set by this device or profile owner.
4052 *
4053 * <p>An empty list means no accessibility services except system services are allowed.
4054 * Null means all accessibility services are allowed.
4055 *
4056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4057 * @return List of accessiblity service package names.
4058 */
Robin Lee25e26452015-06-02 09:56:29 -07004059 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004060 if (mService != null) {
4061 try {
4062 return mService.getPermittedAccessibilityServices(admin);
4063 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004064 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004065 }
4066 }
4067 return null;
4068 }
4069
4070 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004071 * Called by the system to check if a specific accessibility service is disabled by admin.
4072 *
4073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4074 * @param packageName Accessibility service package name that needs to be checked.
4075 * @param userHandle user id the admin is running as.
4076 * @return true if the accessibility service is permitted, otherwise false.
4077 *
4078 * @hide
4079 */
4080 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4081 @NonNull String packageName, int userHandle) {
4082 if (mService != null) {
4083 try {
4084 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4085 userHandle);
4086 } catch (RemoteException e) {
4087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4088 }
4089 }
4090 return false;
4091 }
4092
4093 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004094 * Returns the list of accessibility services permitted by the device or profiles
4095 * owners of this user.
4096 *
4097 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4098 * it will contain the intersection of the permitted lists for any device or profile
4099 * owners that apply to this user. It will also include any system accessibility services.
4100 *
4101 * @param userId which user to check for.
4102 * @return List of accessiblity service package names.
4103 * @hide
4104 */
4105 @SystemApi
4106 public List<String> getPermittedAccessibilityServices(int userId) {
4107 if (mService != null) {
4108 try {
4109 return mService.getPermittedAccessibilityServicesForUser(userId);
4110 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004111 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004112 }
4113 }
4114 return null;
4115 }
4116
4117 /**
4118 * Called by a profile or device owner to set the permitted input methods services. When
4119 * set by a device owner or profile owner the restriction applies to all profiles of the
4120 * user the device owner or profile owner is an admin for.
4121 *
4122 * By default the user can use any input method. When zero or more packages have
4123 * been added, input method that are not in the list and not part of the system
4124 * can not be enabled by the user.
4125 *
4126 * This method will fail if it is called for a admin that is not for the foreground user
4127 * or a profile of the foreground user.
4128 *
4129 * <p> Calling with a null value for the list disables the restriction so that all input methods
4130 * can be used, calling with an empty list disables all but the system's own input methods.
4131 *
4132 * <p> System input methods are always available to the user this method can't modify this.
4133 *
4134 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4135 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004136 * @return true if setting the restriction succeeded. It will fail if there are
4137 * one or more non-system input methods currently enabled that are not in
4138 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004139 */
Robin Lee25e26452015-06-02 09:56:29 -07004140 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004141 if (mService != null) {
4142 try {
4143 return mService.setPermittedInputMethods(admin, packageNames);
4144 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004145 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004146 }
4147 }
4148 return false;
4149 }
4150
4151
4152 /**
4153 * Returns the list of permitted input methods set by this device or profile owner.
4154 *
4155 * <p>An empty list means no input methods except system input methods are allowed.
4156 * Null means all input methods are allowed.
4157 *
4158 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4159 * @return List of input method package names.
4160 */
Robin Lee25e26452015-06-02 09:56:29 -07004161 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004162 if (mService != null) {
4163 try {
4164 return mService.getPermittedInputMethods(admin);
4165 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004166 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004167 }
4168 }
4169 return null;
4170 }
4171
4172 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004173 * Called by the system to check if a specific input method is disabled by admin.
4174 *
4175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4176 * @param packageName Input method package name that needs to be checked.
4177 * @param userHandle user id the admin is running as.
4178 * @return true if the input method is permitted, otherwise false.
4179 *
4180 * @hide
4181 */
4182 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4183 @NonNull String packageName, int userHandle) {
4184 if (mService != null) {
4185 try {
4186 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4187 } catch (RemoteException e) {
4188 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4189 }
4190 }
4191 return false;
4192 }
4193
4194 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004195 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004196 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004197 *
4198 * <p>Null means all input methods are allowed, if a non-null list is returned
4199 * it will contain the intersection of the permitted lists for any device or profile
4200 * owners that apply to this user. It will also include any system input methods.
4201 *
4202 * @return List of input method package names.
4203 * @hide
4204 */
4205 @SystemApi
4206 public List<String> getPermittedInputMethodsForCurrentUser() {
4207 if (mService != null) {
4208 try {
4209 return mService.getPermittedInputMethodsForCurrentUser();
4210 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004211 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004212 }
4213 }
4214 return null;
4215 }
4216
4217 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004218 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4219 * currently installed it.
4220 *
4221 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4222 *
4223 * @return List of package names to keep cached.
4224 * @hide
4225 */
4226 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4227 if (mService != null) {
4228 try {
4229 return mService.getKeepUninstalledPackages(admin);
4230 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004231 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004232 }
4233 }
4234 return null;
4235 }
4236
4237 /**
4238 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4239 * currently installed it.
4240 *
4241 * <p>Please note that setting this policy does not imply that specified apps will be
4242 * automatically pre-cached.</p>
4243 *
4244 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4245 * @param packageNames List of package names to keep cached.
4246 * @hide
4247 */
4248 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4249 @NonNull List<String> packageNames) {
4250 if (mService != null) {
4251 try {
4252 mService.setKeepUninstalledPackages(admin, packageNames);
4253 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004254 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004255 }
4256 }
4257 }
4258
4259 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004260 * Called by a device owner to create a user with the specified name. The UserHandle returned
4261 * by this method should not be persisted as user handles are recycled as users are removed and
4262 * created. If you need to persist an identifier for this user, use
4263 * {@link UserManager#getSerialNumberForUser}.
4264 *
4265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4266 * @param name the user's name
4267 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004268 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4269 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004270 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004271 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004272 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004273 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004274 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004275 try {
4276 return mService.createUser(admin, name);
4277 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004278 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004279 }
4280 return null;
4281 }
4282
4283 /**
Jason Monk03978a42014-06-10 15:05:30 -04004284 * Called by a device owner to create a user with the specified name. The UserHandle returned
4285 * by this method should not be persisted as user handles are recycled as users are removed and
4286 * created. If you need to persist an identifier for this user, use
4287 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4288 * immediately.
4289 *
4290 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4291 * as registered as an active admin on the new user. The profile owner package will be
4292 * installed on the new user if it already is installed on the device.
4293 *
4294 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4295 * profileOwnerComponent when onEnable is called.
4296 *
4297 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4298 * @param name the user's name
4299 * @param ownerName the human readable name of the organisation associated with this DPM.
4300 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4301 * the user.
4302 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4303 * on the new user.
4304 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004305 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4306 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004307 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004308 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004309 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004310 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004311 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4312 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004313 try {
4314 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4315 adminExtras);
4316 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004317 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004318 }
4319 return null;
4320 }
4321
4322 /**
phweissa92e1212016-01-25 17:14:10 +01004323 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004324 */
4325 public static final int SKIP_SETUP_WIZARD = 0x0001;
4326
4327 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004328 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4329 * ephemeral.
4330 * @hide
4331 */
4332 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4333
4334 /**
phweissa92e1212016-01-25 17:14:10 +01004335 * Called by a device owner to create a user with the specified name and a given component of
4336 * the calling package as profile owner. The UserHandle returned by this method should not be
4337 * persisted as user handles are recycled as users are removed and created. If you need to
4338 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4339 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004340 *
phweissa92e1212016-01-25 17:14:10 +01004341 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4342 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4343 * will be registered as an active admin on the new user. The profile owner package will be
4344 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004345 *
4346 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4347 * started for the first time. Then the extras will be passed to the admin when
4348 * onEnable is called.
4349 *
4350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4351 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004352 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4353 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4354 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004355 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4356 * user.
phweissa92e1212016-01-25 17:14:10 +01004357 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004358 * @see UserHandle
4359 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4360 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004361 */
4362 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004363 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4364 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004365 try {
phweissa92e1212016-01-25 17:14:10 +01004366 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004367 } catch (RemoteException re) {
4368 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4369 }
4370 return null;
4371 }
4372
4373 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004374 * Called by a device owner to remove a user and all associated data. The primary user can
4375 * not be removed.
4376 *
4377 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4378 * @param userHandle the user to remove.
4379 * @return {@code true} if the user was removed, {@code false} otherwise.
4380 */
Robin Lee25e26452015-06-02 09:56:29 -07004381 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004382 try {
4383 return mService.removeUser(admin, userHandle);
4384 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004385 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004386 return false;
4387 }
4388 }
4389
4390 /**
Jason Monk582d9112014-07-09 19:57:08 -04004391 * Called by a device owner to switch the specified user to the foreground.
4392 *
4393 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4394 * @param userHandle the user to switch to; null will switch to primary.
4395 * @return {@code true} if the switch was successful, {@code false} otherwise.
4396 *
4397 * @see Intent#ACTION_USER_FOREGROUND
4398 */
Robin Lee25e26452015-06-02 09:56:29 -07004399 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004400 try {
4401 return mService.switchUser(admin, userHandle);
4402 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004403 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004404 return false;
4405 }
4406 }
4407
4408 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004409 * Retrieves the application restrictions for a given target application running in the calling
4410 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004411 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004412 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4413 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4414 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004415 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004416 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4417 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004418 * @param packageName The name of the package to fetch restricted settings of.
4419 * @return {@link Bundle} of settings corresponding to what was set last time
4420 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4421 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004422 *
4423 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004424 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004425 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004426 if (mService != null) {
4427 try {
4428 return mService.getApplicationRestrictions(admin, packageName);
4429 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004430 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004431 }
4432 }
4433 return null;
4434 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004435
4436 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004437 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004438 * <p>
4439 * The calling device admin must be a profile or device owner; if it is not,
4440 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004441 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004442 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4443 * with.
4444 * @param key The key of the restriction. See the constants in
4445 * {@link android.os.UserManager} for the list of keys.
4446 */
Robin Lee25e26452015-06-02 09:56:29 -07004447 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004448 if (mService != null) {
4449 try {
4450 mService.setUserRestriction(admin, key, true);
4451 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004452 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004453 }
4454 }
4455 }
4456
4457 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004458 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004459 * <p>
4460 * The calling device admin must be a profile or device owner; if it is not,
4461 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004462 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004463 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4464 * with.
4465 * @param key The key of the restriction. See the constants in
4466 * {@link android.os.UserManager} for the list of keys.
4467 */
Robin Lee25e26452015-06-02 09:56:29 -07004468 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004469 if (mService != null) {
4470 try {
4471 mService.setUserRestriction(admin, key, false);
4472 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004473 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004474 }
4475 }
4476 }
Adam Connors010cfd42014-04-16 12:48:13 +01004477
4478 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004479 * Called by a profile or device owner to get user restrictions set with
4480 * {@link #addUserRestriction(ComponentName, String)}.
4481 * <p>
4482 * The target user may have more restrictions set by the system or other device owner / profile
4483 * owner. To get all the user restrictions currently set, use
4484 * {@link UserManager#getUserRestrictions()}.
4485 *
4486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004487 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004488 */
4489 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004490 return getUserRestrictions(admin, myUserId());
4491 }
4492
4493 /** @hide per-user version */
4494 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004495 Bundle ret = null;
4496 if (mService != null) {
4497 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004498 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004499 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004500 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004501 }
4502 }
4503 return ret == null ? new Bundle() : ret;
4504 }
4505
4506 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004507 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004508 * is unavailable for use, but the data and actual package file remain.
4509 *
4510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004511 * @param packageName The name of the package to hide or unhide.
4512 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4513 * unhidden.
4514 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004515 */
Robin Lee25e26452015-06-02 09:56:29 -07004516 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004517 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004518 if (mService != null) {
4519 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004520 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004521 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004522 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004523 }
4524 }
4525 return false;
4526 }
4527
4528 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004529 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004530 *
4531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004532 * @param packageName The name of the package to retrieve the hidden status of.
4533 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004534 */
Robin Lee25e26452015-06-02 09:56:29 -07004535 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004536 if (mService != null) {
4537 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004538 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004539 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004540 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004541 }
4542 }
4543 return false;
4544 }
4545
4546 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004547 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004548 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004549 *
4550 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004551 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004552 */
Robin Lee25e26452015-06-02 09:56:29 -07004553 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004554 if (mService != null) {
4555 try {
4556 mService.enableSystemApp(admin, packageName);
4557 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004558 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004559 }
4560 }
4561 }
4562
4563 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004564 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004565 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004566 *
4567 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4568 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004569 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004570 * @return int The number of activities that matched the intent and were installed.
4571 */
Robin Lee25e26452015-06-02 09:56:29 -07004572 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004573 if (mService != null) {
4574 try {
4575 return mService.enableSystemAppWithIntent(admin, intent);
4576 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004577 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004578 }
4579 }
4580 return 0;
4581 }
4582
4583 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004584 * Called by a device owner or profile owner to disable account management for a specific type
4585 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004586 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004587 * <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 +01004588 * security exception will be thrown.
4589 *
4590 * <p>When account management is disabled for an account type, adding or removing an account
4591 * of that type will not be possible.
4592 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004593 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4594 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4595 * management for a specific type is disabled.
4596 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004597 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4598 * @param accountType For which account management is disabled or enabled.
4599 * @param disabled The boolean indicating that account management will be disabled (true) or
4600 * enabled (false).
4601 */
Robin Lee25e26452015-06-02 09:56:29 -07004602 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004603 boolean disabled) {
4604 if (mService != null) {
4605 try {
4606 mService.setAccountManagementDisabled(admin, accountType, disabled);
4607 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004608 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004609 }
4610 }
4611 }
4612
4613 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004614 * Gets the array of accounts for which account management is disabled by the profile owner.
4615 *
4616 * <p> Account management can be disabled/enabled by calling
4617 * {@link #setAccountManagementDisabled}.
4618 *
4619 * @return a list of account types for which account management has been disabled.
4620 *
4621 * @see #setAccountManagementDisabled
4622 */
4623 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004624 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004625 }
4626
4627 /**
4628 * @see #getAccountTypesWithManagementDisabled()
4629 * @hide
4630 */
4631 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004632 if (mService != null) {
4633 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004634 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004635 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004636 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004637 }
4638 }
4639
4640 return null;
4641 }
justinzhang511e0d82014-03-24 16:09:24 -04004642
4643 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004644 * Sets which packages may enter lock task mode.
4645 *
4646 * <p>Any packages that shares uid with an allowed package will also be allowed
4647 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004648 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004649 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004650 * package list results in locked tasks belonging to those packages to be finished.
4651 *
Jason Monkc5185f22014-06-24 11:12:42 -04004652 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004653 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004655 *
4656 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004657 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4658 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004659 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004660 */
Robin Lee25e26452015-06-02 09:56:29 -07004661 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004662 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004663 if (mService != null) {
4664 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004665 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004666 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004667 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004668 }
4669 }
4670 }
4671
4672 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004673 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004674 *
4675 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004676 * @hide
4677 */
Robin Lee25e26452015-06-02 09:56:29 -07004678 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004679 if (mService != null) {
4680 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004681 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004682 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004683 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004684 }
4685 }
4686 return null;
4687 }
4688
4689 /**
4690 * This function lets the caller know whether the given component is allowed to start the
4691 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004692 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004693 */
Jason Monkd7b86212014-06-16 13:15:38 -04004694 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004695 if (mService != null) {
4696 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004697 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004698 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004699 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004700 }
4701 }
4702 return false;
4703 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004704
4705 /**
4706 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4707 * 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 -04004708 * <p>The settings that can be updated with this method are:
4709 * <ul>
4710 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4711 * <li>{@link Settings.Global#AUTO_TIME}</li>
4712 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004713 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004714 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004715 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004716 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004717 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004718 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004719 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004720 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004721 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004722 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004723 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004724 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004725 * <ul>
4726 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4727 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4728 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4729 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4730 * <li>{@link Settings.Global#MODE_RINGER}.
4731 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4732 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4733 * <li>{@link Settings.Global#WIFI_ON}.
4734 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4735 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004736 *
4737 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4738 * @param setting The name of the setting to update.
4739 * @param value The value to update the setting to.
4740 */
Robin Lee25e26452015-06-02 09:56:29 -07004741 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004742 if (mService != null) {
4743 try {
4744 mService.setGlobalSetting(admin, setting, value);
4745 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004746 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004747 }
4748 }
4749 }
4750
4751 /**
4752 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4753 * that the value of the setting is in the correct form for the setting type should be performed
4754 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004755 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004756 * <ul>
4757 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004758 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004759 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4760 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004761 * <p>A device owner can additionally update the following settings:
4762 * <ul>
4763 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4764 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4766 * @param setting The name of the setting to update.
4767 * @param value The value to update the setting to.
4768 */
Robin Lee25e26452015-06-02 09:56:29 -07004769 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004770 if (mService != null) {
4771 try {
4772 mService.setSecureSetting(admin, setting, value);
4773 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004774 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004775 }
4776 }
4777 }
4778
Amith Yamasanif20d6402014-05-24 15:34:37 -07004779 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004780 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004781 * making permission requests of a local or remote administrator of the user.
4782 * <p/>
4783 * Only a profile owner can designate the restrictions provider.
4784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004785 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004786 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004787 * it removes the restrictions provider previously assigned.
4788 */
Robin Lee25e26452015-06-02 09:56:29 -07004789 public void setRestrictionsProvider(@NonNull ComponentName admin,
4790 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004791 if (mService != null) {
4792 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004793 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004794 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004795 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004796 }
4797 }
4798 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004799
4800 /**
4801 * Called by profile or device owners to set the master volume mute on or off.
4802 *
4803 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4804 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4805 */
Robin Lee25e26452015-06-02 09:56:29 -07004806 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004807 if (mService != null) {
4808 try {
4809 mService.setMasterVolumeMuted(admin, on);
4810 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004811 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004812 }
4813 }
4814 }
4815
4816 /**
4817 * Called by profile or device owners to check whether the master volume mute is on or off.
4818 *
4819 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4820 * @return {@code true} if master volume is muted, {@code false} if it's not.
4821 */
Robin Lee25e26452015-06-02 09:56:29 -07004822 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004823 if (mService != null) {
4824 try {
4825 return mService.isMasterVolumeMuted(admin);
4826 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004827 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004828 }
4829 }
4830 return false;
4831 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004832
4833 /**
4834 * Called by profile or device owners to change whether a user can uninstall
4835 * a package.
4836 *
4837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4838 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004839 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004840 */
Robin Lee25e26452015-06-02 09:56:29 -07004841 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004842 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004843 if (mService != null) {
4844 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004845 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004846 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004847 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004848 }
4849 }
4850 }
4851
4852 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004853 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004854 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004855 * <p>
4856 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004857 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004858 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004859 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004860 *
Robin Lee25e26452015-06-02 09:56:29 -07004861 * @param admin The name of the admin component whose blocking policy will be checked, or
4862 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004863 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004864 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004865 */
Robin Lee25e26452015-06-02 09:56:29 -07004866 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004867 if (mService != null) {
4868 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004869 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004870 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004871 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004872 }
4873 }
4874 return false;
4875 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004876
4877 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004878 * Called by the profile owner of a managed profile to enable widget providers from a
4879 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004880 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004881 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004882 * a package may have zero or more provider components, where each component
4883 * provides a different widget type.
4884 * <p>
4885 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004886 *
4887 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4888 * @param packageName The package from which widget providers are white-listed.
4889 * @return Whether the package was added.
4890 *
4891 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4892 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4893 */
Robin Lee25e26452015-06-02 09:56:29 -07004894 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004895 if (mService != null) {
4896 try {
4897 return mService.addCrossProfileWidgetProvider(admin, packageName);
4898 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004899 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004900 }
4901 }
4902 return false;
4903 }
4904
4905 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004906 * Called by the profile owner of a managed profile to disable widget providers from a given
4907 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004908 * package should have been added via {@link #addCrossProfileWidgetProvider(
4909 * android.content.ComponentName, String)}.
4910 * <p>
4911 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004912 *
4913 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4914 * @param packageName The package from which widget providers are no longer
4915 * white-listed.
4916 * @return Whether the package was removed.
4917 *
4918 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4919 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4920 */
Esteban Talavera62399912016-01-11 15:37:55 +00004921 public boolean removeCrossProfileWidgetProvider(
4922 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004923 if (mService != null) {
4924 try {
4925 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4926 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004927 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004928 }
4929 }
4930 return false;
4931 }
4932
4933 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004934 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004935 * available in the parent profile.
4936 *
4937 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4938 * @return The white-listed package list.
4939 *
4940 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4941 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4942 */
Robin Lee25e26452015-06-02 09:56:29 -07004943 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004944 if (mService != null) {
4945 try {
4946 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4947 if (providers != null) {
4948 return providers;
4949 }
4950 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004951 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004952 }
4953 }
4954 return Collections.emptyList();
4955 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004956
4957 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004958 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004959 *
4960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4961 * @param icon the bitmap to set as the photo.
4962 */
Robin Lee25e26452015-06-02 09:56:29 -07004963 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004964 try {
4965 mService.setUserIcon(admin, icon);
4966 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004967 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004968 }
4969 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04004970
4971 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004972 * Called by device owners to set a local system update policy. When a new policy is set,
4973 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004974 *
Robin Lee25e26452015-06-02 09:56:29 -07004975 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
4976 * components in the device owner package can set system update policies and the
4977 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01004978 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07004979 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01004980 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00004981 */
Robin Lee25e26452015-06-02 09:56:29 -07004982 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004983 if (mService != null) {
4984 try {
Robin Lee25e26452015-06-02 09:56:29 -07004985 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004986 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004987 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00004988 }
4989 }
4990 }
4991
4992 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01004993 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004994 *
Robin Lee25e26452015-06-02 09:56:29 -07004995 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00004996 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01004997 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00004998 if (mService != null) {
4999 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005000 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005001 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005002 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005003 }
5004 }
5005 return null;
5006 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005007
5008 /**
5009 * Called by a device owner to disable the keyguard altogether.
5010 *
5011 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5012 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5013 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5014 * being disabled.
5015 *
5016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005017 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005018 *
5019 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005020 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005021 */
Robin Lee25e26452015-06-02 09:56:29 -07005022 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005023 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005024 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005025 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005026 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01005027 return false;
5028 }
5029 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005030
5031 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005032 * Called by device owner to disable the status bar. Disabling the status bar blocks
5033 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005034 * a single use device.
5035 *
5036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005037 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5038 *
5039 * @return {@code false} if attempting to disable the status bar failed.
5040 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005041 */
Robin Lee25e26452015-06-02 09:56:29 -07005042 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005043 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005044 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005045 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005046 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01005047 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00005048 }
5049 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005050
5051 /**
5052 * Callable by the system update service to notify device owners about pending updates.
5053 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5054 * permission.
5055 *
5056 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5057 * when the current pending update was first available. -1 if no update is available.
5058 * @hide
5059 */
5060 @SystemApi
5061 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5062 if (mService != null) {
5063 try {
5064 mService.notifyPendingSystemUpdate(updateReceivedTime);
5065 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005066 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01005067 }
5068 }
5069 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005070
5071 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005072 * Called by profile or device owners to set the default response for future runtime permission
5073 * requests by applications. The policy can allow for normal operation which prompts the
5074 * user to grant a permission, or can allow automatic granting or denying of runtime
5075 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005076 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5077 * the permission grant state via {@link #setPermissionGrantState}.
5078 *
5079 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005080 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005081 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005082 * @param admin Which profile or device owner this request is associated with.
5083 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5084 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005085 *
5086 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005087 */
Robin Lee25e26452015-06-02 09:56:29 -07005088 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005089 try {
5090 mService.setPermissionPolicy(admin, policy);
5091 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005092 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005093 }
5094 }
5095
5096 /**
5097 * Returns the current runtime permission policy set by the device or profile owner. The
5098 * default is {@link #PERMISSION_POLICY_PROMPT}.
5099 * @param admin Which profile or device owner this request is associated with.
5100 * @return the current policy for future permission requests.
5101 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005102 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005103 try {
5104 return mService.getPermissionPolicy(admin);
5105 } catch (RemoteException re) {
5106 return PERMISSION_POLICY_PROMPT;
5107 }
5108 }
5109
5110 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005111 * Sets the grant state of a runtime permission for a specific application. The state
5112 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5113 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5114 * is denied and the user cannot manage it through the UI, and {@link
5115 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5116 * user cannot manage it through the UI. This might affect all permissions in a
5117 * group that the runtime permission belongs to. This method can only be called
5118 * by a profile or device owner.
5119 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005120 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5121 * revoke the permission. It retains the previous grant, if any.
5122 *
5123 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005124 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005125 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005126 * @param admin Which profile or device owner this request is associated with.
5127 * @param packageName The application to grant or revoke a permission to.
5128 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005129 * @param grantState The permission grant state which is one of {@link
5130 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5131 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5132 * @return whether the permission was successfully granted or revoked.
5133 *
5134 * @see #PERMISSION_GRANT_STATE_DENIED
5135 * @see #PERMISSION_GRANT_STATE_DEFAULT
5136 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005137 */
Robin Lee25e26452015-06-02 09:56:29 -07005138 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005139 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005140 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005141 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005142 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005143 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005144 return false;
5145 }
5146 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005147
5148 /**
5149 * Returns the current grant state of a runtime permission for a specific application.
5150 *
5151 * @param admin Which profile or device owner this request is associated with.
5152 * @param packageName The application to check the grant state for.
5153 * @param permission The permission to check for.
5154 * @return the current grant state specified by device policy. If the profile or device owner
5155 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5156 * This does not indicate whether or not the permission is currently granted for the package.
5157 *
5158 * <p/>If a grant state was set by the profile or device owner, then the return value will
5159 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5160 * which indicates if the permission is currently denied or granted.
5161 *
5162 * @see #setPermissionGrantState(ComponentName, String, String, int)
5163 * @see PackageManager#checkPermission(String, String)
5164 */
Robin Lee25e26452015-06-02 09:56:29 -07005165 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005166 String permission) {
5167 try {
5168 return mService.getPermissionGrantState(admin, packageName, permission);
5169 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005170 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005171 return PERMISSION_GRANT_STATE_DEFAULT;
5172 }
5173 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005174
5175 /**
5176 * Returns if provisioning a managed profile or device is possible or not.
5177 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5178 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5179 * Note that even if this method returns true, there is a slight possibility that the
5180 * provisioning will not be allowed when it is actually initiated because some event has
5181 * happened in between.
5182 * @return if provisioning a managed profile or device is possible or not.
5183 * @throws IllegalArgumentException if the supplied action is not valid.
5184 */
5185 public boolean isProvisioningAllowed(String action) {
5186 try {
5187 return mService.isProvisioningAllowed(action);
5188 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005189 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005190 return false;
5191 }
5192 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005193
5194 /**
5195 * @hide
5196 * Return if this user is a managed profile of another user. An admin can become the profile
5197 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5198 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5199 * @param admin Which profile owner this request is associated with.
5200 * @return if this user is a managed profile of another user.
5201 */
5202 public boolean isManagedProfile(@NonNull ComponentName admin) {
5203 try {
5204 return mService.isManagedProfile(admin);
5205 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005206 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005207 return false;
5208 }
5209 }
5210
5211 /**
5212 * @hide
5213 * Return if this user is a system-only user. An admin can manage a device from a system only
5214 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5215 * @param admin Which device owner this request is associated with.
5216 * @return if this user is a system-only user.
5217 */
5218 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5219 try {
5220 return mService.isSystemOnlyUser(admin);
5221 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005222 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005223 return false;
5224 }
5225 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005226
5227 /**
5228 * Called by device owner to get the MAC address of the Wi-Fi device.
5229 *
5230 * @return the MAC address of the Wi-Fi device, or null when the information is not
5231 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5232 *
5233 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5234 */
5235 public String getWifiMacAddress() {
5236 try {
5237 return mService.getWifiMacAddress();
5238 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005239 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005240 return null;
5241 }
5242 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005243
5244 /**
5245 * Called by device owner to reboot the device.
5246 */
5247 public void reboot(@NonNull ComponentName admin) {
5248 try {
5249 mService.reboot(admin);
5250 } catch (RemoteException re) {
5251 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5252 }
5253 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005254
5255 /**
5256 * Called by a device admin to set the short support message. This will
5257 * be displayed to the user in settings screens where funtionality has
5258 * been disabled by the admin.
5259 *
5260 * The message should be limited to a short statement such as
5261 * "This setting is disabled by your administrator. Contact someone@example.com
5262 * for support."
5263 * If the message is longer than 200 characters it may be truncated.
5264 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005265 * <p>If the short support message needs to be localized, it is the responsibility of the
5266 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5267 * and set a new version of this string accordingly.
5268 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005269 * @see #setLongSupportMessage
5270 *
5271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5272 * @param message Short message to be displayed to the user in settings or null to
5273 * clear the existing message.
5274 */
5275 public void setShortSupportMessage(@NonNull ComponentName admin,
5276 @Nullable String message) {
5277 if (mService != null) {
5278 try {
5279 mService.setShortSupportMessage(admin, message);
5280 } catch (RemoteException e) {
5281 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5282 }
5283 }
5284 }
5285
5286 /**
5287 * Called by a device admin to get the short support message.
5288 *
5289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5290 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5291 * or null if no message has been set.
5292 */
5293 public String getShortSupportMessage(@NonNull ComponentName admin) {
5294 if (mService != null) {
5295 try {
5296 return mService.getShortSupportMessage(admin);
5297 } catch (RemoteException e) {
5298 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5299 }
5300 }
5301 return null;
5302 }
5303
5304 /**
5305 * Called by a device admin to set the long support message. This will
5306 * be displayed to the user in the device administators settings screen.
5307 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005308 * <p>If the long support message needs to be localized, it is the responsibility of the
5309 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5310 * and set a new version of this string accordingly.
5311 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005312 * @see #setShortSupportMessage
5313 *
5314 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5315 * @param message Long message to be displayed to the user in settings or null to
5316 * clear the existing message.
5317 */
5318 public void setLongSupportMessage(@NonNull ComponentName admin,
5319 @Nullable String message) {
5320 if (mService != null) {
5321 try {
5322 mService.setLongSupportMessage(admin, message);
5323 } catch (RemoteException e) {
5324 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5325 }
5326 }
5327 }
5328
5329 /**
5330 * Called by a device admin to get the long support message.
5331 *
5332 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5333 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5334 * or null if no message has been set.
5335 */
5336 public String getLongSupportMessage(@NonNull ComponentName admin) {
5337 if (mService != null) {
5338 try {
5339 return mService.getLongSupportMessage(admin);
5340 } catch (RemoteException e) {
5341 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5342 }
5343 }
5344 return null;
5345 }
5346
5347 /**
5348 * Called by the system to get the short support message.
5349 *
5350 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5351 * @param userHandle user id the admin is running as.
5352 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5353 *
5354 * @hide
5355 */
5356 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5357 if (mService != null) {
5358 try {
5359 return mService.getShortSupportMessageForUser(admin, userHandle);
5360 } catch (RemoteException e) {
5361 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5362 }
5363 }
5364 return null;
5365 }
5366
5367
5368 /**
5369 * Called by the system to get the long support message.
5370 *
5371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5372 * @param userHandle user id the admin is running as.
5373 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5374 *
5375 * @hide
5376 */
5377 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5378 if (mService != null) {
5379 try {
5380 return mService.getLongSupportMessageForUser(admin, userHandle);
5381 } catch (RemoteException e) {
5382 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5383 }
5384 }
5385 return null;
5386 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005387
5388 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005389 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5390 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005391 *
5392 * <p> Note only some methods will work on the parent Manager.
5393 *
5394 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5395 */
5396 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5397 try {
5398 if (!mService.isManagedProfile(admin)) {
5399 throw new SecurityException("The current user does not have a parent profile.");
5400 }
5401 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005402 } catch (RemoteException e) {
5403 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5404 return null;
5405 }
5406 }
5407
5408 /**
5409 * Called by device owner to control the device logging feature. Logging can only be
5410 * enabled on single user devices where the sole user is managed by the device owner.
5411 *
5412 * <p> Device logs contain various information intended for security auditing purposes.
5413 * See {@link SecurityEvent} for details.
5414 *
5415 * @param admin Which device owner this request is associated with.
5416 * @param enabled whether device logging should be enabled or not.
5417 * @see #retrieveDeviceLogs
5418 */
5419 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5420 try {
5421 mService.setDeviceLoggingEnabled(admin, enabled);
5422 } catch (RemoteException re) {
5423 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5424 }
5425 }
5426
5427 /**
5428 * Return whether device logging is enabled or not by the device owner.
5429 *
5430 * @param admin Which device owner this request is associated with.
5431 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5432 */
5433 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5434 try {
5435 return mService.getDeviceLoggingEnabled(admin);
5436 } catch (RemoteException re) {
5437 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5438 return false;
5439 }
5440 }
5441
5442 /**
5443 * Called by device owner to retrieve all new device logging entries since the last call to
5444 * this API after device boots.
5445 *
5446 * <p> Access to the logs is rate limited and it will only return new logs after the device
5447 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5448 *
5449 * @param admin Which device owner this request is associated with.
5450 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5451 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5452 */
5453 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5454 try {
5455 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5456 if (list != null) {
5457 return list.getList();
5458 } else {
5459 // Rate limit exceeded.
5460 return null;
5461 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005462 } catch (RemoteException re) {
5463 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5464 return null;
5465 }
5466 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005467
5468 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005469 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5470 * profile.
5471 *
5472 * @hide
5473 */
5474 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5475 mContext.checkSelfPermission(
5476 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5477 if (!uInfo.isManagedProfile()) {
5478 throw new SecurityException("The user " + uInfo.id
5479 + " does not have a parent profile.");
5480 }
5481 return new DevicePolicyManager(mContext, true);
5482 }
5483
5484 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005485 * Called by device owners to retrieve device logs from before the device's last reboot.
5486 *
5487 * <p>
5488 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5489 * corruption-free during power cycles, due to hardware variations and limitations. As a
5490 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5491 * </strong>
5492 *
5493 * @param admin Which device owner this request is associated with.
5494 * @return Device logs from before the latest reboot of the system.
5495 */
5496 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5497 try {
5498 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5499 return list.getList();
5500 } catch (RemoteException re) {
5501 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5502 return Collections.<SecurityEvent>emptyList();
5503 }
5504 }
5505
5506 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005507 * Called by a profile owner of a managed profile to set the color used for customization.
5508 * This color is used as background color of the confirm credentials screen for that user.
5509 * The default color is {@link android.graphics.Color#GRAY}.
5510 *
5511 * <p>The confirm credentials screen can be created using
5512 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5513 *
5514 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5515 * @param color The 32bit representation of the color to be used.
5516 */
5517 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5518 try {
5519 mService.setOrganizationColor(admin, color);
5520 } catch (RemoteException re) {
5521 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5522 }
5523 }
5524
5525 /**
5526 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5527 * This color is used as background color of the confirm credentials screen for that user.
5528 *
5529 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5530 * @return The 32bit representation of the color to be used.
5531 */
5532 public int getOrganizationColor(@NonNull ComponentName admin) {
5533 try {
5534 return mService.getOrganizationColor(admin);
5535 } catch (RemoteException re) {
5536 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5537 return 0;
5538 }
5539 }
5540
5541 /**
5542 * @hide
5543 * Retrieve the customization color for a given user.
5544 *
5545 * @param userHandle The user id of the user we're interested in.
5546 * @return The 32bit representation of the color to be used.
5547 */
5548 public int getOrganizationColorForUser(int userHandle) {
5549 try {
5550 return mService.getOrganizationColorForUser(userHandle);
5551 } catch (RemoteException re) {
5552 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5553 return 0;
5554 }
5555 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005556
5557 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005558 * Called by a profile owner of a managed profile to set the name of the organization under
5559 * management.
5560 *
5561 * <p>If the organization name needs to be localized, it is the responsibility of the
5562 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5563 * and set a new version of this string accordingly.
5564 *
5565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5566 * @param title The organization name or {@code null} to clear a previously set name.
5567 */
5568 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5569 try {
5570 mService.setOrganizationName(admin, title);
5571 } catch (RemoteException re) {
5572 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5573 }
5574 }
5575
5576 /**
5577 * Called by a profile owner of a managed profile to retrieve the name of the organization
5578 * under management.
5579 *
5580 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5581 * @return The organization name or {@code null} if none is set.
5582 */
5583 public String getOrganizationName(@NonNull ComponentName admin) {
5584 try {
5585 return mService.getOrganizationName(admin);
5586 } catch (RemoteException re) {
5587 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5588 return null;
5589 }
5590 }
5591
5592 /**
5593 * Retrieve the default title message used in the confirm credentials screen for a given user.
5594 *
5595 * @param userHandle The user id of the user we're interested in.
5596 * @return The organization name or {@code null} if none is set.
5597 *
5598 * @hide
5599 */
5600 public String getOrganizationNameForUser(int userHandle) {
5601 try {
5602 return mService.getOrganizationNameForUser(userHandle);
5603 } catch (RemoteException re) {
5604 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5605 return null;
5606 }
5607 }
5608
5609 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005610 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5611 * return {@link #STATE_USER_UNMANAGED}
5612 * @hide
5613 */
5614 @UserProvisioningState
5615 public int getUserProvisioningState() {
5616 if (mService != null) {
5617 try {
5618 return mService.getUserProvisioningState();
5619 } catch (RemoteException e) {
5620 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5621 }
5622 }
5623 return STATE_USER_UNMANAGED;
5624 }
5625
5626 /**
5627 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5628 *
5629 * @param state to store
5630 * @param userHandle for user
5631 * @hide
5632 */
5633 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5634 if (mService != null) {
5635 try {
5636 mService.setUserProvisioningState(state, userHandle);
5637 } catch (RemoteException e) {
5638 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5639 }
5640 }
5641 }
5642
5643 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005644 * @hide
5645 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5646 * affiliated if it is managed by the same entity as the device.
5647 *
5648 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5649 * user/profile is considered affiliated if the following conditions are both met:
5650 * <ul>
5651 * <li>The device owner and the user's/profile's profile owner have called this method,
5652 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5653 * and a profile owner intersect, they must have come from the same source, which means that
5654 * the device owner and profile owner are controlled by the same entity.</li>
5655 * <li>The device owner's and profile owner's package names are the same.</li>
5656 * </ul>
5657 *
5658 * @param admin Which profile or device owner this request is associated with.
5659 * @param ids A set of opaque affiliation ids.
5660 */
5661 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5662 try {
5663 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5664 } catch (RemoteException e) {
5665 Log.w(TAG, "Failed talking with device policy service", e);
5666 }
5667 }
5668
5669 /**
5670 * @hide
5671 * Returns whether this user/profile is affiliated with the device. See
5672 * {@link #setAffiliationIds} for the definition of affiliation.
5673 *
5674 * @return whether this user/profile is affiliated with the device.
5675 */
5676 public boolean isAffiliatedUser() {
5677 try {
5678 return mService != null && mService.isAffiliatedUser();
5679 } catch (RemoteException e) {
5680 Log.w(TAG, "Failed talking with device policy service", e);
5681 return false;
5682 }
5683 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005684}