blob: f06979a2c42cae079d2b074fd72a875bc5b570a3 [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.
Steven Ng980a1b62016-02-02 17:43:18 +0000244 *
245 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
246 * the device. A device owner has full control over the device. The device owner can not be
247 * modified by the user and the only way of resetting the device is via factory reset.
248 *
249 * <p>A typical use case would be a device that is owned by a company, but used by either an
250 * employee or client.
251 *
252 * <p>The provisioning message should be sent to an unprovisioned device.
253 *
254 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
255 * by a privileged app with the permission
256 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
257 *
258 * <p>The provisioning intent contains the following properties:
259 * <ul>
260 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
261 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
263 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
276 *
277 * @hide
278 */
279 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
280 @SystemApi
281 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
282 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
283
284 /**
285 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000286 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
287 *
288 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
289 * management state that is distinct from that reached by
290 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
291 * user, and only has control over device-wide policies, not individual users and their data.
292 * The primary benefit is that multiple non-system users are supported when provisioning using
293 * this form of device management.
294 *
295 * <p> During device owner provisioning a device admin app is set as the owner of the device.
296 * A device owner has full control over the device. The device owner can not be modified by the
297 * user.
298 *
299 * <p> A typical use case would be a device that is owned by a company, but used by either an
300 * employee or client.
301 *
302 * <p> An intent with this action can be sent only on an unprovisioned device.
303 * It is possible to check if provisioning is allowed or not by querying the method
304 * {@link #isProvisioningAllowed(String)}.
305 *
306 * <p>The intent contains the following extras:
307 * <ul>
308 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
309 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
310 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
311 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
312 * </ul>
313 *
314 * <p> When device owner provisioning has completed, an intent of the type
315 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
316 * device owner.
317 *
318 * <p> If provisioning fails, the device is factory reset.
319 *
320 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
321 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
322 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
323 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
324 *
325 * @hide
326 */
327 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
328 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
329 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
330
331 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000332 * Activity action: Finalizes management provisioning, should be used after user-setup
333 * has been completed and {@link #getUserProvisioningState()} returns one of:
334 * <ul>
335 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
336 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
337 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
338 * </ul>
339 *
340 * @hide
341 */
342 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
343 public static final String ACTION_PROVISION_FINALIZATION
344 = "android.app.action.PROVISION_FINALIZATION";
345
346 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100347 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100348 * allows a mobile device management application or NFC programmer application which starts
349 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100350 * <p>
351 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
352 * sends the intent to pass data to itself on the newly created profile.
353 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
354 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100355 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
356 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
357 * message should contain a stringified {@link java.util.Properties} instance, whose string
358 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
359 * management application after provisioning.
360 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100361 * <p>
362 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700363 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
364 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100365 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100366 */
367 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100368 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100369
370 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100371 * A String extra holding the package name of the mobile device management application that
372 * will be set as the profile owner or device owner.
373 *
374 * <p>If an application starts provisioning directly via an intent with action
375 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
376 * application that started provisioning. The package will be set as profile owner in that case.
377 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000378 * <p>This package is set as device owner when device owner provisioning is started by an NFC
379 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000380 *
381 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700382 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000383
384 * @see DeviceAdminReceiver
385 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100386 * supported, but only if there is only one device admin receiver in the package that requires
387 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000388 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000389 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000390 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100391 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000392
393 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000394 * A ComponentName extra indicating the device admin receiver of the mobile device management
395 * application that will be set as the profile owner or device owner and active admin.
396 *
397 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100398 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
399 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
400 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000401 *
402 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100403 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
404 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400405 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000406 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000407 *
408 * @see DeviceAdminReceiver
409 */
410 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
411 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
412
413 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000414 * An {@link android.accounts.Account} extra holding the account to migrate during managed
415 * profile provisioning. If the account supplied is present in the primary user, it will be
416 * copied, along with its credentials to the managed profile and removed from the primary user.
417 *
418 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
419 */
420
421 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
422 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
423
424 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100425 * A String extra that, holds the email address of the account which a managed profile is
426 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
427 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100428 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100429 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
430 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100431 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
432 * contains this extra, it is forwarded in the
433 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
434 * device management application that was set as the profile owner during provisioning.
435 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100436 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100437 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
438 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100439
440 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000441 * A integer extra indicating the predominant color to show during the provisioning.
442 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000443 *
444 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
445 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
446 */
447 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
448 "android.app.extra.PROVISIONING_MAIN_COLOR";
449
450 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000451 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700452 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000453 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100454 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
455 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000456 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000457 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
458 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000459
460 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100461 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
462 * will be set to.
463 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000464 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
465 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100466 */
467 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100468 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469
470 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100471 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
472 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100473 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000474 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
475 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100476 */
477 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100478 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100479
480 /**
481 * A String extra holding the {@link java.util.Locale} that the device will be set to.
482 * Format: xx_yy, where xx is the language code, and yy the country code.
483 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000484 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
485 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100486 */
487 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100488 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100489
490 /**
491 * A String extra holding the ssid of the wifi network that should be used during nfc device
492 * owner provisioning for downloading the mobile device management application.
493 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000494 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
495 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100496 */
497 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100498 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100499
500 /**
501 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
502 * is hidden or not.
503 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000504 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
505 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100506 */
507 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100508 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509
510 /**
511 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100512 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
513 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100514 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000515 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
516 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100517 */
518 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100519 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520
521 /**
522 * A String extra holding the password of the wifi network in
523 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
524 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000525 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
526 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100527 */
528 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100529 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100530
531 /**
532 * A String extra holding the proxy host for the wifi network in
533 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
534 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000535 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
536 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100537 */
538 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100539 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100540
541 /**
542 * An int extra holding the proxy port for the wifi network in
543 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
544 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
546 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100547 */
548 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100549 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100550
551 /**
552 * A String extra holding the proxy bypass for the wifi network in
553 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100557 */
558 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100559 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100560
561 /**
562 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
563 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
564 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
566 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100567 */
568 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100569 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570
571 /**
572 * A String extra holding a url that specifies the download location of the device admin
573 * package. When not provided it is assumed that the device admin package is already installed.
574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
576 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577 */
578 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100579 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580
581 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400582 * An int extra holding a minimum required version code for the device admin package. If the
583 * device admin is already installed on the device, it will only be re-downloaded from
584 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
585 * installed package is less than this version code.
586 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400588 * provisioning via an NFC bump.
589 */
590 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
591 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
592
593 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100594 * A String extra holding a http cookie header which should be used in the http request to the
595 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100599 */
600 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100602
603 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100604 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
605 * the file at download location specified in
606 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100607 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100608 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100609 * present. The provided checksum should match the checksum of the file at the download
610 * location. If the checksum doesn't match an error will be shown to the user and the user will
611 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000613 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
614 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100615 *
616 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
617 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700618 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100619 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 */
621 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100622 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623
624 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100625 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100626 * android package archive at the download location specified in {@link
627 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
628 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100629 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100630 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
631 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
632 *
633 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100634 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100635 * the download location. If the checksum does not match an error will be shown to the user and
636 * the user will be asked to factory reset the device.
637 *
638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
640 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100641 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
642 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100643
644 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000645 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
646 * has completed successfully.
647 *
648 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700649 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000650 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800651 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000652 * corresponds to the account requested to be migrated at provisioning time, if any.
653 */
654 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
655 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
656 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
657
658 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400659 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500660 * provisioning.
661 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400662 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100663 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500664 */
665 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
666 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
667
668 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000669 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
670 * provisioning. If this extra is not passed, a default image will be shown.
671 * <h5>The following URI schemes are accepted:</h5>
672 * <ul>
673 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
674 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
675 * </ul>
676 *
677 * <p> It is the responsability of the caller to provide an image with a reasonable
678 * pixed density for the device.
679 *
680 * <p> If a content: URI is passed, the intent should have the flag
681 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
682 * {@link android.content.ClipData} of the intent too.
683 *
684 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
685 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
686 */
687 public static final String EXTRA_PROVISIONING_LOGO_URI =
688 "android.app.extra.PROVISIONING_LOGO_URI";
689
690 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000691 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
692 * during setup-wizard.
693 *
694 * <p>If unspecified, defaults to {@code true} to match the behavior in
695 * {@link android.os.Build.VERSION_CODES#M} and earlier.
696 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000697 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
698 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000699 *
700 * @hide
701 */
702 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
703 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
704
705 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400706 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100707 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400708 * <p>During device owner provisioning a device admin app is set as the owner of the device.
709 * A device owner has full control over the device. The device owner can not be modified by the
710 * user and the only way of resetting the device is if the device owner app calls a factory
711 * reset.
712 *
713 * <p> A typical use case would be a device that is owned by a company, but used by either an
714 * employee or client.
715 *
716 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100717 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000718 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100719 * contains the following properties:
720 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400721 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
722 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100723 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400724 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100725 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
726 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
727 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
728 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
729 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
730 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
731 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
732 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
733 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
734 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100735 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
736 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
737 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100738 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000739 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700740 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400741 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
742 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
743 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400744 */
745 public static final String MIME_TYPE_PROVISIONING_NFC
746 = "application/com.android.managedprovisioning";
747
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100748 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800749 * Activity action: ask the user to add a new device administrator to the system.
750 * The desired policy is the ComponentName of the policy in the
751 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
752 * bring the user through adding the device administrator to the system (or
753 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700754 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800755 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
756 * field to provide the user with additional explanation (in addition
757 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800758 *
759 * <p>If your administrator is already active, this will ordinarily return immediately (without
760 * user intervention). However, if your administrator has been updated and is requesting
761 * additional uses-policy flags, the user will be presented with the new list. New policies
762 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800763 */
764 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
765 public static final String ACTION_ADD_DEVICE_ADMIN
766 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700767
Dianne Hackbornd6847842010-01-12 18:14:19 -0800768 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700769 * @hide
770 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700771 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700772 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700773 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
774 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700775 * to remotely control restrictions on the user.
776 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800777 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700778 * result of whether or not the user approved the action. If approved, the result will
779 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
780 * as a profile owner.
781 *
782 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
783 * field to provide the user with additional explanation (in addition
784 * to your component's description) about what is being added.
785 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700786 * <p>If there is already a profile owner active or the caller is not a system app, the
787 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700788 */
789 @SystemApi
790 public static final String ACTION_SET_PROFILE_OWNER
791 = "android.app.action.SET_PROFILE_OWNER";
792
793 /**
794 * @hide
795 * Name of the profile owner admin that controls the user.
796 */
797 @SystemApi
798 public static final String EXTRA_PROFILE_OWNER_NAME
799 = "android.app.extra.PROFILE_OWNER_NAME";
800
801 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100802 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700803 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700804 *
Jim Miller284b62e2010-06-08 14:27:42 -0700805 * @hide
806 */
807 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
808 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
809
810 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100811 * Broadcast action: sent when the device owner is set or changed.
812 *
813 * This broadcast is sent only to the primary user.
814 * @see #ACTION_PROVISION_MANAGED_DEVICE
815 */
816 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
817 public static final String ACTION_DEVICE_OWNER_CHANGED
818 = "android.app.action.DEVICE_OWNER_CHANGED";
819
820 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800821 * The ComponentName of the administrator component.
822 *
823 * @see #ACTION_ADD_DEVICE_ADMIN
824 */
825 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700826
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800828 * An optional CharSequence providing additional explanation for why the
829 * admin is being added.
830 *
831 * @see #ACTION_ADD_DEVICE_ADMIN
832 */
833 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700834
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800835 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700836 * Activity action: have the user enter a new password. This activity should
837 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
838 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
839 * enter a new password that meets the current requirements. You can use
840 * {@link #isActivePasswordSufficient()} to determine whether you need to
841 * have the user select a new password in order to meet the current
842 * constraints. Upon being resumed from this activity, you can check the new
843 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000844 *
845 * If the intent is launched from within a managed profile with a profile
846 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
847 * this will trigger entering a new password for the parent of the profile.
848 * For all other cases it will trigger entering a new password for the user
849 * or profile it is launched from.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800850 */
851 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
852 public static final String ACTION_SET_NEW_PASSWORD
853 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700854
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000855 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000856 * Activity action: have the user enter a new password for the parent profile.
857 * If the intent is launched from within a managed profile, this will trigger
858 * entering a new password for the parent of the profile. In all other cases
859 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
860 */
861 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
862 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
863 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
864
865 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000866 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
867 * the parent profile to access intents sent from the managed profile.
868 * That is, when an app in the managed profile calls
869 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
870 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000871 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100872 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000873
874 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000875 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
876 * the managed profile to access intents sent from the parent profile.
877 * That is, when an app in the parent profile calls
878 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
879 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000880 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100881 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700882
Dianne Hackbornd6847842010-01-12 18:14:19 -0800883 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100884 * Broadcast action: notify that a new local system update policy has been set by the device
885 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000886 */
887 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100888 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
889 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000890
Amith Yamasanid49489b2015-04-28 14:00:26 -0700891 /**
892 * Permission policy to prompt user for new permission requests for runtime permissions.
893 * Already granted or denied permissions are not affected by this.
894 */
895 public static final int PERMISSION_POLICY_PROMPT = 0;
896
897 /**
898 * Permission policy to always grant new permission requests for runtime permissions.
899 * Already granted or denied permissions are not affected by this.
900 */
901 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
902
903 /**
904 * Permission policy to always deny new permission requests for runtime permissions.
905 * Already granted or denied permissions are not affected by this.
906 */
907 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
908
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700909 /**
910 * Runtime permission state: The user can manage the permission
911 * through the UI.
912 */
913 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
914
915 /**
916 * Runtime permission state: The permission is granted to the app
917 * and the user cannot manage the permission through the UI.
918 */
919 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
920
921 /**
922 * Runtime permission state: The permission is denied to the app
923 * and the user cannot manage the permission through the UI.
924 */
925 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000926
927 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000928 * No management for current user in-effect. This is the default.
929 * @hide
930 */
931 public static final int STATE_USER_UNMANAGED = 0;
932
933 /**
934 * Management partially setup, user setup needs to be completed.
935 * @hide
936 */
937 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
938
939 /**
940 * Management partially setup, user setup completed.
941 * @hide
942 */
943 public static final int STATE_USER_SETUP_COMPLETE = 2;
944
945 /**
946 * Management setup and active on current user.
947 * @hide
948 */
949 public static final int STATE_USER_SETUP_FINALIZED = 3;
950
951 /**
952 * Management partially setup on a managed profile.
953 * @hide
954 */
955 public static final int STATE_USER_PROFILE_COMPLETE = 4;
956
957 /**
958 * @hide
959 */
960 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
961 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
962 @Retention(RetentionPolicy.SOURCE)
963 public @interface UserProvisioningState {}
964
965 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800966 * Return true if the given administrator component is currently
967 * active (enabled) in the system.
968 */
Robin Lee25e26452015-06-02 09:56:29 -0700969 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700970 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100971 }
972
973 /**
974 * @see #isAdminActive(ComponentName)
975 * @hide
976 */
Robin Lee25e26452015-06-02 09:56:29 -0700977 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800978 if (mService != null) {
979 try {
Robin Lee25e26452015-06-02 09:56:29 -0700980 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800981 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800982 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800983 }
984 }
985 return false;
986 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800987 /**
988 * Return true if the given administrator component is currently being removed
989 * for the user.
990 * @hide
991 */
Robin Lee25e26452015-06-02 09:56:29 -0700992 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800993 if (mService != null) {
994 try {
Robin Lee25e26452015-06-02 09:56:29 -0700995 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800996 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800997 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800998 }
999 }
1000 return false;
1001 }
1002
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001003
Dianne Hackbornd6847842010-01-12 18:14:19 -08001004 /**
Robin Lee25e26452015-06-02 09:56:29 -07001005 * Return a list of all currently active device administrators' component
1006 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001007 * returned.
1008 */
1009 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001010 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001011 }
1012
1013 /**
1014 * @see #getActiveAdmins()
1015 * @hide
1016 */
1017 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001018 if (mService != null) {
1019 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001020 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001021 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001022 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001023 }
1024 }
1025 return null;
1026 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001027
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001028 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001029 * Used by package administration code to determine if a package can be stopped
1030 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001031 * @hide
1032 */
1033 public boolean packageHasActiveAdmins(String packageName) {
1034 if (mService != null) {
1035 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001036 return mService.packageHasActiveAdmins(packageName, myUserId());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001037 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001038 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001039 }
1040 }
1041 return false;
1042 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001043
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001044 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001045 * Remove a current administration component. This can only be called
1046 * by the application that owns the administration component; if you
1047 * try to remove someone else's component, a security exception will be
1048 * thrown.
1049 */
Robin Lee25e26452015-06-02 09:56:29 -07001050 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001051 if (mService != null) {
1052 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001053 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001054 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001055 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 }
1057 }
1058 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059
Dianne Hackbornd6847842010-01-12 18:14:19 -08001060 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001061 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001062 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001063 * but requires additional policies after an upgrade.
1064 *
1065 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1066 * an active administrator, or an exception will be thrown.
1067 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1068 */
Robin Lee25e26452015-06-02 09:56:29 -07001069 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001070 if (mService != null) {
1071 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001072 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001073 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001074 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001075 }
1076 }
1077 return false;
1078 }
1079
1080 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001081 * Returns true if the Profile Challenge is available to use for the given profile user.
1082 *
1083 * @hide
1084 */
1085 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1086 if (mService != null) {
1087 try {
1088 return mService.isSeparateProfileChallengeAllowed(userHandle);
1089 } catch (RemoteException e) {
1090 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1091 }
1092 }
1093 return false;
1094 }
1095
1096 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001097 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1098 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001099 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001100 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001101 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001102
Dianne Hackbornd6847842010-01-12 18:14:19 -08001103 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001104 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1105 * recognition technology. This implies technologies that can recognize the identity of
1106 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1107 * Note that quality constants are ordered so that higher values are more restrictive.
1108 */
1109 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1110
1111 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001112 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001113 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001114 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001115 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001116 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001117
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001118 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001119 * Constant for {@link #setPasswordQuality}: the user must have entered a
1120 * password containing at least numeric characters. Note that quality
1121 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001122 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001123 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001124
Dianne Hackbornd6847842010-01-12 18:14:19 -08001125 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001126 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001127 * password containing at least numeric characters with no repeating (4444)
1128 * or ordered (1234, 4321, 2468) sequences. Note that quality
1129 * constants are ordered so that higher values are more restrictive.
1130 */
1131 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1132
1133 /**
1134 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001135 * password containing at least alphabetic (or other symbol) characters.
1136 * Note that quality constants are ordered so that higher values are more
1137 * restrictive.
1138 */
1139 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001140
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001141 /**
1142 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001143 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001144 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001145 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001146 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001147 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001148
Dianne Hackbornd6847842010-01-12 18:14:19 -08001149 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001150 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001151 * password containing at least a letter, a numerical digit and a special
1152 * symbol, by default. With this password quality, passwords can be
1153 * restricted to contain various sets of characters, like at least an
1154 * uppercase letter, etc. These are specified using various methods,
1155 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1156 * that quality constants are ordered so that higher values are more
1157 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001158 */
1159 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1160
1161 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001162 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1163 * modify password. In case this password quality is set, the password is
1164 * managed by a profile owner. The profile owner can set any password,
1165 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1166 * that quality constants are ordered so that higher values are more
1167 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1168 * the highest.
1169 * @hide
1170 */
1171 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1172
1173 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001174 * Called by an application that is administering the device to set the
1175 * password restrictions it is imposing. After setting this, the user
1176 * will not be able to enter a new password that is not at least as
1177 * restrictive as what has been set. Note that the current password
1178 * will remain until the user has set a new one, so the change does not
1179 * take place immediately. To prompt the user for a new password, use
1180 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001181 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001182 * <p>Quality constants are ordered so that higher values are more restrictive;
1183 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001184 * the user's preference, and any other considerations) is the one that
1185 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001186 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001187 * <p>The calling device admin must have requested
1188 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1189 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001190 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001191 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001192 * @param quality The new desired quality. One of
1193 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001194 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1195 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1196 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001197 */
Robin Lee25e26452015-06-02 09:56:29 -07001198 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001199 if (mService != null) {
1200 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001201 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001202 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001203 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001204 }
1205 }
1206 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001207
Dianne Hackbornd6847842010-01-12 18:14:19 -08001208 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001209 * Retrieve the current minimum password quality for all admins of this user
1210 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001211 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001212 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001213 */
Robin Lee25e26452015-06-02 09:56:29 -07001214 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001215 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001216 }
1217
1218 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001219 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001220 if (mService != null) {
1221 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001222 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001223 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001224 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001225 }
1226 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001227 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001228 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001229
Dianne Hackbornd6847842010-01-12 18:14:19 -08001230 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001231 * Called by an application that is administering the device to set the
1232 * minimum allowed password length. After setting this, the user
1233 * will not be able to enter a new password that is not at least as
1234 * restrictive as what has been set. Note that the current password
1235 * will remain until the user has set a new one, so the change does not
1236 * take place immediately. To prompt the user for a new password, use
1237 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1238 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001239 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1240 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1241 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001242 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001243 * <p>The calling device admin must have requested
1244 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1245 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001246 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001248 * @param length The new desired minimum password length. A value of 0
1249 * means there is no restriction.
1250 */
Robin Lee25e26452015-06-02 09:56:29 -07001251 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001252 if (mService != null) {
1253 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001254 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001256 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001257 }
1258 }
1259 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001260
Dianne Hackbornd6847842010-01-12 18:14:19 -08001261 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001262 * Retrieve the current minimum password length for all admins of this
1263 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001264 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001265 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001266 */
Robin Lee25e26452015-06-02 09:56:29 -07001267 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001268 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001269 }
1270
1271 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001272 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001273 if (mService != null) {
1274 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001275 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001276 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001277 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001278 }
1279 }
1280 return 0;
1281 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001282
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001283 /**
1284 * Called by an application that is administering the device to set the
1285 * minimum number of upper case letters required in the password. After
1286 * setting this, the user will not be able to enter a new password that is
1287 * not at least as restrictive as what has been set. Note that the current
1288 * password will remain until the user has set a new one, so the change does
1289 * not take place immediately. To prompt the user for a new password, use
1290 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1291 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001292 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1293 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001294 * <p>
1295 * The calling device admin must have requested
1296 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1297 * this method; if it has not, a security exception will be thrown.
1298 *
1299 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1300 * with.
1301 * @param length The new desired minimum number of upper case letters
1302 * required in the password. A value of 0 means there is no
1303 * restriction.
1304 */
Robin Lee25e26452015-06-02 09:56:29 -07001305 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001306 if (mService != null) {
1307 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001308 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001309 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001310 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001311 }
1312 }
1313 }
1314
1315 /**
1316 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001317 * password for all admins of this user and its profiles or a particular one.
1318 * This is the same value as set by
1319 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001320 * and only applies when the password quality is
1321 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001322 *
Robin Lee25e26452015-06-02 09:56:29 -07001323 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001324 * aggregate all admins.
1325 * @return The minimum number of upper case letters required in the
1326 * password.
1327 */
Robin Lee25e26452015-06-02 09:56:29 -07001328 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001329 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001330 }
1331
1332 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001333 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001334 if (mService != null) {
1335 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001336 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001337 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001338 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001339 }
1340 }
1341 return 0;
1342 }
1343
1344 /**
1345 * Called by an application that is administering the device to set the
1346 * minimum number of lower case letters required in the password. After
1347 * setting this, the user will not be able to enter a new password that is
1348 * not at least as restrictive as what has been set. Note that the current
1349 * password will remain until the user has set a new one, so the change does
1350 * not take place immediately. To prompt the user for a new password, use
1351 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1352 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001353 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1354 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001355 * <p>
1356 * The calling device admin must have requested
1357 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1358 * this method; if it has not, a security exception will be thrown.
1359 *
1360 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1361 * with.
1362 * @param length The new desired minimum number of lower case letters
1363 * required in the password. A value of 0 means there is no
1364 * restriction.
1365 */
Robin Lee25e26452015-06-02 09:56:29 -07001366 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001367 if (mService != null) {
1368 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001369 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001370 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001371 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001372 }
1373 }
1374 }
1375
1376 /**
1377 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001378 * password for all admins of this user and its profiles or a particular one.
1379 * This is the same value as set by
1380 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001381 * and only applies when the password quality is
1382 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001383 *
Robin Lee25e26452015-06-02 09:56:29 -07001384 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001385 * aggregate all admins.
1386 * @return The minimum number of lower case letters required in the
1387 * password.
1388 */
Robin Lee25e26452015-06-02 09:56:29 -07001389 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001390 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001391 }
1392
1393 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001394 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001395 if (mService != null) {
1396 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001397 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001398 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001399 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001400 }
1401 }
1402 return 0;
1403 }
1404
1405 /**
1406 * Called by an application that is administering the device to set the
1407 * minimum number of letters required in the password. After setting this,
1408 * the user will not be able to enter a new password that is not at least as
1409 * restrictive as what has been set. Note that the current password will
1410 * remain until the user has set a new one, so the change does not take
1411 * place immediately. To prompt the user for a new password, use
1412 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1413 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001414 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1415 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001416 * <p>
1417 * The calling device admin must have requested
1418 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1419 * this method; if it has not, a security exception will be thrown.
1420 *
1421 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1422 * with.
1423 * @param length The new desired minimum number of letters required in the
1424 * password. A value of 0 means there is no restriction.
1425 */
Robin Lee25e26452015-06-02 09:56:29 -07001426 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001427 if (mService != null) {
1428 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001429 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001430 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001431 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001432 }
1433 }
1434 }
1435
1436 /**
1437 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001438 * admins or a particular one. This is the same value as
1439 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1440 * and only applies when the password quality is
1441 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001442 *
Robin Lee25e26452015-06-02 09:56:29 -07001443 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001444 * aggregate all admins.
1445 * @return The minimum number of letters required in the password.
1446 */
Robin Lee25e26452015-06-02 09:56:29 -07001447 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001448 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001449 }
1450
1451 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001452 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001453 if (mService != null) {
1454 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001455 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001456 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001457 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001458 }
1459 }
1460 return 0;
1461 }
1462
1463 /**
1464 * Called by an application that is administering the device to set the
1465 * minimum number of numerical digits required in the password. After
1466 * setting this, the user will not be able to enter a new password that is
1467 * not at least as restrictive as what has been set. Note that the current
1468 * password will remain until the user has set a new one, so the change does
1469 * not take place immediately. To prompt the user for a new password, use
1470 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1471 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001472 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1473 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001474 * <p>
1475 * The calling device admin must have requested
1476 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1477 * this method; if it has not, a security exception will be thrown.
1478 *
1479 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1480 * with.
1481 * @param length The new desired minimum number of numerical digits required
1482 * in the password. A value of 0 means there is no restriction.
1483 */
Robin Lee25e26452015-06-02 09:56:29 -07001484 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001485 if (mService != null) {
1486 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001487 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001488 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001489 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 }
1491 }
1492 }
1493
1494 /**
1495 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001496 * for all admins of this user and its profiles or a particular one.
1497 * This is the same value as set by
1498 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001499 * and only applies when the password quality is
1500 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 *
Robin Lee25e26452015-06-02 09:56:29 -07001502 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001503 * aggregate all admins.
1504 * @return The minimum number of numerical digits required in the password.
1505 */
Robin Lee25e26452015-06-02 09:56:29 -07001506 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001507 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001508 }
1509
1510 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001511 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001512 if (mService != null) {
1513 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001514 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001515 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001516 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001517 }
1518 }
1519 return 0;
1520 }
1521
1522 /**
1523 * Called by an application that is administering the device to set the
1524 * minimum number of symbols required in the password. After setting this,
1525 * the user will not be able to enter a new password that is not at least as
1526 * restrictive as what has been set. Note that the current password will
1527 * remain until the user has set a new one, so the change does not take
1528 * place immediately. To prompt the user for a new password, use
1529 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1530 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001531 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1532 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001533 * <p>
1534 * The calling device admin must have requested
1535 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1536 * this method; if it has not, a security exception will be thrown.
1537 *
1538 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1539 * with.
1540 * @param length The new desired minimum number of symbols required in the
1541 * password. A value of 0 means there is no restriction.
1542 */
Robin Lee25e26452015-06-02 09:56:29 -07001543 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001544 if (mService != null) {
1545 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001546 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001547 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001548 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001549 }
1550 }
1551 }
1552
1553 /**
1554 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001555 * admins or a particular one. This is the same value as
1556 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1557 * and only applies when the password quality is
1558 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001559 *
Robin Lee25e26452015-06-02 09:56:29 -07001560 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001561 * aggregate all admins.
1562 * @return The minimum number of symbols required in the password.
1563 */
Robin Lee25e26452015-06-02 09:56:29 -07001564 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001565 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001566 }
1567
1568 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001569 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001570 if (mService != null) {
1571 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001572 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001573 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001574 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001575 }
1576 }
1577 return 0;
1578 }
1579
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001580 /**
1581 * Called by an application that is administering the device to set the
1582 * minimum number of non-letter characters (numerical digits or symbols)
1583 * required in the password. After setting this, the user will not be able
1584 * to enter a new password that is not at least as restrictive as what has
1585 * been set. Note that the current password will remain until the user has
1586 * set a new one, so the change does not take place immediately. To prompt
1587 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1588 * setting this value. This constraint is only imposed if the administrator
1589 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1590 * {@link #setPasswordQuality}. The default value is 0.
1591 * <p>
1592 * The calling device admin must have requested
1593 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1594 * this method; if it has not, a security exception will be thrown.
1595 *
1596 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1597 * with.
1598 * @param length The new desired minimum number of letters required in the
1599 * password. A value of 0 means there is no restriction.
1600 */
Robin Lee25e26452015-06-02 09:56:29 -07001601 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001602 if (mService != null) {
1603 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001604 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001605 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001606 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001607 }
1608 }
1609 }
1610
1611 /**
1612 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001613 * password for all admins of this user and its profiles or a particular one.
1614 * This is the same value as set by
1615 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001616 * and only applies when the password quality is
1617 * {@link #PASSWORD_QUALITY_COMPLEX}.
1618 *
Robin Lee25e26452015-06-02 09:56:29 -07001619 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001620 * aggregate all admins.
1621 * @return The minimum number of letters required in the password.
1622 */
Robin Lee25e26452015-06-02 09:56:29 -07001623 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001624 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001625 }
1626
1627 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001628 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001629 if (mService != null) {
1630 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001631 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001632 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001633 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001634 }
1635 }
1636 return 0;
1637 }
1638
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001639 /**
1640 * Called by an application that is administering the device to set the length
1641 * of the password history. After setting this, the user will not be able to
1642 * enter a new password that is the same as any password in the history. Note
1643 * that the current password will remain until the user has set a new one, so
1644 * the change does not take place immediately. To prompt the user for a new
1645 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1646 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001647 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1648 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1649 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650 *
1651 * <p>
1652 * The calling device admin must have requested
1653 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1654 * method; if it has not, a security exception will be thrown.
1655 *
1656 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1657 * with.
1658 * @param length The new desired length of password history. A value of 0
1659 * means there is no restriction.
1660 */
Robin Lee25e26452015-06-02 09:56:29 -07001661 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001662 if (mService != null) {
1663 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001664 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001665 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001666 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001667 }
1668 }
1669 }
1670
1671 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001672 * Called by a device admin to set the password expiration timeout. Calling this method
1673 * will restart the countdown for password expiration for the given admin, as will changing
1674 * the device password (for all admins).
1675 *
1676 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1677 * For example, to have the password expire 5 days from now, timeout would be
1678 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1679 *
1680 * <p>To disable password expiration, a value of 0 may be used for timeout.
1681 *
Jim Millera4e28d12010-11-08 16:15:47 -08001682 * <p>The calling device admin must have requested
1683 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1684 * method; if it has not, a security exception will be thrown.
1685 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001686 * <p> Note that setting the password will automatically reset the expiration time for all
1687 * active admins. Active admins do not need to explicitly call this method in that case.
1688 *
Jim Millera4e28d12010-11-08 16:15:47 -08001689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1690 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1691 * means there is no restriction (unlimited).
1692 */
Robin Lee25e26452015-06-02 09:56:29 -07001693 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001694 if (mService != null) {
1695 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001696 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001697 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001698 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001699 }
1700 }
1701 }
1702
1703 /**
Jim Miller6b857682011-02-16 16:27:41 -08001704 * Get the password expiration timeout for the given admin. The expiration timeout is the
1705 * recurring expiration timeout provided in the call to
1706 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001707 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001708 *
Robin Lee25e26452015-06-02 09:56:29 -07001709 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001710 * @return The timeout for the given admin or the minimum of all timeouts
1711 */
Robin Lee25e26452015-06-02 09:56:29 -07001712 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001713 if (mService != null) {
1714 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001715 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001716 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001717 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001718 }
1719 }
1720 return 0;
1721 }
1722
1723 /**
1724 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001725 * all admins of this user and its profiles if admin is null. If the password is
1726 * expired, this will return the time since the password expired as a negative number.
1727 * If admin is null, then a composite of all expiration timeouts is returned
1728 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001729 *
Robin Lee25e26452015-06-02 09:56:29 -07001730 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001731 * @return The password expiration time, in ms.
1732 */
Robin Lee25e26452015-06-02 09:56:29 -07001733 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001734 if (mService != null) {
1735 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001736 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001737 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001738 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001739 }
1740 }
1741 return 0;
1742 }
1743
1744 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001745 * Retrieve the current password history length for all admins of this
1746 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001747 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001748 * all admins.
1749 * @return The length of the password history
1750 */
Robin Lee25e26452015-06-02 09:56:29 -07001751 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001752 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001753 }
1754
1755 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001756 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001757 if (mService != null) {
1758 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001759 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001760 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001761 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001762 }
1763 }
1764 return 0;
1765 }
1766
Dianne Hackbornd6847842010-01-12 18:14:19 -08001767 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001768 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001769 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001770 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001771 * @return Returns the maximum length that the user can enter.
1772 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001773 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001774 // Kind-of arbitrary.
1775 return 16;
1776 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001777
Dianne Hackborn254cb442010-01-27 19:23:59 -08001778 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001779 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001780 * to meet the policy requirements (quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001781 * requested by the admins of this user and its profiles that don't have a separate challenge.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001782 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001783 * <p>The calling device admin must have requested
1784 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1785 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001786 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001787 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001788 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001789 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001790 if (mService != null) {
1791 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001792 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001793 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001794 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001795 }
1796 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001797 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001798 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001799
Dianne Hackbornd6847842010-01-12 18:14:19 -08001800 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001801 * Determine whether the current profile password the user has set is sufficient
1802 * to meet the policy requirements (quality, minimum length) that have been
1803 * requested by the admins of the parent user and its profiles.
1804 *
1805 * @param userHandle the userId of the profile to check the password for.
1806 * @return Returns true if the password would meet the current requirements, else false.
1807 * @hide
1808 */
1809 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1810 if (mService != null) {
1811 try {
1812 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1813 } catch (RemoteException e) {
1814 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1815 }
1816 }
1817 return false;
1818 }
1819
1820 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001821 * Retrieve the number of times the user has failed at entering a
1822 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001823 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001824 * <p>The calling device admin must have requested
1825 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1826 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001827 */
1828 public int getCurrentFailedPasswordAttempts() {
1829 if (mService != null) {
1830 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001831 return mService.getCurrentFailedPasswordAttempts(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001832 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001833 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001834 }
1835 }
1836 return -1;
1837 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001838
1839 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001840 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001841 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001842 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001843 * @hide
1844 */
1845 public boolean getDoNotAskCredentialsOnBoot() {
1846 if (mService != null) {
1847 try {
1848 return mService.getDoNotAskCredentialsOnBoot();
1849 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001850 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001851 }
1852 }
1853 return false;
1854 }
1855
1856 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001857 * Setting this to a value greater than zero enables a built-in policy
1858 * that will perform a device wipe after too many incorrect
1859 * device-unlock passwords have been entered. This built-in policy combines
1860 * watching for failed passwords and wiping the device, and requires
1861 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001862 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001863 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001864 * <p>To implement any other policy (e.g. wiping data for a particular
1865 * application only, erasing or revoking credentials, or reporting the
1866 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001867 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001868 * instead. Do not use this API, because if the maximum count is reached,
1869 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001870 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001872 * @param num The number of failed password attempts at which point the
1873 * device will wipe its data.
1874 */
Robin Lee25e26452015-06-02 09:56:29 -07001875 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001876 if (mService != null) {
1877 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001878 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001879 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001880 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001881 }
1882 }
1883 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001884
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001885 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001886 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001887 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001888 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001889 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001890 * all admins.
1891 */
Robin Lee25e26452015-06-02 09:56:29 -07001892 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001893 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001894 }
1895
1896 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001897 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001898 if (mService != null) {
1899 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001900 return mService.getMaximumFailedPasswordsForWipe(
1901 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001902 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001903 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001904 }
1905 }
1906 return 0;
1907 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001908
Dianne Hackborn254cb442010-01-27 19:23:59 -08001909 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001910 * Returns the profile with the smallest maximum failed passwords for wipe,
1911 * for the given user. So for primary user, it might return the primary or
1912 * a managed profile. For a secondary user, it would be the same as the
1913 * user passed in.
1914 * @hide Used only by Keyguard
1915 */
1916 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1917 if (mService != null) {
1918 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001919 return mService.getProfileWithMinimumFailedPasswordsForWipe(
1920 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001921 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001922 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001923 }
1924 }
1925 return UserHandle.USER_NULL;
1926 }
1927
1928 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001929 * Flag for {@link #resetPassword}: don't allow other admins to change
1930 * the password again until the user has entered it.
1931 */
1932 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001933
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001934 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001935 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1936 * If the flag is set, the device can be booted without asking for user password.
1937 * The absence of this flag does not change the current boot requirements. This flag
1938 * can be set by the device owner only. If the app is not the device owner, the flag
1939 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1940 * device to factory defaults.
1941 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001942 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001943
1944 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001945 * Force a new device unlock password (the password needed to access the
1946 * entire device, not for individual accounts) on the user. This takes
1947 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001948 *
1949 * <p>Calling this from a managed profile that shares the password with the owner profile
1950 * will throw a security exception.
1951 *
1952 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1953 * device admins that are not device owner and not profile owner.
1954 * The password can now only be changed if there is currently no password set. Device owner
1955 * and profile owner can still do this.</em>
1956 *
1957 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001958 * current password quality and length constraints as returned by
1959 * {@link #getPasswordQuality(ComponentName)} and
1960 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1961 * these constraints, then it will be rejected and false returned. Note
1962 * that the password may be a stronger quality (containing alphanumeric
1963 * characters when the requested quality is only numeric), in which case
1964 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001965 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001966 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001967 * pattern or password if the current password constraints allow it. <em>Note: This will not
1968 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1969 * device owner and not profile owner. Once set, the password cannot be changed to null or
1970 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001971 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001972 * <p>The calling device admin must have requested
1973 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1974 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001975 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001976 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001977 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001978 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001979 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08001980 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001981 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001982 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001983 if (mParentInstance) {
1984 throw new SecurityException("Reset password does not work across profiles.");
1985 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001986 if (mService != null) {
1987 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08001988 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001989 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001990 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001991 }
1992 }
1993 return false;
1994 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001995
Dianne Hackbornd6847842010-01-12 18:14:19 -08001996 /**
1997 * Called by an application that is administering the device to set the
1998 * maximum time for user activity until the device will lock. This limits
1999 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002000 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002001 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002002 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002003 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002004 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002006 * @param timeMs The new desired maximum time to lock in milliseconds.
2007 * A value of 0 means there is no restriction.
2008 */
Robin Lee25e26452015-06-02 09:56:29 -07002009 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002010 if (mService != null) {
2011 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002012 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002013 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002014 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002015 }
2016 }
2017 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018
Dianne Hackbornd6847842010-01-12 18:14:19 -08002019 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01002020 * Retrieve the current maximum time to unlock for all admins of this user
2021 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07002022 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002023 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002024 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002025 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002026 */
Robin Lee25e26452015-06-02 09:56:29 -07002027 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002028 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002029 }
2030
2031 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002032 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002033 if (mService != null) {
2034 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002035 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002036 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002037 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002038 }
2039 }
2040 return 0;
2041 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002042
Dianne Hackbornd6847842010-01-12 18:14:19 -08002043 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002044 * Make the device lock immediately, as if the lock screen timeout has
2045 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002046 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002047 * <p>The calling device admin must have requested
2048 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2049 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002050 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002051 public void lockNow() {
2052 if (mService != null) {
2053 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002054 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002055 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002056 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002057 }
2058 }
2059 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002060
Dianne Hackbornd6847842010-01-12 18:14:19 -08002061 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002062 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002063 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002064 */
2065 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2066
2067 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002068 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2069 * data.
2070 *
Paul Crowley2934b262014-12-02 11:21:13 +00002071 * <p>This flag may only be set by device owner admins; if it is set by
2072 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002073 */
2074 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2075
2076 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002077 * Ask the user data be wiped. Wiping the primary user will cause the
2078 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002079 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002080 * <p>The calling device admin must have requested
2081 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2082 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002083 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002084 * @param flags Bit mask of additional options: currently supported flags
2085 * are {@link #WIPE_EXTERNAL_STORAGE} and
2086 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002087 */
2088 public void wipeData(int flags) {
2089 if (mService != null) {
2090 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002091 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002092 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002093 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002094 }
2095 }
2096 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002097
Dianne Hackbornd6847842010-01-12 18:14:19 -08002098 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002099 * Called by an application that is administering the device to set the
2100 * global proxy and exclusion list.
2101 * <p>
2102 * The calling device admin must have requested
2103 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2104 * this method; if it has not, a security exception will be thrown.
2105 * Only the first device admin can set the proxy. If a second admin attempts
2106 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002107 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002108 * be returned.
2109 * The method can be called repeatedly by the device admin alrady setting the
2110 * proxy to update the proxy and exclusion list.
2111 *
Robin Lee25e26452015-06-02 09:56:29 -07002112 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002113 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2114 * Pass Proxy.NO_PROXY to reset the proxy.
2115 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002116 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2117 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002118 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002119 */
Robin Lee25e26452015-06-02 09:56:29 -07002120 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002121 List<String> exclusionList ) {
2122 if (proxySpec == null) {
2123 throw new NullPointerException();
2124 }
2125 if (mService != null) {
2126 try {
2127 String hostSpec;
2128 String exclSpec;
2129 if (proxySpec.equals(Proxy.NO_PROXY)) {
2130 hostSpec = null;
2131 exclSpec = null;
2132 } else {
2133 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2134 throw new IllegalArgumentException();
2135 }
2136 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2137 String hostName = sa.getHostName();
2138 int port = sa.getPort();
2139 StringBuilder hostBuilder = new StringBuilder();
2140 hostSpec = hostBuilder.append(hostName)
2141 .append(":").append(Integer.toString(port)).toString();
2142 if (exclusionList == null) {
2143 exclSpec = "";
2144 } else {
2145 StringBuilder listBuilder = new StringBuilder();
2146 boolean firstDomain = true;
2147 for (String exclDomain : exclusionList) {
2148 if (!firstDomain) {
2149 listBuilder = listBuilder.append(",");
2150 } else {
2151 firstDomain = false;
2152 }
2153 listBuilder = listBuilder.append(exclDomain.trim());
2154 }
2155 exclSpec = listBuilder.toString();
2156 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002157 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2158 != android.net.Proxy.PROXY_VALID)
2159 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002160 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002161 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002162 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002163 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002164 }
2165 }
2166 return null;
2167 }
2168
2169 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002170 * Set a network-independent global HTTP proxy. This is not normally what you want
2171 * for typical HTTP proxies - they are generally network dependent. However if you're
2172 * doing something unusual like general internal filtering this may be useful. On
2173 * a private network where the proxy is not accessible, you may break HTTP using this.
2174 *
2175 * <p>This method requires the caller to be the device owner.
2176 *
2177 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2178 * @see ProxyInfo
2179 *
2180 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2181 * with.
2182 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2183 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2184 */
Robin Lee25e26452015-06-02 09:56:29 -07002185 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2186 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002187 if (mService != null) {
2188 try {
2189 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2190 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002191 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002192 }
2193 }
2194 }
2195
2196 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002197 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002198 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2199 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002200 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002201 */
2202 public ComponentName getGlobalProxyAdmin() {
2203 if (mService != null) {
2204 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002205 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002206 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002207 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002208 }
2209 }
2210 return null;
2211 }
2212
2213 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002214 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002215 * indicating that encryption is not supported.
2216 */
2217 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2218
2219 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002220 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002221 * indicating that encryption is supported, but is not currently active.
2222 */
2223 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2224
2225 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002226 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002227 * indicating that encryption is not currently active, but is currently
2228 * being activated. This is only reported by devices that support
2229 * encryption of data and only when the storage is currently
2230 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2231 * to become encrypted will never return this value.
2232 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002233 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002234
2235 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002236 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002237 * indicating that encryption is active.
2238 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002239 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002240
2241 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002242 * Result code for {@link #getStorageEncryptionStatus}:
2243 * indicating that encryption is active, but an encryption key has not
2244 * been set by the user.
2245 */
2246 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2247
2248 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002249 * Activity action: begin the process of encrypting data on the device. This activity should
2250 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2251 * After resuming from this activity, use {@link #getStorageEncryption}
2252 * to check encryption status. However, on some devices this activity may never return, as
2253 * it may trigger a reboot and in some cases a complete data wipe of the device.
2254 */
2255 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2256 public static final String ACTION_START_ENCRYPTION
2257 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002258 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002259 * Widgets are enabled in keyguard
2260 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002261 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002262
2263 /**
Jim Miller50e62182014-04-23 17:25:00 -07002264 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002265 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002266 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2267
2268 /**
2269 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2270 */
2271 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2272
2273 /**
Jim Miller50e62182014-04-23 17:25:00 -07002274 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2275 */
2276 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2277
2278 /**
2279 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2280 */
2281 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2282
2283 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002284 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002285 * (e.g. PIN/Pattern/Password).
2286 */
2287 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2288
2289 /**
Jim Miller06e34502014-07-17 14:46:05 -07002290 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2291 */
2292 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2293
2294 /**
Jim Miller35207742012-11-02 15:33:20 -07002295 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002296 */
2297 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002298
2299 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002300 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002301 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002302 *
2303 * <p>When multiple device administrators attempt to control device
2304 * encryption, the most secure, supported setting will always be
2305 * used. If any device administrator requests device encryption,
2306 * it will be enabled; Conversely, if a device administrator
2307 * attempts to disable device encryption while another
2308 * device administrator has enabled it, the call to disable will
2309 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2310 *
2311 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002312 * written to other storage areas may or may not be encrypted, and this policy does not require
2313 * or control the encryption of any other storage areas.
2314 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2315 * {@code true}, then the directory returned by
2316 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2317 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002318 *
2319 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2320 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2321 * the encryption key may not be fully secured. For maximum security, the administrator should
2322 * also require (and check for) a pattern, PIN, or password.
2323 *
2324 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2325 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002326 * @return the new request status (for all active admins) - will be one of
2327 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2328 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2329 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002330 */
Robin Lee25e26452015-06-02 09:56:29 -07002331 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002332 if (mService != null) {
2333 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002334 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002335 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002336 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002337 }
2338 }
2339 return ENCRYPTION_STATUS_UNSUPPORTED;
2340 }
2341
2342 /**
2343 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002344 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002345 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2347 * this will return the requested encryption setting as an aggregate of all active
2348 * administrators.
2349 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002350 */
Robin Lee25e26452015-06-02 09:56:29 -07002351 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002352 if (mService != null) {
2353 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002354 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002355 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002356 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002357 }
2358 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002359 return false;
2360 }
2361
2362 /**
2363 * Called by an application that is administering the device to
2364 * determine the current encryption status of the device.
2365 *
2366 * Depending on the returned status code, the caller may proceed in different
2367 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2368 * storage system does not support encryption. If the
2369 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2370 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002371 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2372 * storage system has enabled encryption but no password is set so further action
2373 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002374 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2375 *
Robin Lee7e678712014-07-24 16:41:31 +01002376 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002377 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002378 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2379 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002380 */
2381 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002382 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002383 }
2384
2385 /** @hide per-user version */
2386 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002387 if (mService != null) {
2388 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002389 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002390 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002391 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002392 }
2393 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002394 return ENCRYPTION_STATUS_UNSUPPORTED;
2395 }
2396
2397 /**
Robin Lee7e678712014-07-24 16:41:31 +01002398 * Installs the given certificate as a user CA.
2399 *
Robin Lee25e26452015-06-02 09:56:29 -07002400 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2401 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002402 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002403 *
2404 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002405 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002406 */
Robin Lee25e26452015-06-02 09:56:29 -07002407 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002408 if (mService != null) {
2409 try {
Robin Lee7e678712014-07-24 16:41:31 +01002410 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002411 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002412 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002413 }
2414 }
2415 return false;
2416 }
2417
2418 /**
Robin Lee7e678712014-07-24 16:41:31 +01002419 * Uninstalls the given certificate from trusted user CAs, if present.
2420 *
Robin Lee25e26452015-06-02 09:56:29 -07002421 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2422 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002423 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002424 */
Robin Lee25e26452015-06-02 09:56:29 -07002425 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002426 if (mService != null) {
2427 try {
Robin Lee306fe082014-06-19 14:04:24 +00002428 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002429 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002430 } catch (CertificateException e) {
2431 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002432 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002433 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002434 }
2435 }
2436 }
2437
2438 /**
Robin Lee7e678712014-07-24 16:41:31 +01002439 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2440 * If a user has installed any certificates by other means than device policy these will be
2441 * included too.
2442 *
Robin Lee25e26452015-06-02 09:56:29 -07002443 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2444 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002445 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002446 */
Robin Lee25e26452015-06-02 09:56:29 -07002447 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002448 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002449 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002450 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002451 mService.enforceCanManageCaCerts(admin);
2452 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2453 for (String alias : certStore.userAliases()) {
2454 try {
2455 certs.add(certStore.getCertificate(alias).getEncoded());
2456 } catch (CertificateException ce) {
2457 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2458 }
2459 }
2460 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002461 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002462 }
2463 }
2464 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002465 }
2466
2467 /**
Robin Lee7e678712014-07-24 16:41:31 +01002468 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2469 * means other than device policy will also be removed, except for system CA certificates.
2470 *
Robin Lee25e26452015-06-02 09:56:29 -07002471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2472 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002473 */
Robin Lee25e26452015-06-02 09:56:29 -07002474 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002475 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002476 try {
2477 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2478 .toArray(new String[0]));
2479 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002480 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002481 }
2482 }
2483 }
2484
2485 /**
2486 * Returns whether this certificate is installed as a trusted CA.
2487 *
Robin Lee25e26452015-06-02 09:56:29 -07002488 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2489 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002490 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002491 */
Robin Lee25e26452015-06-02 09:56:29 -07002492 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002493 if (mService != null) {
2494 try {
2495 mService.enforceCanManageCaCerts(admin);
2496 return getCaCertAlias(certBuffer) != null;
2497 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002498 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002499 } catch (CertificateException ce) {
2500 Log.w(TAG, "Could not parse certificate", ce);
2501 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002502 }
2503 return false;
2504 }
2505
2506 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002507 * Called by a device or profile owner to install a certificate and private key pair. The
2508 * keypair will be visible to all apps within the profile.
2509 *
Robin Lee25e26452015-06-02 09:56:29 -07002510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2511 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002512 * @param privKey The private key to install.
2513 * @param cert The certificate to install.
2514 * @param alias The private key alias under which to install the certificate. If a certificate
2515 * with that alias already exists, it will be overwritten.
2516 * @return {@code true} if the keys were installed, {@code false} otherwise.
2517 */
Robin Leefbc65642015-08-03 16:21:22 +01002518 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2519 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002520 try {
2521 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002522 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2523 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002524 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002525 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002526 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002527 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2528 Log.w(TAG, "Failed to obtain private key material", e);
2529 } catch (CertificateException | IOException e) {
2530 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002531 }
2532 return false;
2533 }
2534
2535 /**
Robin Leefbc65642015-08-03 16:21:22 +01002536 * Called by a device or profile owner to remove all user credentials installed under a given
2537 * alias.
2538 *
2539 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2540 * {@code null} if calling from a delegated certificate installer.
2541 * @param alias The private key alias under which the certificate is installed.
2542 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2543 */
2544 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2545 try {
2546 return mService.removeKeyPair(admin, alias);
2547 } catch (RemoteException e) {
2548 Log.w(TAG, "Failed talking with device policy service", e);
2549 }
2550 return false;
2551 }
2552
2553 /**
Robin Lee25e26452015-06-02 09:56:29 -07002554 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002555 * doesn't exist.
2556 */
2557 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2558 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2559 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2560 new ByteArrayInputStream(certBuffer));
2561 return new TrustedCertificateStore().getCertificateAlias(cert);
2562 }
2563
2564 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002565 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002566 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002567 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002568 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002569 * <p>
2570 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2571 * it is later cleared by calling this method with a null value or uninstallling the certificate
2572 * installer.
2573 *
Robin Lee25e26452015-06-02 09:56:29 -07002574 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002575 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002576 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002577 */
Robin Lee25e26452015-06-02 09:56:29 -07002578 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2579 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002580 if (mService != null) {
2581 try {
Robin Lee25e26452015-06-02 09:56:29 -07002582 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002583 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002584 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002585 }
2586 }
2587 }
2588
2589 /**
2590 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002591 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002592 *
Robin Lee25e26452015-06-02 09:56:29 -07002593 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2594 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002595 * if none is set.
2596 */
Robin Lee25e26452015-06-02 09:56:29 -07002597 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002598 if (mService != null) {
2599 try {
Robin Lee25e26452015-06-02 09:56:29 -07002600 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002601 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002602 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002603 }
2604 }
2605 return null;
2606 }
2607
2608 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002609 * Called by a device or profile owner to configure an always-on VPN connection through a
2610 * specific application for the current user.
2611 * This connection is automatically granted and persisted after a reboot.
2612 *
2613 * <p>The designated package should declare a {@link android.net.VpnService} in its
2614 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2615 * otherwise the call will fail.
2616 *
2617 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2618 * to remove an existing always-on VPN configuration.
2619 *
2620 * @return {@code true} if the package is set as always-on VPN controller;
2621 * {@code false} otherwise.
2622 */
2623 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2624 @Nullable String vpnPackage) {
2625 if (mService != null) {
2626 try {
2627 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2628 } catch (RemoteException e) {
2629 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2630 }
2631 }
2632 return false;
2633 }
2634
2635 /**
2636 * Called by a device or profile owner to read the name of the package administering an
2637 * always-on VPN connection for the current user.
2638 * If there is no such package, or the always-on VPN is provided by the system instead
2639 * of by an application, {@code null} will be returned.
2640 *
2641 * @return Package name of VPN controller responsible for always-on VPN,
2642 * or {@code null} if none is set.
2643 */
2644 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2645 if (mService != null) {
2646 try {
2647 return mService.getAlwaysOnVpnPackage(admin);
2648 } catch (RemoteException e) {
2649 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2650 }
2651 }
2652 return null;
2653 }
2654
2655 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002656 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002657 * on the device, for this user. After setting this, no applications running as this user
2658 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002659 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002660 * <p>If the caller is device owner, then the restriction will be applied to all users.
2661 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002662 * <p>The calling device admin must have requested
2663 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2664 * this method; if it has not, a security exception will be thrown.
2665 *
2666 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2667 * @param disabled Whether or not the camera should be disabled.
2668 */
Robin Lee25e26452015-06-02 09:56:29 -07002669 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002670 if (mService != null) {
2671 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002672 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002673 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002674 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002675 }
2676 }
2677 }
2678
2679 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002680 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002681 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002682 * @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 -07002683 * have disabled the camera
2684 */
Robin Lee25e26452015-06-02 09:56:29 -07002685 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002686 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002687 }
2688
2689 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002690 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002691 if (mService != null) {
2692 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002693 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002694 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002695 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002696 }
2697 }
2698 return false;
2699 }
2700
2701 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002702 * Called by a device owner to request a bugreport.
2703 *
2704 * <p>There must be only one user on the device, managed by the device owner.
2705 * Otherwise a security exception will be thrown.
2706 *
2707 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2708 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2709 * if it wasn't triggered because a previous bugreport operation is still active
2710 * (either the bugreport is still running or waiting for the user to share or decline)
2711 */
2712 public boolean requestBugreport(@NonNull ComponentName admin) {
2713 if (mService != null) {
2714 try {
2715 return mService.requestBugreport(admin);
2716 } catch (RemoteException e) {
2717 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2718 }
2719 }
2720 return false;
2721 }
2722
2723 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002724 * Determine whether or not creating a guest user has been disabled for the device
2725 *
2726 * @hide
2727 */
2728 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2729 // Currently guest users can always be created if multi-user is enabled
2730 // TODO introduce a policy for guest user creation
2731 return false;
2732 }
2733
2734 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002735 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2736 * screen capture also prevents the content from being shown on display devices that do not have
2737 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2738 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002739 *
2740 * <p>The calling device admin must be a device or profile owner. If it is not, a
2741 * security exception will be thrown.
2742 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002743 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002744 * blocks assist requests for all activities of the relevant user.
2745 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002747 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002748 */
Robin Lee25e26452015-06-02 09:56:29 -07002749 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002750 if (mService != null) {
2751 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002752 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002753 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002754 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002755 }
2756 }
2757 }
2758
2759 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002760 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002761 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002762 * @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 +01002763 * have disabled screen capture.
2764 */
Robin Lee25e26452015-06-02 09:56:29 -07002765 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002766 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002767 }
2768
2769 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002770 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002771 if (mService != null) {
2772 try {
2773 return mService.getScreenCaptureDisabled(admin, userHandle);
2774 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002775 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002776 }
2777 }
2778 return false;
2779 }
2780
2781 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002782 * Called by a device owner to set whether auto time is required. If auto time is
2783 * required the user cannot set the date and time, but has to use network date and time.
2784 *
2785 * <p>Note: if auto time is required the user can still manually set the time zone.
2786 *
2787 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2788 * be thrown.
2789 *
2790 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2791 * @param required Whether auto time is set required or not.
2792 */
Robin Lee25e26452015-06-02 09:56:29 -07002793 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002794 if (mService != null) {
2795 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002796 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002797 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002798 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002799 }
2800 }
2801 }
2802
2803 /**
2804 * @return true if auto time is required.
2805 */
2806 public boolean getAutoTimeRequired() {
2807 if (mService != null) {
2808 try {
2809 return mService.getAutoTimeRequired();
2810 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002811 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002812 }
2813 }
2814 return false;
2815 }
2816
2817 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01002818 * Called by a device owner to set whether all users created on the device should be ephemeral.
2819 *
2820 * <p>The system user is exempt from this policy - it is never ephemeral.
2821 *
2822 * <p>The calling device admin must be the device owner. If it is not, a security exception will
2823 * be thrown.
2824 *
2825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2826 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
2827 * subsequently created users will be ephemeral.
2828 * @hide
2829 */
2830 public void setForceEphemeralUsers(
2831 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
2832 if (mService != null) {
2833 try {
2834 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
2835 } catch (RemoteException e) {
2836 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2837 }
2838 }
2839 }
2840
2841 /**
2842 * @return true if all users are created ephemeral.
2843 * @hide
2844 */
2845 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
2846 if (mService != null) {
2847 try {
2848 return mService.getForceEphemeralUsers(admin);
2849 } catch (RemoteException e) {
2850 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2851 }
2852 }
2853 return false;
2854 }
2855
2856 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002857 * Called by an application that is administering the device to disable keyguard customizations,
2858 * such as widgets. After setting this, keyguard features will be disabled according to the
2859 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002860 *
2861 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002862 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002863 * this method; if it has not, a security exception will be thrown.
2864 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002865 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002866 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002867 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002868 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002869 * <ul>
2870 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2871 * these will affect the profile's parent user.
2872 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2873 * generated by applications in the managed profile.
2874 * </ul>
2875 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2876 * can check which features have been disabled by calling
2877 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002878 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002879 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002880 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2881 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002882 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002883 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2884 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002885 */
Robin Lee25e26452015-06-02 09:56:29 -07002886 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002887 if (mService != null) {
2888 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002889 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002890 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002891 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002892 }
2893 }
2894 }
2895
2896 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002897 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002898 * admin, if specified, or all admins.
Esteban Talavera62399912016-01-11 15:37:55 +00002899 * @param admin The name of the admin component to check, or {@code null} to check whether any
2900 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002901 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2902 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002903 */
Robin Lee25e26452015-06-02 09:56:29 -07002904 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002905 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002906 }
2907
2908 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002909 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002910 if (mService != null) {
2911 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002912 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002913 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002914 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002915 }
2916 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002917 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002918 }
2919
2920 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002921 * @hide
2922 */
Robin Lee25e26452015-06-02 09:56:29 -07002923 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2924 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002925 if (mService != null) {
2926 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002927 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002928 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002929 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002930 }
2931 }
2932 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002933
Dianne Hackbornd6847842010-01-12 18:14:19 -08002934 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002935 * @hide
2936 */
Robin Lee25e26452015-06-02 09:56:29 -07002937 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002938 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002939 }
2940
2941 /**
Robin Lee25e26452015-06-02 09:56:29 -07002942 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002943 * @hide
2944 */
Robin Lee25e26452015-06-02 09:56:29 -07002945 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002946 ActivityInfo ai;
2947 try {
2948 ai = mContext.getPackageManager().getReceiverInfo(cn,
2949 PackageManager.GET_META_DATA);
2950 } catch (PackageManager.NameNotFoundException e) {
2951 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2952 return null;
2953 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002954
Dianne Hackbornd6847842010-01-12 18:14:19 -08002955 ResolveInfo ri = new ResolveInfo();
2956 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002957
Dianne Hackbornd6847842010-01-12 18:14:19 -08002958 try {
2959 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002960 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002961 Log.w(TAG, "Unable to parse device policy " + cn, e);
2962 return null;
2963 }
2964 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002965
Dianne Hackbornd6847842010-01-12 18:14:19 -08002966 /**
2967 * @hide
2968 */
Robin Lee25e26452015-06-02 09:56:29 -07002969 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002970 if (mService != null) {
2971 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002972 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002973 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002974 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002975 }
2976 }
2977 }
2978
2979 /**
2980 * @hide
2981 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002982 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002983 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002984 if (mService != null) {
2985 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002986 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002987 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002988 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002989 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002990 }
2991 }
2992 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002993
Dianne Hackbornd6847842010-01-12 18:14:19 -08002994 /**
2995 * @hide
2996 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002997 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002998 if (mService != null) {
2999 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003000 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003001 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003002 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003003 }
3004 }
3005 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003006
Dianne Hackbornd6847842010-01-12 18:14:19 -08003007 /**
3008 * @hide
3009 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003010 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003011 if (mService != null) {
3012 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003013 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003014 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003015 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003016 }
3017 }
3018 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003019
3020 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003021 * Should be called when keyguard has been dismissed.
3022 * @hide
3023 */
3024 public void reportKeyguardDismissed() {
3025 if (mService != null) {
3026 try {
3027 mService.reportKeyguardDismissed();
3028 } catch (RemoteException e) {
3029 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3030 }
3031 }
3032 }
3033
3034 /**
3035 * Should be called when keyguard view has been shown to the user.
3036 * @hide
3037 */
3038 public void reportKeyguardSecured() {
3039 if (mService != null) {
3040 try {
3041 mService.reportKeyguardSecured();
3042 } catch (RemoteException e) {
3043 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3044 }
3045 }
3046 }
3047
3048 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003049 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003050 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003051 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3052 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003053 * @return whether the package was successfully registered as the device owner.
3054 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003055 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003056 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003057 public boolean setDeviceOwner(ComponentName who) {
3058 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003059 }
3060
3061 /**
3062 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003063 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003064 public boolean setDeviceOwner(ComponentName who, int userId) {
3065 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003066 }
3067
3068 /**
3069 * @hide
3070 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003071 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3072 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003073 }
3074
3075 /**
3076 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003077 * Sets the given package as the device owner. The package must already be installed. There
3078 * must not already be a device owner.
3079 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3080 * this method.
3081 * Calling this after the setup phase of the primary user has completed is allowed only if
3082 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003083 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003084 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003085 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003086 * @return whether the package was successfully registered as the device owner.
3087 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003088 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003089 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003090 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003091 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003092 if (mService != null) {
3093 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003094 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003095 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003096 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003097 }
3098 }
3099 return false;
3100 }
3101
3102 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003103 * Used to determine if a particular package has been registered as a Device Owner app.
3104 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003105 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003106 * package is currently registered as the device owner app, pass in the package name from
3107 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003108 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003109 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3110 * the setup process.
3111 * @param packageName the package name of the app, to compare with the registered device owner
3112 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003113 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003114 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003115 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003116 return isDeviceOwnerAppOnCallingUser(packageName);
3117 }
3118
3119 /**
3120 * @return true if a package is registered as device owner, only when it's running on the
3121 * calling user.
3122 *
3123 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3124 * @hide
3125 */
3126 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3127 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3128 }
3129
3130 /**
3131 * @return true if a package is registered as device owner, even if it's running on a different
3132 * user.
3133 *
3134 * <p>Requires the MANAGE_USERS permission.
3135 *
3136 * @hide
3137 */
3138 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3139 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3140 }
3141
3142 /**
3143 * @return device owner component name, only when it's running on the calling user.
3144 *
3145 * @hide
3146 */
3147 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3148 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3149 }
3150
3151 /**
3152 * @return device owner component name, even if it's running on a different user.
3153 *
3154 * <p>Requires the MANAGE_USERS permission.
3155 *
3156 * @hide
3157 */
3158 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3159 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3160 }
3161
3162 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003163 if (packageName == null) {
3164 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003165 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003166 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003167 if (deviceOwner == null) {
3168 return false;
3169 }
3170 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003171 }
3172
Makoto Onukic8a5a552015-11-19 14:29:12 -08003173 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3174 if (mService != null) {
3175 try {
3176 return mService.getDeviceOwnerComponent(callingUserOnly);
3177 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003178 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003179 }
3180 }
3181 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003182 }
3183
Jason Monkb0dced82014-06-06 14:36:20 -04003184 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003185 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3186 * no device owner.
3187 *
3188 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003189 *
3190 * @hide
3191 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003192 public int getDeviceOwnerUserId() {
3193 if (mService != null) {
3194 try {
3195 return mService.getDeviceOwnerUserId();
3196 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003197 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003198 }
3199 }
3200 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003201 }
3202
3203 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003204 * Clears the current device owner. The caller must be the device owner.
3205 *
3206 * This function should be used cautiously as once it is called it cannot
3207 * be undone. The device owner can only be set as a part of device setup
3208 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003209 *
3210 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003211 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003212 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003213 if (mService != null) {
3214 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003215 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003216 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003217 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003218 }
3219 }
3220 }
3221
Makoto Onukia52562c2015-10-01 16:12:31 -07003222 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003223 * Returns the device owner package name, only if it's running on the calling user.
3224 *
3225 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003226 *
3227 * @hide
3228 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003229 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003230 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003231 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3232 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003233 }
3234
3235 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003236 * @return true if the device is managed by any device owner.
3237 *
3238 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003239 *
3240 * @hide
3241 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003242 public boolean isDeviceManaged() {
3243 return getDeviceOwnerComponentOnAnyUser() != null;
3244 }
3245
3246 /**
3247 * Returns the device owner name. Note this method *will* return the device owner
3248 * name when it's running on a different user.
3249 *
3250 * <p>Requires the MANAGE_USERS permission.
3251 *
3252 * @hide
3253 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003254 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003255 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003256 if (mService != null) {
3257 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003258 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003259 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003260 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003261 }
3262 }
3263 return null;
3264 }
Adam Connors776c5552014-01-09 10:42:56 +00003265
3266 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003267 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003268 * @deprecated Do not use
3269 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003270 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003271 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003272 @SystemApi
3273 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003274 return null;
3275 }
3276
3277 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003278 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003279 * @deprecated Do not use
3280 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003281 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003282 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003283 @SystemApi
3284 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003285 return null;
3286 }
3287
Julia Reynolds20118f12015-02-11 12:34:08 -05003288 /**
Adam Connors776c5552014-01-09 10:42:56 +00003289 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003290 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303291 * Sets the given component as an active admin and registers the package as the profile
3292 * owner for this user. The package must already be installed and there shouldn't be
3293 * an existing profile owner registered for this user. Also, this method must be called
3294 * before the user setup has been completed.
3295 * <p>
3296 * This method can only be called by system apps that hold MANAGE_USERS permission and
3297 * MANAGE_DEVICE_ADMINS permission.
3298 * @param admin The component to register as an active admin and profile owner.
3299 * @param ownerName The user-visible name of the entity that is managing this user.
3300 * @return whether the admin was successfully registered as the profile owner.
3301 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3302 * the user has already been set up.
3303 */
Justin Morey80440cc2014-07-24 09:16:35 -05003304 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003305 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303306 throws IllegalArgumentException {
3307 if (mService != null) {
3308 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003309 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303310 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003311 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303312 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303313 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3314 }
3315 }
3316 return false;
3317 }
3318
3319 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003320 * Clears the active profile owner and removes all user restrictions. The caller must
3321 * be from the same package as the active profile owner for this user, otherwise a
3322 * SecurityException will be thrown.
3323 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003324 * <p>This doesn't work for managed profile owners.
3325 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003326 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003327 */
Robin Lee25e26452015-06-02 09:56:29 -07003328 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003329 if (mService != null) {
3330 try {
3331 mService.clearProfileOwner(admin);
3332 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003333 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003334 }
3335 }
3336 }
3337
3338 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003339 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003340 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003341 */
3342 public boolean hasUserSetupCompleted() {
3343 if (mService != null) {
3344 try {
3345 return mService.hasUserSetupCompleted();
3346 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003347 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003348 }
3349 }
3350 return true;
3351 }
3352
3353 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003354 * @hide
3355 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003356 * already be installed. There must not already be a profile owner for this user.
3357 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3358 * this method.
3359 * Calling this after the setup phase of the specified user has completed is allowed only if:
3360 * - the caller is SYSTEM_UID.
3361 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003362 * @param admin the component name to be registered as profile owner.
3363 * @param ownerName the human readable name of the organisation associated with this DPM.
3364 * @param userHandle the userId to set the profile owner for.
3365 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003366 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3367 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003368 */
Robin Lee25e26452015-06-02 09:56:29 -07003369 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003370 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003371 if (mService != null) {
3372 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003373 if (ownerName == null) {
3374 ownerName = "";
3375 }
3376 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003377 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003378 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003379 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3380 }
3381 }
3382 return false;
3383 }
3384
3385 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003386 * Sets the device owner information to be shown on the lock screen.
3387 *
3388 * <p>If the device owner information is {@code null} or empty then the device owner info is
3389 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003390 * <p>If the device owner information contains only whitespaces then the message on the lock
3391 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003392 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003393 * <p>If the device owner information needs to be localized, it is the responsibility of the
3394 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3395 * and set a new version of this string accordingly.
3396 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003397 * @param admin The name of the admin component to check.
3398 * @param info Device owner information which will be displayed instead of the user
3399 * owner info.
3400 * @return Whether the device owner information has been set.
3401 */
3402 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3403 if (mService != null) {
3404 try {
3405 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3406 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003407 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003408 }
3409 }
3410 return false;
3411 }
3412
3413 /**
3414 * @return The device owner information. If it is not set returns {@code null}.
3415 */
3416 public String getDeviceOwnerLockScreenInfo() {
3417 if (mService != null) {
3418 try {
3419 return mService.getDeviceOwnerLockScreenInfo();
3420 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003421 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003422 }
3423 }
3424 return null;
3425 }
3426
3427 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003428 * Called by device or profile owners for setting the package suspended for this user.
3429 * A suspended package will not be started by the package manager, its notifications will
3430 * be hidden and it will not show up in recents. The package must already be installed.
3431 *
3432 * @param admin The name of the admin component to check.
3433 * @param packageName The package name of the app to suspend or unsuspend.
3434 * @param suspended If set to {@code true} than the package will be suspended, if set to
3435 * {@code false} the package will be unsuspended.
3436 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3437 * otherwise.
3438 */
3439 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3440 boolean suspended) {
3441 if (mService != null) {
3442 try {
3443 return mService.setPackageSuspended(admin, packageName, suspended);
3444 } catch (RemoteException re) {
3445 Log.w(TAG, "Failed talking with device policy service", re);
3446 }
3447 }
3448 return false;
3449 }
3450
3451 /**
3452 * Called by device or profile owners to determine if a package is suspended.
3453 *
3454 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3455 * @param packageName The name of the package to retrieve the suspended status of.
3456 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3457 */
3458 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3459 if (mService != null) {
3460 try {
3461 return mService.getPackageSuspended(admin, packageName);
3462 } catch (RemoteException e) {
3463 Log.w(TAG, "Failed talking with device policy service", e);
3464 }
3465 }
3466 return false;
3467 }
3468
3469 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003470 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3471 * be used. Only the profile owner can call this.
3472 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003473 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003474 *
3475 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3476 */
Robin Lee25e26452015-06-02 09:56:29 -07003477 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003478 if (mService != null) {
3479 try {
3480 mService.setProfileEnabled(admin);
3481 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003482 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003483 }
3484 }
3485 }
3486
3487 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003488 * Sets the name of the profile. In the device owner case it sets the name of the user
3489 * 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 +01003490 * never called by the profile or device owner, the name will be set to default values.
3491 *
3492 * @see #isProfileOwnerApp
3493 * @see #isDeviceOwnerApp
3494 *
Robin Lee25e26452015-06-02 09:56:29 -07003495 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003496 * @param profileName The name of the profile.
3497 */
Robin Lee25e26452015-06-02 09:56:29 -07003498 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003499 if (mService != null) {
3500 try {
Robin Lee25e26452015-06-02 09:56:29 -07003501 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003502 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003503 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003504 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003505 }
3506 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003507
3508 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003509 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003510 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003511 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003512 *
3513 * @param packageName The package name of the app to compare with the registered profile owner.
3514 * @return Whether or not the package is registered as the profile owner.
3515 */
3516 public boolean isProfileOwnerApp(String packageName) {
3517 if (mService != null) {
3518 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003519 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003520 return profileOwner != null
3521 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003522 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003523 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003524 }
3525 }
3526 return false;
3527 }
3528
3529 /**
3530 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003531 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003532 * owner has been set for that user.
3533 * @throws IllegalArgumentException if the userId is invalid.
3534 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003535 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003536 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003537 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3538 }
3539
3540 /**
3541 * @see #getProfileOwner()
3542 * @hide
3543 */
3544 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003545 if (mService != null) {
3546 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003547 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003548 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003549 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003550 throw new IllegalArgumentException(
3551 "Requested profile owner for invalid userId", re);
3552 }
3553 }
3554 return null;
3555 }
3556
3557 /**
3558 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003559 * @return the human readable name of the organisation associated with this DPM or {@code null}
3560 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003561 * @throws IllegalArgumentException if the userId is invalid.
3562 */
3563 public String getProfileOwnerName() throws IllegalArgumentException {
3564 if (mService != null) {
3565 try {
3566 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3567 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003568 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003569 throw new IllegalArgumentException(
3570 "Requested profile owner for invalid userId", re);
3571 }
3572 }
3573 return null;
3574 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003575
3576 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003577 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003578 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003579 * @return the human readable name of the organisation associated with this profile owner or
3580 * null if one is not set.
3581 * @throws IllegalArgumentException if the userId is invalid.
3582 */
3583 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003584 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003585 if (mService != null) {
3586 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003587 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003588 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003589 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003590 throw new IllegalArgumentException(
3591 "Requested profile owner for invalid userId", re);
3592 }
3593 }
3594 return null;
3595 }
3596
3597 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003598 * Called by a profile owner or device owner to add a default intent handler activity for
3599 * intents that match a certain intent filter. This activity will remain the default intent
3600 * handler even if the set of potential event handlers for the intent filter changes and if
3601 * the intent preferences are reset.
3602 *
3603 * <p>The default disambiguation mechanism takes over if the activity is not installed
3604 * (anymore). When the activity is (re)installed, it is automatically reset as default
3605 * intent handler for the filter.
3606 *
3607 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3608 * security exception will be thrown.
3609 *
3610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3611 * @param filter The IntentFilter for which a default handler is added.
3612 * @param activity The Activity that is added as default intent handler.
3613 */
Robin Lee25e26452015-06-02 09:56:29 -07003614 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3615 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003616 if (mService != null) {
3617 try {
3618 mService.addPersistentPreferredActivity(admin, filter, activity);
3619 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003620 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003621 }
3622 }
3623 }
3624
3625 /**
3626 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003627 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003628 *
3629 * <p>The calling device admin must be a profile owner. If it is not, a security
3630 * exception will be thrown.
3631 *
3632 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3633 * @param packageName The name of the package for which preferences are removed.
3634 */
Robin Lee25e26452015-06-02 09:56:29 -07003635 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003636 String packageName) {
3637 if (mService != null) {
3638 try {
3639 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3640 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003641 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003642 }
3643 }
3644 }
Robin Lee66e5d962014-04-09 16:44:21 +01003645
3646 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003647 * Called by a profile owner or device owner to grant permission to a package to manage
3648 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3649 * {@link #getApplicationRestrictions}.
3650 * <p>
3651 * This permission is persistent until it is later cleared by calling this method with a
3652 * {@code null} value or uninstalling the managing package.
3653 *
3654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3655 * @param packageName The package name which will be given access to application restrictions
3656 * APIs. If {@code null} is given the current package will be cleared.
3657 */
3658 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3659 @Nullable String packageName) {
3660 if (mService != null) {
3661 try {
3662 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3663 } catch (RemoteException e) {
3664 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3665 }
3666 }
3667 }
3668
3669 /**
3670 * Called by a profile owner or device owner to retrieve the application restrictions managing
3671 * package for the current user, or {@code null} if none is set.
3672 *
3673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3674 * @return The package name allowed to manage application restrictions on the current user, or
3675 * {@code null} if none is set.
3676 */
3677 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3678 if (mService != null) {
3679 try {
3680 return mService.getApplicationRestrictionsManagingPackage(admin);
3681 } catch (RemoteException e) {
3682 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3683 }
3684 }
3685 return null;
3686 }
3687
3688 /**
3689 * Returns {@code true} if the calling package has been granted permission via
3690 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3691 * restrictions for the calling user.
3692 */
3693 public boolean isCallerApplicationRestrictionsManagingPackage() {
3694 if (mService != null) {
3695 try {
3696 return mService.isCallerApplicationRestrictionsManagingPackage();
3697 } catch (RemoteException e) {
3698 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3699 }
3700 }
3701 return false;
3702 }
3703
3704 /**
3705 * Sets the application restrictions for a given target application running in the calling user.
3706 *
3707 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3708 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3709 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003710 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003711 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3712 * <ul>
3713 * <li>{@code boolean}
3714 * <li>{@code int}
3715 * <li>{@code String} or {@code String[]}
3716 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3717 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003718 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003719 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003720 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003721 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3722 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003723 * <p>The application restrictions are only made visible to the target application via
3724 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3725 * device owner, and the application restrictions managing package via
3726 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003727 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003728 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3729 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003730 * @param packageName The name of the package to update restricted settings for.
3731 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3732 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003733 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003734 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003735 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003736 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003737 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003738 Bundle settings) {
3739 if (mService != null) {
3740 try {
3741 mService.setApplicationRestrictions(admin, packageName, settings);
3742 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003743 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003744 }
3745 }
3746 }
3747
3748 /**
Jim Millere303bf42014-08-26 17:12:29 -07003749 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3750 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3751 * trust agents but those enabled by this function call. If flag
3752 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003753 *
3754 * <p>The calling device admin must have requested
3755 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003756 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003757 *
3758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003759 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003760 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003761 * will be strictly disabled according to the state of the
3762 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3763 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3764 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3765 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003766 */
Robin Lee25e26452015-06-02 09:56:29 -07003767 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3768 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003769 if (mService != null) {
3770 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003771 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003772 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003773 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003774 }
3775 }
3776 }
3777
3778 /**
Jim Millere303bf42014-08-26 17:12:29 -07003779 * Gets configuration for the given trust agent based on aggregating all calls to
3780 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3781 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003782 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003783 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3784 * this function returns a list of configurations for all admins that declare
3785 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3786 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3787 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3788 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003789 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003790 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003791 */
Robin Lee25e26452015-06-02 09:56:29 -07003792 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3793 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003794 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003795 }
3796
3797 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003798 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3799 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003800 if (mService != null) {
3801 try {
Jim Millere303bf42014-08-26 17:12:29 -07003802 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003803 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003804 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003805 }
3806 }
Jim Millere303bf42014-08-26 17:12:29 -07003807 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003808 }
3809
3810 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003811 * Called by a profile owner of a managed profile to set whether caller-Id information from
3812 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003813 *
3814 * <p>The calling device admin must be a profile owner. If it is not, a
3815 * security exception will be thrown.
3816 *
Robin Lee25e26452015-06-02 09:56:29 -07003817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003818 * @param disabled If true caller-Id information in the managed profile is not displayed.
3819 */
Robin Lee25e26452015-06-02 09:56:29 -07003820 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003821 if (mService != null) {
3822 try {
Robin Lee25e26452015-06-02 09:56:29 -07003823 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003824 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003825 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003826 }
3827 }
3828 }
3829
3830 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003831 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3832 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003833 *
3834 * <p>The calling device admin must be a profile owner. If it is not, a
3835 * security exception will be thrown.
3836 *
Robin Lee25e26452015-06-02 09:56:29 -07003837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003838 */
Robin Lee25e26452015-06-02 09:56:29 -07003839 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003840 if (mService != null) {
3841 try {
Robin Lee25e26452015-06-02 09:56:29 -07003842 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003843 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003844 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003845 }
3846 }
3847 return false;
3848 }
3849
3850 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003851 * Determine whether or not caller-Id information has been disabled.
3852 *
3853 * @param userHandle The user for whom to check the caller-id permission
3854 * @hide
3855 */
3856 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3857 if (mService != null) {
3858 try {
3859 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3860 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003861 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003862 }
3863 }
3864 return false;
3865 }
3866
3867 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003868 * Called by a profile owner of a managed profile to set whether contacts search from
3869 * the managed profile will be shown in the parent profile, for incoming calls.
3870 *
3871 * <p>The calling device admin must be a profile owner. If it is not, a
3872 * security exception will be thrown.
3873 *
3874 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3875 * @param disabled If true contacts search in the managed profile is not displayed.
3876 */
3877 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3878 boolean disabled) {
3879 if (mService != null) {
3880 try {
3881 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3882 } catch (RemoteException e) {
3883 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3884 }
3885 }
3886 }
3887
3888 /**
3889 * Called by a profile owner of a managed profile to determine whether or not contacts search
3890 * has been disabled.
3891 *
3892 * <p>The calling device admin must be a profile owner. If it is not, a
3893 * security exception will be thrown.
3894 *
3895 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3896 */
3897 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3898 if (mService != null) {
3899 try {
3900 return mService.getCrossProfileContactsSearchDisabled(admin);
3901 } catch (RemoteException e) {
3902 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3903 }
3904 }
3905 return false;
3906 }
3907
3908
3909 /**
3910 * Determine whether or not contacts search has been disabled.
3911 *
3912 * @param userHandle The user for whom to check the contacts search permission
3913 * @hide
3914 */
3915 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3916 if (mService != null) {
3917 try {
3918 return mService
3919 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3920 } catch (RemoteException e) {
3921 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3922 }
3923 }
3924 return false;
3925 }
3926
3927 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003928 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00003929 *
Makoto Onuki1040da12015-03-19 11:24:00 -07003930 * @hide
3931 */
3932 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00003933 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003934 if (mService != null) {
3935 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00003936 mService.startManagedQuickContact(actualLookupKey, actualContactId,
3937 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003938 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003939 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003940 }
3941 }
3942 }
3943
3944 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003945 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00003946 * @hide
3947 */
3948 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
3949 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00003950 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00003951 originalIntent);
3952 }
3953
3954 /**
Ricky Wai778ba132015-03-31 14:21:22 +01003955 * Called by a profile owner of a managed profile to set whether bluetooth
3956 * devices can access enterprise contacts.
3957 * <p>
3958 * The calling device admin must be a profile owner. If it is not, a
3959 * security exception will be thrown.
3960 * <p>
3961 * This API works on managed profile only.
3962 *
Robin Lee25e26452015-06-02 09:56:29 -07003963 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003964 * with.
3965 * @param disabled If true, bluetooth devices cannot access enterprise
3966 * contacts.
3967 */
Robin Lee25e26452015-06-02 09:56:29 -07003968 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01003969 if (mService != null) {
3970 try {
Robin Lee25e26452015-06-02 09:56:29 -07003971 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01003972 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003973 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003974 }
3975 }
3976 }
3977
3978 /**
3979 * Called by a profile owner of a managed profile to determine whether or
3980 * not Bluetooth devices cannot access enterprise contacts.
3981 * <p>
3982 * The calling device admin must be a profile owner. If it is not, a
3983 * security exception will be thrown.
3984 * <p>
3985 * This API works on managed profile only.
3986 *
Robin Lee25e26452015-06-02 09:56:29 -07003987 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01003988 * with.
3989 */
Robin Lee25e26452015-06-02 09:56:29 -07003990 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01003991 if (mService != null) {
3992 try {
Robin Lee25e26452015-06-02 09:56:29 -07003993 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01003994 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003995 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01003996 }
3997 }
3998 return true;
3999 }
4000
4001 /**
4002 * Determine whether or not Bluetooth devices cannot access contacts.
4003 * <p>
4004 * This API works on managed profile UserHandle only.
4005 *
4006 * @param userHandle The user for whom to check the caller-id permission
4007 * @hide
4008 */
4009 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4010 if (mService != null) {
4011 try {
4012 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4013 .getIdentifier());
4014 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004015 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004016 }
4017 }
4018 return true;
4019 }
4020
4021 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004022 * Called by the profile owner of a managed profile so that some intents sent in the managed
4023 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004024 * Only activity intents are supported.
4025 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004026 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004027 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4028 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004029 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4030 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004031 */
Robin Lee25e26452015-06-02 09:56:29 -07004032 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004033 if (mService != null) {
4034 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004035 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004036 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004037 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004038 }
4039 }
4040 }
4041
4042 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004043 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4044 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004045 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004046 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4047 */
Robin Lee25e26452015-06-02 09:56:29 -07004048 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004049 if (mService != null) {
4050 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004051 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004052 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004053 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004054 }
4055 }
4056 }
4057
4058 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004059 * Called by a profile or device owner to set the permitted accessibility services. When
4060 * set by a device owner or profile owner the restriction applies to all profiles of the
4061 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004062 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004063 * By default the user can use any accessiblity service. When zero or more packages have
4064 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004065 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004066 *
4067 * <p> Calling with a null value for the list disables the restriction so that all services
4068 * can be used, calling with an empty list only allows the builtin system's services.
4069 *
4070 * <p> System accesibility services are always available to the user the list can't modify
4071 * this.
4072 *
4073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4074 * @param packageNames List of accessibility service package names.
4075 *
4076 * @return true if setting the restriction succeeded. It fail if there is
4077 * one or more non-system accessibility services enabled, that are not in the list.
4078 */
Robin Lee25e26452015-06-02 09:56:29 -07004079 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004080 List<String> packageNames) {
4081 if (mService != null) {
4082 try {
4083 return mService.setPermittedAccessibilityServices(admin, packageNames);
4084 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004085 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004086 }
4087 }
4088 return false;
4089 }
4090
4091 /**
4092 * Returns the list of permitted accessibility services set by this device or profile owner.
4093 *
4094 * <p>An empty list means no accessibility services except system services are allowed.
4095 * Null means all accessibility services are allowed.
4096 *
4097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4098 * @return List of accessiblity service package names.
4099 */
Robin Lee25e26452015-06-02 09:56:29 -07004100 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004101 if (mService != null) {
4102 try {
4103 return mService.getPermittedAccessibilityServices(admin);
4104 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004105 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004106 }
4107 }
4108 return null;
4109 }
4110
4111 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004112 * Called by the system to check if a specific accessibility service is disabled by admin.
4113 *
4114 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4115 * @param packageName Accessibility service package name that needs to be checked.
4116 * @param userHandle user id the admin is running as.
4117 * @return true if the accessibility service is permitted, otherwise false.
4118 *
4119 * @hide
4120 */
4121 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4122 @NonNull String packageName, int userHandle) {
4123 if (mService != null) {
4124 try {
4125 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4126 userHandle);
4127 } catch (RemoteException e) {
4128 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4129 }
4130 }
4131 return false;
4132 }
4133
4134 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004135 * Returns the list of accessibility services permitted by the device or profiles
4136 * owners of this user.
4137 *
4138 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4139 * it will contain the intersection of the permitted lists for any device or profile
4140 * owners that apply to this user. It will also include any system accessibility services.
4141 *
4142 * @param userId which user to check for.
4143 * @return List of accessiblity service package names.
4144 * @hide
4145 */
4146 @SystemApi
4147 public List<String> getPermittedAccessibilityServices(int userId) {
4148 if (mService != null) {
4149 try {
4150 return mService.getPermittedAccessibilityServicesForUser(userId);
4151 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004152 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004153 }
4154 }
4155 return null;
4156 }
4157
4158 /**
4159 * Called by a profile or device owner to set the permitted input methods services. When
4160 * set by a device owner or profile owner the restriction applies to all profiles of the
4161 * user the device owner or profile owner is an admin for.
4162 *
4163 * By default the user can use any input method. When zero or more packages have
4164 * been added, input method that are not in the list and not part of the system
4165 * can not be enabled by the user.
4166 *
4167 * This method will fail if it is called for a admin that is not for the foreground user
4168 * or a profile of the foreground user.
4169 *
4170 * <p> Calling with a null value for the list disables the restriction so that all input methods
4171 * can be used, calling with an empty list disables all but the system's own input methods.
4172 *
4173 * <p> System input methods are always available to the user this method can't modify this.
4174 *
4175 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4176 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004177 * @return true if setting the restriction succeeded. It will fail if there are
4178 * one or more non-system input methods currently enabled that are not in
4179 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004180 */
Robin Lee25e26452015-06-02 09:56:29 -07004181 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004182 if (mService != null) {
4183 try {
4184 return mService.setPermittedInputMethods(admin, packageNames);
4185 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004186 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004187 }
4188 }
4189 return false;
4190 }
4191
4192
4193 /**
4194 * Returns the list of permitted input methods set by this device or profile owner.
4195 *
4196 * <p>An empty list means no input methods except system input methods are allowed.
4197 * Null means all input methods are allowed.
4198 *
4199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4200 * @return List of input method package names.
4201 */
Robin Lee25e26452015-06-02 09:56:29 -07004202 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004203 if (mService != null) {
4204 try {
4205 return mService.getPermittedInputMethods(admin);
4206 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004207 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004208 }
4209 }
4210 return null;
4211 }
4212
4213 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004214 * Called by the system to check if a specific input method is disabled by admin.
4215 *
4216 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4217 * @param packageName Input method package name that needs to be checked.
4218 * @param userHandle user id the admin is running as.
4219 * @return true if the input method is permitted, otherwise false.
4220 *
4221 * @hide
4222 */
4223 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4224 @NonNull String packageName, int userHandle) {
4225 if (mService != null) {
4226 try {
4227 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4228 } catch (RemoteException e) {
4229 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4230 }
4231 }
4232 return false;
4233 }
4234
4235 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004236 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004237 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004238 *
4239 * <p>Null means all input methods are allowed, if a non-null list is returned
4240 * it will contain the intersection of the permitted lists for any device or profile
4241 * owners that apply to this user. It will also include any system input methods.
4242 *
4243 * @return List of input method package names.
4244 * @hide
4245 */
4246 @SystemApi
4247 public List<String> getPermittedInputMethodsForCurrentUser() {
4248 if (mService != null) {
4249 try {
4250 return mService.getPermittedInputMethodsForCurrentUser();
4251 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004252 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004253 }
4254 }
4255 return null;
4256 }
4257
4258 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004259 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4260 * currently installed it.
4261 *
4262 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4263 *
4264 * @return List of package names to keep cached.
4265 * @hide
4266 */
4267 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4268 if (mService != null) {
4269 try {
4270 return mService.getKeepUninstalledPackages(admin);
4271 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004272 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004273 }
4274 }
4275 return null;
4276 }
4277
4278 /**
4279 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4280 * currently installed it.
4281 *
4282 * <p>Please note that setting this policy does not imply that specified apps will be
4283 * automatically pre-cached.</p>
4284 *
4285 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4286 * @param packageNames List of package names to keep cached.
4287 * @hide
4288 */
4289 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4290 @NonNull List<String> packageNames) {
4291 if (mService != null) {
4292 try {
4293 mService.setKeepUninstalledPackages(admin, packageNames);
4294 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004295 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004296 }
4297 }
4298 }
4299
4300 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004301 * Called by a device owner to create a user with the specified name. The UserHandle returned
4302 * by this method should not be persisted as user handles are recycled as users are removed and
4303 * created. If you need to persist an identifier for this user, use
4304 * {@link UserManager#getSerialNumberForUser}.
4305 *
4306 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4307 * @param name the user's name
4308 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004309 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4310 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004311 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004312 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004313 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004314 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004315 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004316 try {
4317 return mService.createUser(admin, name);
4318 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004319 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004320 }
4321 return null;
4322 }
4323
4324 /**
Jason Monk03978a42014-06-10 15:05:30 -04004325 * Called by a device owner to create a user with the specified name. The UserHandle returned
4326 * by this method should not be persisted as user handles are recycled as users are removed and
4327 * created. If you need to persist an identifier for this user, use
4328 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4329 * immediately.
4330 *
4331 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4332 * as registered as an active admin on the new user. The profile owner package will be
4333 * installed on the new user if it already is installed on the device.
4334 *
4335 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4336 * profileOwnerComponent when onEnable is called.
4337 *
4338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4339 * @param name the user's name
4340 * @param ownerName the human readable name of the organisation associated with this DPM.
4341 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4342 * the user.
4343 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4344 * on the new user.
4345 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004346 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4347 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004348 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004349 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004350 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004351 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004352 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4353 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004354 try {
4355 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4356 adminExtras);
4357 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004358 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004359 }
4360 return null;
4361 }
4362
4363 /**
phweissa92e1212016-01-25 17:14:10 +01004364 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004365 */
4366 public static final int SKIP_SETUP_WIZARD = 0x0001;
4367
4368 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004369 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4370 * ephemeral.
4371 * @hide
4372 */
4373 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4374
4375 /**
phweissa92e1212016-01-25 17:14:10 +01004376 * Called by a device owner to create a user with the specified name and a given component of
4377 * the calling package as profile owner. The UserHandle returned by this method should not be
4378 * persisted as user handles are recycled as users are removed and created. If you need to
4379 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4380 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004381 *
phweissa92e1212016-01-25 17:14:10 +01004382 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4383 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4384 * will be registered as an active admin on the new user. The profile owner package will be
4385 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004386 *
4387 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4388 * started for the first time. Then the extras will be passed to the admin when
4389 * onEnable is called.
4390 *
4391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4392 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004393 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4394 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4395 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004396 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4397 * user.
phweissa92e1212016-01-25 17:14:10 +01004398 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004399 * @see UserHandle
4400 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4401 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004402 */
4403 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004404 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4405 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004406 try {
phweissa92e1212016-01-25 17:14:10 +01004407 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004408 } catch (RemoteException re) {
4409 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4410 }
4411 return null;
4412 }
4413
4414 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004415 * Called by a device owner to remove a user and all associated data. The primary user can
4416 * not be removed.
4417 *
4418 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4419 * @param userHandle the user to remove.
4420 * @return {@code true} if the user was removed, {@code false} otherwise.
4421 */
Robin Lee25e26452015-06-02 09:56:29 -07004422 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004423 try {
4424 return mService.removeUser(admin, userHandle);
4425 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004426 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004427 return false;
4428 }
4429 }
4430
4431 /**
Jason Monk582d9112014-07-09 19:57:08 -04004432 * Called by a device owner to switch the specified user to the foreground.
4433 *
4434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4435 * @param userHandle the user to switch to; null will switch to primary.
4436 * @return {@code true} if the switch was successful, {@code false} otherwise.
4437 *
4438 * @see Intent#ACTION_USER_FOREGROUND
4439 */
Robin Lee25e26452015-06-02 09:56:29 -07004440 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004441 try {
4442 return mService.switchUser(admin, userHandle);
4443 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004444 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004445 return false;
4446 }
4447 }
4448
4449 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004450 * Retrieves the application restrictions for a given target application running in the calling
4451 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004452 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004453 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4454 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4455 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004456 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004457 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4458 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004459 * @param packageName The name of the package to fetch restricted settings of.
4460 * @return {@link Bundle} of settings corresponding to what was set last time
4461 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4462 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004463 *
4464 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004465 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004466 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004467 if (mService != null) {
4468 try {
4469 return mService.getApplicationRestrictions(admin, packageName);
4470 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004471 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004472 }
4473 }
4474 return null;
4475 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004476
4477 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004478 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004479 * <p>
4480 * The calling device admin must be a profile or device owner; if it is not,
4481 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004482 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004483 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4484 * with.
4485 * @param key The key of the restriction. See the constants in
4486 * {@link android.os.UserManager} for the list of keys.
4487 */
Robin Lee25e26452015-06-02 09:56:29 -07004488 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004489 if (mService != null) {
4490 try {
4491 mService.setUserRestriction(admin, key, true);
4492 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004493 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004494 }
4495 }
4496 }
4497
4498 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004499 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004500 * <p>
4501 * The calling device admin must be a profile or device owner; if it is not,
4502 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004503 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004504 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4505 * with.
4506 * @param key The key of the restriction. See the constants in
4507 * {@link android.os.UserManager} for the list of keys.
4508 */
Robin Lee25e26452015-06-02 09:56:29 -07004509 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004510 if (mService != null) {
4511 try {
4512 mService.setUserRestriction(admin, key, false);
4513 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004514 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004515 }
4516 }
4517 }
Adam Connors010cfd42014-04-16 12:48:13 +01004518
4519 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004520 * Called by a profile or device owner to get user restrictions set with
4521 * {@link #addUserRestriction(ComponentName, String)}.
4522 * <p>
4523 * The target user may have more restrictions set by the system or other device owner / profile
4524 * owner. To get all the user restrictions currently set, use
4525 * {@link UserManager#getUserRestrictions()}.
4526 *
4527 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004528 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004529 */
4530 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004531 return getUserRestrictions(admin, myUserId());
4532 }
4533
4534 /** @hide per-user version */
4535 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004536 Bundle ret = null;
4537 if (mService != null) {
4538 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004539 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004540 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004541 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004542 }
4543 }
4544 return ret == null ? new Bundle() : ret;
4545 }
4546
4547 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004548 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004549 * is unavailable for use, but the data and actual package file remain.
4550 *
4551 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004552 * @param packageName The name of the package to hide or unhide.
4553 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4554 * unhidden.
4555 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004556 */
Robin Lee25e26452015-06-02 09:56:29 -07004557 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004558 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004559 if (mService != null) {
4560 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004561 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004562 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004563 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004564 }
4565 }
4566 return false;
4567 }
4568
4569 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004570 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004571 *
4572 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004573 * @param packageName The name of the package to retrieve the hidden status of.
4574 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004575 */
Robin Lee25e26452015-06-02 09:56:29 -07004576 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004577 if (mService != null) {
4578 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004579 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004580 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004581 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004582 }
4583 }
4584 return false;
4585 }
4586
4587 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004588 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004589 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004590 *
4591 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004592 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004593 */
Robin Lee25e26452015-06-02 09:56:29 -07004594 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004595 if (mService != null) {
4596 try {
4597 mService.enableSystemApp(admin, packageName);
4598 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004599 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004600 }
4601 }
4602 }
4603
4604 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004605 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004606 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004607 *
4608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4609 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004610 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004611 * @return int The number of activities that matched the intent and were installed.
4612 */
Robin Lee25e26452015-06-02 09:56:29 -07004613 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004614 if (mService != null) {
4615 try {
4616 return mService.enableSystemAppWithIntent(admin, intent);
4617 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004618 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004619 }
4620 }
4621 return 0;
4622 }
4623
4624 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004625 * Called by a device owner or profile owner to disable account management for a specific type
4626 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004627 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004628 * <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 +01004629 * security exception will be thrown.
4630 *
4631 * <p>When account management is disabled for an account type, adding or removing an account
4632 * of that type will not be possible.
4633 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004634 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4635 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4636 * management for a specific type is disabled.
4637 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004638 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4639 * @param accountType For which account management is disabled or enabled.
4640 * @param disabled The boolean indicating that account management will be disabled (true) or
4641 * enabled (false).
4642 */
Robin Lee25e26452015-06-02 09:56:29 -07004643 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004644 boolean disabled) {
4645 if (mService != null) {
4646 try {
4647 mService.setAccountManagementDisabled(admin, accountType, disabled);
4648 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004649 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004650 }
4651 }
4652 }
4653
4654 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004655 * Gets the array of accounts for which account management is disabled by the profile owner.
4656 *
4657 * <p> Account management can be disabled/enabled by calling
4658 * {@link #setAccountManagementDisabled}.
4659 *
4660 * @return a list of account types for which account management has been disabled.
4661 *
4662 * @see #setAccountManagementDisabled
4663 */
4664 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004665 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004666 }
4667
4668 /**
4669 * @see #getAccountTypesWithManagementDisabled()
4670 * @hide
4671 */
4672 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004673 if (mService != null) {
4674 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004675 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004676 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004677 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004678 }
4679 }
4680
4681 return null;
4682 }
justinzhang511e0d82014-03-24 16:09:24 -04004683
4684 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004685 * Sets which packages may enter lock task mode.
4686 *
4687 * <p>Any packages that shares uid with an allowed package will also be allowed
4688 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004689 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004690 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004691 * package list results in locked tasks belonging to those packages to be finished.
4692 *
Jason Monkc5185f22014-06-24 11:12:42 -04004693 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004694 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004695 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004696 *
4697 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004698 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4699 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004700 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004701 */
Robin Lee25e26452015-06-02 09:56:29 -07004702 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004703 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004704 if (mService != null) {
4705 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004706 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004707 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004708 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004709 }
4710 }
4711 }
4712
4713 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004714 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004715 *
4716 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004717 * @hide
4718 */
Robin Lee25e26452015-06-02 09:56:29 -07004719 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004720 if (mService != null) {
4721 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004722 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004723 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004724 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004725 }
4726 }
4727 return null;
4728 }
4729
4730 /**
4731 * This function lets the caller know whether the given component is allowed to start the
4732 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004733 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004734 */
Jason Monkd7b86212014-06-16 13:15:38 -04004735 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004736 if (mService != null) {
4737 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004738 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004739 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004740 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004741 }
4742 }
4743 return false;
4744 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004745
4746 /**
4747 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4748 * 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 -04004749 * <p>The settings that can be updated with this method are:
4750 * <ul>
4751 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4752 * <li>{@link Settings.Global#AUTO_TIME}</li>
4753 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004754 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004755 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004756 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004757 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004758 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004759 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004760 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004761 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004762 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004763 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004764 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004765 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004766 * <ul>
4767 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4768 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4769 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4770 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4771 * <li>{@link Settings.Global#MODE_RINGER}.
4772 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4773 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4774 * <li>{@link Settings.Global#WIFI_ON}.
4775 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4776 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004777 *
4778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4779 * @param setting The name of the setting to update.
4780 * @param value The value to update the setting to.
4781 */
Robin Lee25e26452015-06-02 09:56:29 -07004782 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004783 if (mService != null) {
4784 try {
4785 mService.setGlobalSetting(admin, setting, value);
4786 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004787 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004788 }
4789 }
4790 }
4791
4792 /**
4793 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4794 * that the value of the setting is in the correct form for the setting type should be performed
4795 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004796 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004797 * <ul>
4798 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004799 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004800 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4801 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004802 * <p>A device owner can additionally update the following settings:
4803 * <ul>
4804 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4805 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004806 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4807 * @param setting The name of the setting to update.
4808 * @param value The value to update the setting to.
4809 */
Robin Lee25e26452015-06-02 09:56:29 -07004810 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004811 if (mService != null) {
4812 try {
4813 mService.setSecureSetting(admin, setting, value);
4814 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004815 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004816 }
4817 }
4818 }
4819
Amith Yamasanif20d6402014-05-24 15:34:37 -07004820 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004821 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004822 * making permission requests of a local or remote administrator of the user.
4823 * <p/>
4824 * Only a profile owner can designate the restrictions provider.
4825 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004826 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004827 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004828 * it removes the restrictions provider previously assigned.
4829 */
Robin Lee25e26452015-06-02 09:56:29 -07004830 public void setRestrictionsProvider(@NonNull ComponentName admin,
4831 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004832 if (mService != null) {
4833 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004834 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004835 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004836 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004837 }
4838 }
4839 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004840
4841 /**
4842 * Called by profile or device owners to set the master volume mute on or off.
4843 *
4844 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4845 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4846 */
Robin Lee25e26452015-06-02 09:56:29 -07004847 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004848 if (mService != null) {
4849 try {
4850 mService.setMasterVolumeMuted(admin, on);
4851 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004852 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004853 }
4854 }
4855 }
4856
4857 /**
4858 * Called by profile or device owners to check whether the master volume mute is on or off.
4859 *
4860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4861 * @return {@code true} if master volume is muted, {@code false} if it's not.
4862 */
Robin Lee25e26452015-06-02 09:56:29 -07004863 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004864 if (mService != null) {
4865 try {
4866 return mService.isMasterVolumeMuted(admin);
4867 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004868 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004869 }
4870 }
4871 return false;
4872 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004873
4874 /**
4875 * Called by profile or device owners to change whether a user can uninstall
4876 * a package.
4877 *
4878 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4879 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004880 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004881 */
Robin Lee25e26452015-06-02 09:56:29 -07004882 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004883 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004884 if (mService != null) {
4885 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004886 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004887 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004888 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004889 }
4890 }
4891 }
4892
4893 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004894 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004895 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004896 * <p>
4897 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004898 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004899 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004900 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004901 *
Robin Lee25e26452015-06-02 09:56:29 -07004902 * @param admin The name of the admin component whose blocking policy will be checked, or
4903 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004904 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004905 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004906 */
Robin Lee25e26452015-06-02 09:56:29 -07004907 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004908 if (mService != null) {
4909 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004910 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004911 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004912 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004913 }
4914 }
4915 return false;
4916 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004917
4918 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004919 * Called by the profile owner of a managed profile to enable widget providers from a
4920 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004921 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004922 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004923 * a package may have zero or more provider components, where each component
4924 * provides a different widget type.
4925 * <p>
4926 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004927 *
4928 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4929 * @param packageName The package from which widget providers are white-listed.
4930 * @return Whether the package was added.
4931 *
4932 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4933 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4934 */
Robin Lee25e26452015-06-02 09:56:29 -07004935 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004936 if (mService != null) {
4937 try {
4938 return mService.addCrossProfileWidgetProvider(admin, packageName);
4939 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004940 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004941 }
4942 }
4943 return false;
4944 }
4945
4946 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004947 * Called by the profile owner of a managed profile to disable widget providers from a given
4948 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07004949 * package should have been added via {@link #addCrossProfileWidgetProvider(
4950 * android.content.ComponentName, String)}.
4951 * <p>
4952 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004953 *
4954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4955 * @param packageName The package from which widget providers are no longer
4956 * white-listed.
4957 * @return Whether the package was removed.
4958 *
4959 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4960 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4961 */
Esteban Talavera62399912016-01-11 15:37:55 +00004962 public boolean removeCrossProfileWidgetProvider(
4963 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004964 if (mService != null) {
4965 try {
4966 return mService.removeCrossProfileWidgetProvider(admin, packageName);
4967 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004968 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004969 }
4970 }
4971 return false;
4972 }
4973
4974 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004975 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07004976 * available in the parent profile.
4977 *
4978 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4979 * @return The white-listed package list.
4980 *
4981 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
4982 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4983 */
Robin Lee25e26452015-06-02 09:56:29 -07004984 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004985 if (mService != null) {
4986 try {
4987 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
4988 if (providers != null) {
4989 return providers;
4990 }
4991 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004992 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07004993 }
4994 }
4995 return Collections.emptyList();
4996 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05004997
4998 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004999 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005000 *
5001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5002 * @param icon the bitmap to set as the photo.
5003 */
Robin Lee25e26452015-06-02 09:56:29 -07005004 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005005 try {
5006 mService.setUserIcon(admin, icon);
5007 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005008 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005009 }
5010 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005011
5012 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005013 * Called by device owners to set a local system update policy. When a new policy is set,
5014 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005015 *
Robin Lee25e26452015-06-02 09:56:29 -07005016 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5017 * components in the device owner package can set system update policies and the
5018 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005019 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005020 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005021 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005022 */
Robin Lee25e26452015-06-02 09:56:29 -07005023 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005024 if (mService != null) {
5025 try {
Robin Lee25e26452015-06-02 09:56:29 -07005026 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005027 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005028 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005029 }
5030 }
5031 }
5032
5033 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005034 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005035 *
Robin Lee25e26452015-06-02 09:56:29 -07005036 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005037 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005038 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005039 if (mService != null) {
5040 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005041 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005042 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005043 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005044 }
5045 }
5046 return null;
5047 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005048
5049 /**
5050 * Called by a device owner to disable the keyguard altogether.
5051 *
5052 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5053 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5054 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5055 * being disabled.
5056 *
5057 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005058 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005059 *
5060 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005061 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005062 */
Robin Lee25e26452015-06-02 09:56:29 -07005063 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005064 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005065 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005066 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005067 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01005068 return false;
5069 }
5070 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005071
5072 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005073 * Called by device owner to disable the status bar. Disabling the status bar blocks
5074 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005075 * a single use device.
5076 *
5077 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005078 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5079 *
5080 * @return {@code false} if attempting to disable the status bar failed.
5081 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005082 */
Robin Lee25e26452015-06-02 09:56:29 -07005083 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005084 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005085 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005086 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01005088 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00005089 }
5090 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005091
5092 /**
5093 * Callable by the system update service to notify device owners about pending updates.
5094 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5095 * permission.
5096 *
5097 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5098 * when the current pending update was first available. -1 if no update is available.
5099 * @hide
5100 */
5101 @SystemApi
5102 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5103 if (mService != null) {
5104 try {
5105 mService.notifyPendingSystemUpdate(updateReceivedTime);
5106 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005107 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01005108 }
5109 }
5110 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005111
5112 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005113 * Called by profile or device owners to set the default response for future runtime permission
5114 * requests by applications. The policy can allow for normal operation which prompts the
5115 * user to grant a permission, or can allow automatic granting or denying of runtime
5116 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005117 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5118 * the permission grant state via {@link #setPermissionGrantState}.
5119 *
5120 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005121 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005122 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005123 * @param admin Which profile or device owner this request is associated with.
5124 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5125 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005126 *
5127 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005128 */
Robin Lee25e26452015-06-02 09:56:29 -07005129 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005130 try {
5131 mService.setPermissionPolicy(admin, policy);
5132 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005133 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005134 }
5135 }
5136
5137 /**
5138 * Returns the current runtime permission policy set by the device or profile owner. The
5139 * default is {@link #PERMISSION_POLICY_PROMPT}.
5140 * @param admin Which profile or device owner this request is associated with.
5141 * @return the current policy for future permission requests.
5142 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005143 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005144 try {
5145 return mService.getPermissionPolicy(admin);
5146 } catch (RemoteException re) {
5147 return PERMISSION_POLICY_PROMPT;
5148 }
5149 }
5150
5151 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005152 * Sets the grant state of a runtime permission for a specific application. The state
5153 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5154 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5155 * is denied and the user cannot manage it through the UI, and {@link
5156 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5157 * user cannot manage it through the UI. This might affect all permissions in a
5158 * group that the runtime permission belongs to. This method can only be called
5159 * by a profile or device owner.
5160 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005161 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5162 * revoke the permission. It retains the previous grant, if any.
5163 *
5164 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005165 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005166 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005167 * @param admin Which profile or device owner this request is associated with.
5168 * @param packageName The application to grant or revoke a permission to.
5169 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005170 * @param grantState The permission grant state which is one of {@link
5171 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5172 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5173 * @return whether the permission was successfully granted or revoked.
5174 *
5175 * @see #PERMISSION_GRANT_STATE_DENIED
5176 * @see #PERMISSION_GRANT_STATE_DEFAULT
5177 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005178 */
Robin Lee25e26452015-06-02 09:56:29 -07005179 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005180 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005181 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005182 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005183 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005184 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005185 return false;
5186 }
5187 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005188
5189 /**
5190 * Returns the current grant state of a runtime permission for a specific application.
5191 *
5192 * @param admin Which profile or device owner this request is associated with.
5193 * @param packageName The application to check the grant state for.
5194 * @param permission The permission to check for.
5195 * @return the current grant state specified by device policy. If the profile or device owner
5196 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5197 * This does not indicate whether or not the permission is currently granted for the package.
5198 *
5199 * <p/>If a grant state was set by the profile or device owner, then the return value will
5200 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5201 * which indicates if the permission is currently denied or granted.
5202 *
5203 * @see #setPermissionGrantState(ComponentName, String, String, int)
5204 * @see PackageManager#checkPermission(String, String)
5205 */
Robin Lee25e26452015-06-02 09:56:29 -07005206 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005207 String permission) {
5208 try {
5209 return mService.getPermissionGrantState(admin, packageName, permission);
5210 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005211 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005212 return PERMISSION_GRANT_STATE_DEFAULT;
5213 }
5214 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005215
5216 /**
5217 * Returns if provisioning a managed profile or device is possible or not.
5218 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5219 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5220 * Note that even if this method returns true, there is a slight possibility that the
5221 * provisioning will not be allowed when it is actually initiated because some event has
5222 * happened in between.
5223 * @return if provisioning a managed profile or device is possible or not.
5224 * @throws IllegalArgumentException if the supplied action is not valid.
5225 */
5226 public boolean isProvisioningAllowed(String action) {
5227 try {
5228 return mService.isProvisioningAllowed(action);
5229 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005230 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005231 return false;
5232 }
5233 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005234
5235 /**
5236 * @hide
5237 * Return if this user is a managed profile of another user. An admin can become the profile
5238 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5239 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5240 * @param admin Which profile owner this request is associated with.
5241 * @return if this user is a managed profile of another user.
5242 */
5243 public boolean isManagedProfile(@NonNull ComponentName admin) {
5244 try {
5245 return mService.isManagedProfile(admin);
5246 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005247 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005248 return false;
5249 }
5250 }
5251
5252 /**
5253 * @hide
5254 * Return if this user is a system-only user. An admin can manage a device from a system only
5255 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5256 * @param admin Which device owner this request is associated with.
5257 * @return if this user is a system-only user.
5258 */
5259 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5260 try {
5261 return mService.isSystemOnlyUser(admin);
5262 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005263 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005264 return false;
5265 }
5266 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005267
5268 /**
5269 * Called by device owner to get the MAC address of the Wi-Fi device.
5270 *
5271 * @return the MAC address of the Wi-Fi device, or null when the information is not
5272 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5273 *
5274 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5275 */
5276 public String getWifiMacAddress() {
5277 try {
5278 return mService.getWifiMacAddress();
5279 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005280 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005281 return null;
5282 }
5283 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005284
5285 /**
5286 * Called by device owner to reboot the device.
5287 */
5288 public void reboot(@NonNull ComponentName admin) {
5289 try {
5290 mService.reboot(admin);
5291 } catch (RemoteException re) {
5292 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5293 }
5294 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005295
5296 /**
5297 * Called by a device admin to set the short support message. This will
5298 * be displayed to the user in settings screens where funtionality has
5299 * been disabled by the admin.
5300 *
5301 * The message should be limited to a short statement such as
5302 * "This setting is disabled by your administrator. Contact someone@example.com
5303 * for support."
5304 * If the message is longer than 200 characters it may be truncated.
5305 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005306 * <p>If the short support message needs to be localized, it is the responsibility of the
5307 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5308 * and set a new version of this string accordingly.
5309 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005310 * @see #setLongSupportMessage
5311 *
5312 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5313 * @param message Short message to be displayed to the user in settings or null to
5314 * clear the existing message.
5315 */
5316 public void setShortSupportMessage(@NonNull ComponentName admin,
5317 @Nullable String message) {
5318 if (mService != null) {
5319 try {
5320 mService.setShortSupportMessage(admin, message);
5321 } catch (RemoteException e) {
5322 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5323 }
5324 }
5325 }
5326
5327 /**
5328 * Called by a device admin to get the short support message.
5329 *
5330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5331 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5332 * or null if no message has been set.
5333 */
5334 public String getShortSupportMessage(@NonNull ComponentName admin) {
5335 if (mService != null) {
5336 try {
5337 return mService.getShortSupportMessage(admin);
5338 } catch (RemoteException e) {
5339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5340 }
5341 }
5342 return null;
5343 }
5344
5345 /**
5346 * Called by a device admin to set the long support message. This will
5347 * be displayed to the user in the device administators settings screen.
5348 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005349 * <p>If the long support message needs to be localized, it is the responsibility of the
5350 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5351 * and set a new version of this string accordingly.
5352 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005353 * @see #setShortSupportMessage
5354 *
5355 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5356 * @param message Long message to be displayed to the user in settings or null to
5357 * clear the existing message.
5358 */
5359 public void setLongSupportMessage(@NonNull ComponentName admin,
5360 @Nullable String message) {
5361 if (mService != null) {
5362 try {
5363 mService.setLongSupportMessage(admin, message);
5364 } catch (RemoteException e) {
5365 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5366 }
5367 }
5368 }
5369
5370 /**
5371 * Called by a device admin to get the long support message.
5372 *
5373 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5374 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5375 * or null if no message has been set.
5376 */
5377 public String getLongSupportMessage(@NonNull ComponentName admin) {
5378 if (mService != null) {
5379 try {
5380 return mService.getLongSupportMessage(admin);
5381 } catch (RemoteException e) {
5382 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5383 }
5384 }
5385 return null;
5386 }
5387
5388 /**
5389 * Called by the system to get the short support message.
5390 *
5391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5392 * @param userHandle user id the admin is running as.
5393 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5394 *
5395 * @hide
5396 */
5397 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5398 if (mService != null) {
5399 try {
5400 return mService.getShortSupportMessageForUser(admin, userHandle);
5401 } catch (RemoteException e) {
5402 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5403 }
5404 }
5405 return null;
5406 }
5407
5408
5409 /**
5410 * Called by the system to get the long support message.
5411 *
5412 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5413 * @param userHandle user id the admin is running as.
5414 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5415 *
5416 * @hide
5417 */
5418 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5419 if (mService != null) {
5420 try {
5421 return mService.getLongSupportMessageForUser(admin, userHandle);
5422 } catch (RemoteException e) {
5423 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5424 }
5425 }
5426 return null;
5427 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005428
5429 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005430 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5431 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005432 *
5433 * <p> Note only some methods will work on the parent Manager.
5434 *
5435 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5436 */
5437 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5438 try {
5439 if (!mService.isManagedProfile(admin)) {
5440 throw new SecurityException("The current user does not have a parent profile.");
5441 }
5442 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005443 } catch (RemoteException e) {
5444 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5445 return null;
5446 }
5447 }
5448
5449 /**
5450 * Called by device owner to control the device logging feature. Logging can only be
5451 * enabled on single user devices where the sole user is managed by the device owner.
5452 *
5453 * <p> Device logs contain various information intended for security auditing purposes.
5454 * See {@link SecurityEvent} for details.
5455 *
5456 * @param admin Which device owner this request is associated with.
5457 * @param enabled whether device logging should be enabled or not.
5458 * @see #retrieveDeviceLogs
5459 */
5460 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5461 try {
5462 mService.setDeviceLoggingEnabled(admin, enabled);
5463 } catch (RemoteException re) {
5464 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5465 }
5466 }
5467
5468 /**
5469 * Return whether device logging is enabled or not by the device owner.
5470 *
5471 * @param admin Which device owner this request is associated with.
5472 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5473 */
5474 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5475 try {
5476 return mService.getDeviceLoggingEnabled(admin);
5477 } catch (RemoteException re) {
5478 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5479 return false;
5480 }
5481 }
5482
5483 /**
5484 * Called by device owner to retrieve all new device logging entries since the last call to
5485 * this API after device boots.
5486 *
5487 * <p> Access to the logs is rate limited and it will only return new logs after the device
5488 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5489 *
5490 * @param admin Which device owner this request is associated with.
5491 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5492 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5493 */
5494 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5495 try {
5496 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5497 if (list != null) {
5498 return list.getList();
5499 } else {
5500 // Rate limit exceeded.
5501 return null;
5502 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005503 } catch (RemoteException re) {
5504 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5505 return null;
5506 }
5507 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005508
5509 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005510 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5511 * profile.
5512 *
5513 * @hide
5514 */
5515 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5516 mContext.checkSelfPermission(
5517 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5518 if (!uInfo.isManagedProfile()) {
5519 throw new SecurityException("The user " + uInfo.id
5520 + " does not have a parent profile.");
5521 }
5522 return new DevicePolicyManager(mContext, true);
5523 }
5524
5525 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005526 * Called by device owners to retrieve device logs from before the device's last reboot.
5527 *
5528 * <p>
5529 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5530 * corruption-free during power cycles, due to hardware variations and limitations. As a
5531 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5532 * </strong>
5533 *
5534 * @param admin Which device owner this request is associated with.
5535 * @return Device logs from before the latest reboot of the system.
5536 */
5537 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5538 try {
5539 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5540 return list.getList();
5541 } catch (RemoteException re) {
5542 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5543 return Collections.<SecurityEvent>emptyList();
5544 }
5545 }
5546
5547 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005548 * Called by a profile owner of a managed profile to set the color used for customization.
5549 * This color is used as background color of the confirm credentials screen for that user.
5550 * The default color is {@link android.graphics.Color#GRAY}.
5551 *
5552 * <p>The confirm credentials screen can be created using
5553 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5554 *
5555 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5556 * @param color The 32bit representation of the color to be used.
5557 */
5558 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5559 try {
5560 mService.setOrganizationColor(admin, color);
5561 } catch (RemoteException re) {
5562 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5563 }
5564 }
5565
5566 /**
5567 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5568 * This color is used as background color of the confirm credentials screen for that user.
5569 *
5570 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5571 * @return The 32bit representation of the color to be used.
5572 */
5573 public int getOrganizationColor(@NonNull ComponentName admin) {
5574 try {
5575 return mService.getOrganizationColor(admin);
5576 } catch (RemoteException re) {
5577 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5578 return 0;
5579 }
5580 }
5581
5582 /**
5583 * @hide
5584 * Retrieve the customization color for a given user.
5585 *
5586 * @param userHandle The user id of the user we're interested in.
5587 * @return The 32bit representation of the color to be used.
5588 */
5589 public int getOrganizationColorForUser(int userHandle) {
5590 try {
5591 return mService.getOrganizationColorForUser(userHandle);
5592 } catch (RemoteException re) {
5593 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5594 return 0;
5595 }
5596 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005597
5598 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005599 * Called by a profile owner of a managed profile to set the name of the organization under
5600 * management.
5601 *
5602 * <p>If the organization name needs to be localized, it is the responsibility of the
5603 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5604 * and set a new version of this string accordingly.
5605 *
5606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5607 * @param title The organization name or {@code null} to clear a previously set name.
5608 */
5609 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5610 try {
5611 mService.setOrganizationName(admin, title);
5612 } catch (RemoteException re) {
5613 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5614 }
5615 }
5616
5617 /**
5618 * Called by a profile owner of a managed profile to retrieve the name of the organization
5619 * under management.
5620 *
5621 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5622 * @return The organization name or {@code null} if none is set.
5623 */
5624 public String getOrganizationName(@NonNull ComponentName admin) {
5625 try {
5626 return mService.getOrganizationName(admin);
5627 } catch (RemoteException re) {
5628 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5629 return null;
5630 }
5631 }
5632
5633 /**
5634 * Retrieve the default title message used in the confirm credentials screen for a given user.
5635 *
5636 * @param userHandle The user id of the user we're interested in.
5637 * @return The organization name or {@code null} if none is set.
5638 *
5639 * @hide
5640 */
5641 public String getOrganizationNameForUser(int userHandle) {
5642 try {
5643 return mService.getOrganizationNameForUser(userHandle);
5644 } catch (RemoteException re) {
5645 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5646 return null;
5647 }
5648 }
5649
5650 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005651 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5652 * return {@link #STATE_USER_UNMANAGED}
5653 * @hide
5654 */
5655 @UserProvisioningState
5656 public int getUserProvisioningState() {
5657 if (mService != null) {
5658 try {
5659 return mService.getUserProvisioningState();
5660 } catch (RemoteException e) {
5661 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5662 }
5663 }
5664 return STATE_USER_UNMANAGED;
5665 }
5666
5667 /**
5668 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5669 *
5670 * @param state to store
5671 * @param userHandle for user
5672 * @hide
5673 */
5674 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5675 if (mService != null) {
5676 try {
5677 mService.setUserProvisioningState(state, userHandle);
5678 } catch (RemoteException e) {
5679 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5680 }
5681 }
5682 }
5683
5684 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005685 * @hide
5686 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5687 * affiliated if it is managed by the same entity as the device.
5688 *
5689 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5690 * user/profile is considered affiliated if the following conditions are both met:
5691 * <ul>
5692 * <li>The device owner and the user's/profile's profile owner have called this method,
5693 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5694 * and a profile owner intersect, they must have come from the same source, which means that
5695 * the device owner and profile owner are controlled by the same entity.</li>
5696 * <li>The device owner's and profile owner's package names are the same.</li>
5697 * </ul>
5698 *
5699 * @param admin Which profile or device owner this request is associated with.
5700 * @param ids A set of opaque affiliation ids.
5701 */
5702 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5703 try {
5704 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5705 } catch (RemoteException e) {
5706 Log.w(TAG, "Failed talking with device policy service", e);
5707 }
5708 }
5709
5710 /**
5711 * @hide
5712 * Returns whether this user/profile is affiliated with the device. See
5713 * {@link #setAffiliationIds} for the definition of affiliation.
5714 *
5715 * @return whether this user/profile is affiliated with the device.
5716 */
5717 public boolean isAffiliatedUser() {
5718 try {
5719 return mService != null && mService.isAffiliatedUser();
5720 } catch (RemoteException e) {
5721 Log.w(TAG, "Failed talking with device policy service", e);
5722 return false;
5723 }
5724 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005725
5726 /**
5727 * @hide
5728 * Returns whether the uninstall for {@code packageName} for the current user is in queue
5729 * to be started
5730 * @param packageName the package to check for
5731 * @return whether the uninstall intent for {@code packageName} is pending
5732 */
5733 public boolean isUninstallInQueue(String packageName) {
5734 try {
5735 return mService.isUninstallInQueue(packageName);
5736 } catch (RemoteException re) {
5737 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5738 return false;
5739 }
5740 }
5741
5742 /**
5743 * @hide
5744 * @param packageName the package containing active DAs to be uninstalled
5745 */
5746 public void uninstallPackageWithActiveAdmins(String packageName) {
5747 try {
5748 mService.uninstallPackageWithActiveAdmins(packageName);
5749 } catch (RemoteException re) {
5750 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5751 }
5752 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005753}