blob: a83ff426c78e4ceb09793a38ef5c520f0d93c475 [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
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000019import android.annotation.ColorInt;
Alan Treadwayafad8782016-01-19 15:15:08 +000020import android.annotation.IntDef;
Robin Lee25e26452015-06-02 09:56:29 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Dianne Hackbornd6847842010-01-12 18:14:19 -080023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050025import android.annotation.SystemApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000026import android.annotation.UserIdInt;
Jason Monkd7b86212014-06-16 13:15:38 -040027import android.app.Activity;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000028import android.auditing.SecurityLog;
29import android.auditing.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.content.ComponentName;
31import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010032import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000033import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000036import android.content.pm.ParceledListSlice;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.content.pm.ResolveInfo;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000038import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050039import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040040import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000041import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010042import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070043import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000044import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080045import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080046import android.os.RemoteException;
47import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070048import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040049import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000050import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000051import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010052import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070053import android.service.restrictions.RestrictionsReceiver;
Dianne Hackbornd6847842010-01-12 18:14:19 -080054import android.util.Log;
55
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070056import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040057import com.android.org.conscrypt.TrustedCertificateStore;
58
Jessica Hummel91da58d2014-04-10 17:39:43 +010059import org.xmlpull.v1.XmlPullParserException;
60
Maggie Benthallda51e682013-08-08 22:35:44 -040061import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080062import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000063import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070065import java.net.InetSocketAddress;
66import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010067import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000068import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010069import java.security.PrivateKey;
70import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040071import java.security.cert.CertificateException;
72import java.security.cert.CertificateFactory;
73import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010074import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000075import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070076import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070077import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080078import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010079import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080080
81/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000082 * Public interface for managing policies enforced on a device. Most clients of this class must be
83 * registered with the system as a
Benjamin Franz6cdb27e2015-02-26 12:26:53 +000084 * <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a>. Additionally,
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000085 * a device administrator may be registered as either a profile or device owner. A given method is
86 * accessible to all device administrators unless the documentation for that method specifies that
87 * it is restricted to either device or profile owners.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080088 *
89 * <div class="special reference">
90 * <h3>Developer Guides</h3>
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000091 * <p>For more information about managing policies for device administration, read the
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080092 * <a href="{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a>
Robin Lee25e26452015-06-02 09:56:29 -070093 * developer guide.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080094 * </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080095 */
96public class DevicePolicyManager {
97 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080098
99 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000101 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700102
Makoto Onukic8a5a552015-11-19 14:29:12 -0800103 private static final String REMOTE_EXCEPTION_MESSAGE =
104 "Failed to talk with device policy manager service";
105
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000106 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000107 this(context,
108 IDevicePolicyManager.Stub.asInterface(
109 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
110 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800111 }
112
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800113 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000115 protected DevicePolicyManager(
116 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 mContext = context;
118 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000119 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120 }
121
122 /** @hide */
123 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000124 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800125 return me.mService != null ? me : null;
126 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700127
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700128 /** @hide test will override it. */
129 @VisibleForTesting
130 protected int myUserId() {
131 return UserHandle.myUserId();
132 }
133
Dianne Hackbornd6847842010-01-12 18:14:19 -0800134 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000135 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000136 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100137 * <p>A managed profile allows data separation for example for the usage of a
138 * device as a personal and corporate device. The user which provisioning is started from and
139 * the managed profile share a launcher.
140 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800141 * <p>This intent will typically be sent by a mobile device management application (MDM).
142 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
143 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100144 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000145 * <p>It is possible to check if provisioning is allowed or not by querying the method
146 * {@link #isProvisioningAllowed(String)}.
147 *
148 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000149 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700150 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000151 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
152 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000153 *
154 * <p> The intent may also contain the following extras:
155 * <ul>
156 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
157 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
158 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000159 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000160 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
161 * in the provisioning intent. The
162 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
163 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
164 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100165 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100166 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
167 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100168 *
169 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
170 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
171 * the provisioning flow was successful, although this doesn't guarantee the full flow will
172 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
173 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000174 */
175 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
176 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100177 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000178
179 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000180 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000181 * Activity action: Starts the provisioning flow which sets up a managed user.
182 *
183 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800184 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000185 * owner who has full control over the user. Provisioning can only happen before user setup has
186 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
187 * allowed.
188 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000189 * <p>This intent should contain the extra
190 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000191 *
192 * <p> If provisioning fails, the device returns to its previous state.
193 *
194 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
195 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
196 * the provisioning flow was successful, although this doesn't guarantee the full flow will
197 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
198 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000199 */
200 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
201 public static final String ACTION_PROVISION_MANAGED_USER
202 = "android.app.action.PROVISION_MANAGED_USER";
203
204 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 * Activity action: Starts the provisioning flow which sets up a managed device.
206 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
207 *
208 * <p> During device owner provisioning a device admin app is set as the owner of the device.
209 * A device owner has full control over the device. The device owner can not be modified by the
210 * user.
211 *
212 * <p> A typical use case would be a device that is owned by a company, but used by either an
213 * employee or client.
214 *
215 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000216 * It is possible to check if provisioning is allowed or not by querying the method
217 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100218 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000219 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100220 * <ul>
221 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
222 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
223 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100224 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000225 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000226 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100227 * </ul>
228 *
229 * <p> When device owner provisioning has completed, an intent of the type
230 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
231 * device owner.
232 *
233 * <p> If provisioning fails, the device is factory reset.
234 *
Alan Treadway4582f812015-07-28 11:49:35 +0100235 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
236 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
237 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
238 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 */
240 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
241 public static final String ACTION_PROVISION_MANAGED_DEVICE
242 = "android.app.action.PROVISION_MANAGED_DEVICE";
243
244 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000245 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000246 *
247 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
248 * the device. A device owner has full control over the device. The device owner can not be
249 * modified by the user and the only way of resetting the device is via factory reset.
250 *
251 * <p>A typical use case would be a device that is owned by a company, but used by either an
252 * employee or client.
253 *
254 * <p>The provisioning message should be sent to an unprovisioned device.
255 *
256 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
257 * by a privileged app with the permission
258 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
259 *
260 * <p>The provisioning intent contains the following properties:
261 * <ul>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
263 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
278 *
279 * @hide
280 */
281 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
282 @SystemApi
283 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
284 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
285
286 /**
287 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000288 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
289 *
290 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
291 * management state that is distinct from that reached by
292 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
293 * user, and only has control over device-wide policies, not individual users and their data.
294 * The primary benefit is that multiple non-system users are supported when provisioning using
295 * this form of device management.
296 *
297 * <p> During device owner provisioning a device admin app is set as the owner of the device.
298 * A device owner has full control over the device. The device owner can not be modified by the
299 * user.
300 *
301 * <p> A typical use case would be a device that is owned by a company, but used by either an
302 * employee or client.
303 *
304 * <p> An intent with this action can be sent only on an unprovisioned device.
305 * It is possible to check if provisioning is allowed or not by querying the method
306 * {@link #isProvisioningAllowed(String)}.
307 *
308 * <p>The intent contains the following extras:
309 * <ul>
310 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
311 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
314 * </ul>
315 *
316 * <p> When device owner provisioning has completed, an intent of the type
317 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
318 * device owner.
319 *
320 * <p> If provisioning fails, the device is factory reset.
321 *
322 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
323 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
324 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
325 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
326 *
327 * @hide
328 */
329 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
330 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
331 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
332
333 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000334 * Activity action: Finalizes management provisioning, should be used after user-setup
335 * has been completed and {@link #getUserProvisioningState()} returns one of:
336 * <ul>
337 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
338 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
339 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
340 * </ul>
341 *
342 * @hide
343 */
344 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
345 public static final String ACTION_PROVISION_FINALIZATION
346 = "android.app.action.PROVISION_FINALIZATION";
347
348 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100349 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100350 * allows a mobile device management application or NFC programmer application which starts
351 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100352 * <p>
353 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
354 * sends the intent to pass data to itself on the newly created profile.
355 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
356 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100357 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
358 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
359 * message should contain a stringified {@link java.util.Properties} instance, whose string
360 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
361 * management application after provisioning.
362 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100363 * <p>
364 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700365 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
366 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100367 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100368 */
369 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100370 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100371
372 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100373 * A String extra holding the package name of the mobile device management application that
374 * will be set as the profile owner or device owner.
375 *
376 * <p>If an application starts provisioning directly via an intent with action
377 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
378 * application that started provisioning. The package will be set as profile owner in that case.
379 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000380 * <p>This package is set as device owner when device owner provisioning is started by an NFC
381 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000382 *
383 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700384 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000385
386 * @see DeviceAdminReceiver
387 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100388 * supported, but only if there is only one device admin receiver in the package that requires
389 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000390 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000391 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000392 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100393 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000394
395 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000396 * A ComponentName extra indicating the device admin receiver of the mobile device management
397 * application that will be set as the profile owner or device owner and active admin.
398 *
399 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100400 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
401 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
402 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000403 *
404 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100405 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
406 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400407 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000408 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000409 *
410 * @see DeviceAdminReceiver
411 */
412 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
413 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
414
415 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000416 * An {@link android.accounts.Account} extra holding the account to migrate during managed
417 * profile provisioning. If the account supplied is present in the primary user, it will be
418 * copied, along with its credentials to the managed profile and removed from the primary user.
419 *
420 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
421 */
422
423 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
424 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
425
426 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100427 * A String extra that, holds the email address of the account which a managed profile is
428 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
429 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100430 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100431 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
432 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100433 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
434 * contains this extra, it is forwarded in the
435 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
436 * device management application that was set as the profile owner during provisioning.
437 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100438 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100439 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
440 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100441
442 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000443 * A integer extra indicating the predominant color to show during the provisioning.
444 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000445 *
446 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
447 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
448 */
449 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
450 "android.app.extra.PROVISIONING_MAIN_COLOR";
451
452 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000453 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700454 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000455 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100456 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
457 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000458 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000459 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
460 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000461
462 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100463 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
464 * will be set to.
465 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000466 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
467 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100468 */
469 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100470 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100471
472 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100473 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
474 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100475 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000476 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
477 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100478 */
479 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100480 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100481
482 /**
483 * A String extra holding the {@link java.util.Locale} that the device will be set to.
484 * Format: xx_yy, where xx is the language code, and yy the country code.
485 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000486 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
487 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100488 */
489 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100490 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100491
492 /**
493 * A String extra holding the ssid of the wifi network that should be used during nfc device
494 * owner provisioning for downloading the mobile device management application.
495 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000496 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
497 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100498 */
499 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100500 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100501
502 /**
503 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
504 * is hidden or not.
505 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000506 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
507 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100508 */
509 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100510 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100511
512 /**
513 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100514 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
515 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100516 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000517 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
518 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100519 */
520 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100521 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100522
523 /**
524 * A String extra holding the password of the wifi network in
525 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
526 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000527 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
528 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100529 */
530 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100531 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100532
533 /**
534 * A String extra holding the proxy host for the wifi network in
535 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
536 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000537 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
538 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100539 */
540 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100541 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100542
543 /**
544 * An int extra holding the proxy port for the wifi network in
545 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
546 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000547 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
548 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100549 */
550 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100551 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100552
553 /**
554 * A String extra holding the proxy bypass for the wifi network in
555 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
556 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000557 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
558 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100559 */
560 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100561 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100562
563 /**
564 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
565 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
566 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000567 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
568 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100569 */
570 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100571 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572
573 /**
574 * A String extra holding a url that specifies the download location of the device admin
575 * package. When not provided it is assumed that the device admin package is already installed.
576 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000577 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
578 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 */
580 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100581 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582
583 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400584 * An int extra holding a minimum required version code for the device admin package. If the
585 * device admin is already installed on the device, it will only be re-downloaded from
586 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
587 * installed package is less than this version code.
588 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400589 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400590 * provisioning via an NFC bump.
591 */
592 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
593 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
594
595 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100596 * A String extra holding a http cookie header which should be used in the http request to the
597 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
598 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000599 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
600 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100601 */
602 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100603 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100604
605 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100606 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
607 * the file at download location specified in
608 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100609 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100610 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100611 * present. The provided checksum should match the checksum of the file at the download
612 * location. If the checksum doesn't match an error will be shown to the user and the user will
613 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100614 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000615 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
616 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100617 *
618 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
619 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700620 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100621 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 */
623 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100624 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625
626 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100627 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100628 * android package archive at the download location specified in {@link
629 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
630 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100631 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100632 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
633 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
634 *
635 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100636 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100637 * the download location. If the checksum does not match an error will be shown to the user and
638 * the user will be asked to factory reset the device.
639 *
640 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
641 * provisioning via an NFC bump.
642 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100643 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
644 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100645
646 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000647 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
648 * has completed successfully.
649 *
650 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700651 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000652 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800653 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000654 * corresponds to the account requested to be migrated at provisioning time, if any.
655 */
656 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
657 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
658 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
659
660 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400661 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500662 * provisioning.
663 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400664 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100665 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500666 */
667 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
668 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
669
670 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000671 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
672 * provisioning. If this extra is not passed, a default image will be shown.
673 * <h5>The following URI schemes are accepted:</h5>
674 * <ul>
675 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
676 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
677 * </ul>
678 *
679 * <p> It is the responsability of the caller to provide an image with a reasonable
680 * pixed density for the device.
681 *
682 * <p> If a content: URI is passed, the intent should have the flag
683 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
684 * {@link android.content.ClipData} of the intent too.
685 *
686 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
687 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
688 */
689 public static final String EXTRA_PROVISIONING_LOGO_URI =
690 "android.app.extra.PROVISIONING_LOGO_URI";
691
692 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000693 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
694 * during setup-wizard.
695 *
696 * <p>If unspecified, defaults to {@code true} to match the behavior in
697 * {@link android.os.Build.VERSION_CODES#M} and earlier.
698 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000699 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
700 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000701 *
702 * @hide
703 */
704 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
705 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
706
707 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400708 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100709 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400710 * <p>During device owner provisioning a device admin app is set as the owner of the device.
711 * A device owner has full control over the device. The device owner can not be modified by the
712 * user and the only way of resetting the device is if the device owner app calls a factory
713 * reset.
714 *
715 * <p> A typical use case would be a device that is owned by a company, but used by either an
716 * employee or client.
717 *
718 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100719 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000720 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100721 * contains the following properties:
722 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400723 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
724 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100725 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400726 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100727 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
728 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
729 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
730 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
731 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
732 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
733 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
734 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
735 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
736 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100737 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
738 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
739 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100740 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000741 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700742 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400743 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
744 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
745 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400746 */
747 public static final String MIME_TYPE_PROVISIONING_NFC
748 = "application/com.android.managedprovisioning";
749
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100750 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800751 * Activity action: ask the user to add a new device administrator to the system.
752 * The desired policy is the ComponentName of the policy in the
753 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
754 * bring the user through adding the device administrator to the system (or
755 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700756 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800757 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
758 * field to provide the user with additional explanation (in addition
759 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800760 *
761 * <p>If your administrator is already active, this will ordinarily return immediately (without
762 * user intervention). However, if your administrator has been updated and is requesting
763 * additional uses-policy flags, the user will be presented with the new list. New policies
764 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800765 */
766 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
767 public static final String ACTION_ADD_DEVICE_ADMIN
768 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700769
Dianne Hackbornd6847842010-01-12 18:14:19 -0800770 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700771 * @hide
772 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700773 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700774 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700775 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
776 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700777 * to remotely control restrictions on the user.
778 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800779 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700780 * result of whether or not the user approved the action. If approved, the result will
781 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
782 * as a profile owner.
783 *
784 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
785 * field to provide the user with additional explanation (in addition
786 * to your component's description) about what is being added.
787 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700788 * <p>If there is already a profile owner active or the caller is not a system app, the
789 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700790 */
791 @SystemApi
792 public static final String ACTION_SET_PROFILE_OWNER
793 = "android.app.action.SET_PROFILE_OWNER";
794
795 /**
796 * @hide
797 * Name of the profile owner admin that controls the user.
798 */
799 @SystemApi
800 public static final String EXTRA_PROFILE_OWNER_NAME
801 = "android.app.extra.PROFILE_OWNER_NAME";
802
803 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100804 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700805 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700806 *
Jim Miller284b62e2010-06-08 14:27:42 -0700807 * @hide
808 */
809 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
810 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
811
812 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100813 * Broadcast action: sent when the device owner is set or changed.
814 *
815 * This broadcast is sent only to the primary user.
816 * @see #ACTION_PROVISION_MANAGED_DEVICE
817 */
818 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
819 public static final String ACTION_DEVICE_OWNER_CHANGED
820 = "android.app.action.DEVICE_OWNER_CHANGED";
821
822 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 * The ComponentName of the administrator component.
824 *
825 * @see #ACTION_ADD_DEVICE_ADMIN
826 */
827 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700828
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800830 * An optional CharSequence providing additional explanation for why the
831 * admin is being added.
832 *
833 * @see #ACTION_ADD_DEVICE_ADMIN
834 */
835 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700836
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800837 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700838 * Activity action: have the user enter a new password. This activity should
839 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
840 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
841 * enter a new password that meets the current requirements. You can use
842 * {@link #isActivePasswordSufficient()} to determine whether you need to
843 * have the user select a new password in order to meet the current
844 * constraints. Upon being resumed from this activity, you can check the new
845 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000846 *
847 * If the intent is launched from within a managed profile with a profile
848 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
849 * this will trigger entering a new password for the parent of the profile.
850 * For all other cases it will trigger entering a new password for the user
851 * or profile it is launched from.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800852 */
853 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
854 public static final String ACTION_SET_NEW_PASSWORD
855 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700856
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000857 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000858 * Activity action: have the user enter a new password for the parent profile.
859 * If the intent is launched from within a managed profile, this will trigger
860 * entering a new password for the parent of the profile. In all other cases
861 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
862 */
863 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
864 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
865 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
866
867 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000868 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
869 * the parent profile to access intents sent from the managed profile.
870 * That is, when an app in the managed profile calls
871 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
872 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000873 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100874 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000875
876 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000877 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
878 * the managed profile to access intents sent from the parent profile.
879 * That is, when an app in the parent profile calls
880 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
881 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000882 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100883 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700884
Dianne Hackbornd6847842010-01-12 18:14:19 -0800885 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100886 * Broadcast action: notify that a new local system update policy has been set by the device
887 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000888 */
889 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100890 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
891 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000892
Amith Yamasanid49489b2015-04-28 14:00:26 -0700893 /**
894 * Permission policy to prompt user for new permission requests for runtime permissions.
895 * Already granted or denied permissions are not affected by this.
896 */
897 public static final int PERMISSION_POLICY_PROMPT = 0;
898
899 /**
900 * Permission policy to always grant new permission requests for runtime permissions.
901 * Already granted or denied permissions are not affected by this.
902 */
903 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
904
905 /**
906 * Permission policy to always deny new permission requests for runtime permissions.
907 * Already granted or denied permissions are not affected by this.
908 */
909 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
910
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700911 /**
912 * Runtime permission state: The user can manage the permission
913 * through the UI.
914 */
915 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
916
917 /**
918 * Runtime permission state: The permission is granted to the app
919 * and the user cannot manage the permission through the UI.
920 */
921 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
922
923 /**
924 * Runtime permission state: The permission is denied to the app
925 * and the user cannot manage the permission through the UI.
926 */
927 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +0000928
929 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000930 * No management for current user in-effect. This is the default.
931 * @hide
932 */
933 public static final int STATE_USER_UNMANAGED = 0;
934
935 /**
936 * Management partially setup, user setup needs to be completed.
937 * @hide
938 */
939 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
940
941 /**
942 * Management partially setup, user setup completed.
943 * @hide
944 */
945 public static final int STATE_USER_SETUP_COMPLETE = 2;
946
947 /**
948 * Management setup and active on current user.
949 * @hide
950 */
951 public static final int STATE_USER_SETUP_FINALIZED = 3;
952
953 /**
954 * Management partially setup on a managed profile.
955 * @hide
956 */
957 public static final int STATE_USER_PROFILE_COMPLETE = 4;
958
959 /**
960 * @hide
961 */
962 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
963 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
964 @Retention(RetentionPolicy.SOURCE)
965 public @interface UserProvisioningState {}
966
967 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800968 * Return true if the given administrator component is currently
969 * active (enabled) in the system.
970 */
Robin Lee25e26452015-06-02 09:56:29 -0700971 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700972 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100973 }
974
975 /**
976 * @see #isAdminActive(ComponentName)
977 * @hide
978 */
Robin Lee25e26452015-06-02 09:56:29 -0700979 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800980 if (mService != null) {
981 try {
Robin Lee25e26452015-06-02 09:56:29 -0700982 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800983 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800984 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 }
986 }
987 return false;
988 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800989 /**
990 * Return true if the given administrator component is currently being removed
991 * for the user.
992 * @hide
993 */
Robin Lee25e26452015-06-02 09:56:29 -0700994 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800995 if (mService != null) {
996 try {
Robin Lee25e26452015-06-02 09:56:29 -0700997 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800998 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -0800999 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001000 }
1001 }
1002 return false;
1003 }
1004
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001005
Dianne Hackbornd6847842010-01-12 18:14:19 -08001006 /**
Robin Lee25e26452015-06-02 09:56:29 -07001007 * Return a list of all currently active device administrators' component
1008 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001009 * returned.
1010 */
1011 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001012 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001013 }
1014
1015 /**
1016 * @see #getActiveAdmins()
1017 * @hide
1018 */
1019 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001020 if (mService != null) {
1021 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001022 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001023 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001024 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001025 }
1026 }
1027 return null;
1028 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001029
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001030 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001031 * Used by package administration code to determine if a package can be stopped
1032 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001033 * @hide
1034 */
1035 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001036 return packageHasActiveAdmins(packageName, myUserId());
1037 }
1038
1039 /**
1040 * Used by package administration code to determine if a package can be stopped
1041 * or uninstalled.
1042 * @hide
1043 */
1044 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001045 if (mService != null) {
1046 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001047 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001048 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001049 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001050 }
1051 }
1052 return false;
1053 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001054
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001055 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 * Remove a current administration component. This can only be called
1057 * by the application that owns the administration component; if you
1058 * try to remove someone else's component, a security exception will be
1059 * thrown.
1060 */
Robin Lee25e26452015-06-02 09:56:29 -07001061 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001062 if (mService != null) {
1063 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001064 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001065 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001066 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001067 }
1068 }
1069 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001070
Dianne Hackbornd6847842010-01-12 18:14:19 -08001071 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001072 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001073 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001074 * but requires additional policies after an upgrade.
1075 *
1076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1077 * an active administrator, or an exception will be thrown.
1078 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001081 if (mService != null) {
1082 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001083 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001084 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001085 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001086 }
1087 }
1088 return false;
1089 }
1090
1091 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001092 * Returns true if the Profile Challenge is available to use for the given profile user.
1093 *
1094 * @hide
1095 */
1096 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1097 if (mService != null) {
1098 try {
1099 return mService.isSeparateProfileChallengeAllowed(userHandle);
1100 } catch (RemoteException e) {
1101 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1102 }
1103 }
1104 return false;
1105 }
1106
1107 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001108 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1109 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001110 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001111 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001112 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001113
Dianne Hackbornd6847842010-01-12 18:14:19 -08001114 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001115 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1116 * recognition technology. This implies technologies that can recognize the identity of
1117 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1118 * Note that quality constants are ordered so that higher values are more restrictive.
1119 */
1120 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1121
1122 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001123 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001124 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001125 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001126 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001127 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001128
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001129 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001130 * Constant for {@link #setPasswordQuality}: the user must have entered a
1131 * password containing at least numeric characters. Note that quality
1132 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001133 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001134 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001135
Dianne Hackbornd6847842010-01-12 18:14:19 -08001136 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001137 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001138 * password containing at least numeric characters with no repeating (4444)
1139 * or ordered (1234, 4321, 2468) sequences. Note that quality
1140 * constants are ordered so that higher values are more restrictive.
1141 */
1142 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1143
1144 /**
1145 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001146 * password containing at least alphabetic (or other symbol) characters.
1147 * Note that quality constants are ordered so that higher values are more
1148 * restrictive.
1149 */
1150 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001151
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001152 /**
1153 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001154 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001155 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001156 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001157 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001158 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159
Dianne Hackbornd6847842010-01-12 18:14:19 -08001160 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001161 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001162 * password containing at least a letter, a numerical digit and a special
1163 * symbol, by default. With this password quality, passwords can be
1164 * restricted to contain various sets of characters, like at least an
1165 * uppercase letter, etc. These are specified using various methods,
1166 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1167 * that quality constants are ordered so that higher values are more
1168 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 */
1170 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1171
1172 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001173 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1174 * modify password. In case this password quality is set, the password is
1175 * managed by a profile owner. The profile owner can set any password,
1176 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1177 * that quality constants are ordered so that higher values are more
1178 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1179 * the highest.
1180 * @hide
1181 */
1182 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1183
1184 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001185 * Called by an application that is administering the device to set the
1186 * password restrictions it is imposing. After setting this, the user
1187 * will not be able to enter a new password that is not at least as
1188 * restrictive as what has been set. Note that the current password
1189 * will remain until the user has set a new one, so the change does not
1190 * take place immediately. To prompt the user for a new password, use
1191 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001192 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001193 * <p>Quality constants are ordered so that higher values are more restrictive;
1194 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001195 * the user's preference, and any other considerations) is the one that
1196 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001197 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001198 * <p>The calling device admin must have requested
1199 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1200 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001201 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001202 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001203 * @param quality The new desired quality. One of
1204 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001205 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1206 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1207 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001208 */
Robin Lee25e26452015-06-02 09:56:29 -07001209 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001210 if (mService != null) {
1211 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001212 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001213 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001214 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001215 }
1216 }
1217 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001218
Dianne Hackbornd6847842010-01-12 18:14:19 -08001219 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001220 * Retrieve the current minimum password quality for all admins of this user
1221 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001222 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001223 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001224 */
Robin Lee25e26452015-06-02 09:56:29 -07001225 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001226 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001227 }
1228
1229 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001230 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001231 if (mService != null) {
1232 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001233 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001234 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001235 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001236 }
1237 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001238 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001239 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001240
Dianne Hackbornd6847842010-01-12 18:14:19 -08001241 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001242 * Called by an application that is administering the device to set the
1243 * minimum allowed password length. After setting this, the user
1244 * will not be able to enter a new password that is not at least as
1245 * restrictive as what has been set. Note that the current password
1246 * will remain until the user has set a new one, so the change does not
1247 * take place immediately. To prompt the user for a new password, use
1248 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1249 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001250 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1251 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1252 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001253 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001254 * <p>The calling device admin must have requested
1255 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1256 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001257 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001259 * @param length The new desired minimum password length. A value of 0
1260 * means there is no restriction.
1261 */
Robin Lee25e26452015-06-02 09:56:29 -07001262 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001263 if (mService != null) {
1264 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001265 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001266 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001267 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001268 }
1269 }
1270 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001271
Dianne Hackbornd6847842010-01-12 18:14:19 -08001272 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001273 * Retrieve the current minimum password length for all admins of this
1274 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001275 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001276 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001277 */
Robin Lee25e26452015-06-02 09:56:29 -07001278 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001279 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001280 }
1281
1282 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001283 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001284 if (mService != null) {
1285 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001286 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001287 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001288 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001289 }
1290 }
1291 return 0;
1292 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001293
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001294 /**
1295 * Called by an application that is administering the device to set the
1296 * minimum number of upper case letters required in the password. After
1297 * setting this, the user will not be able to enter a new password that is
1298 * not at least as restrictive as what has been set. Note that the current
1299 * password will remain until the user has set a new one, so the change does
1300 * not take place immediately. To prompt the user for a new password, use
1301 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1302 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001303 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1304 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001305 * <p>
1306 * The calling device admin must have requested
1307 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1308 * this method; if it has not, a security exception will be thrown.
1309 *
1310 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1311 * with.
1312 * @param length The new desired minimum number of upper case letters
1313 * required in the password. A value of 0 means there is no
1314 * restriction.
1315 */
Robin Lee25e26452015-06-02 09:56:29 -07001316 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001317 if (mService != null) {
1318 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001319 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001320 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001321 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001322 }
1323 }
1324 }
1325
1326 /**
1327 * Retrieve the current number of upper case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001328 * password for all admins of this user and its profiles or a particular one.
1329 * This is the same value as set by
1330 * {#link {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001331 * and only applies when the password quality is
1332 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001333 *
Robin Lee25e26452015-06-02 09:56:29 -07001334 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001335 * aggregate all admins.
1336 * @return The minimum number of upper case letters required in the
1337 * password.
1338 */
Robin Lee25e26452015-06-02 09:56:29 -07001339 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001340 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001341 }
1342
1343 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001344 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001345 if (mService != null) {
1346 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001347 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001348 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001349 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001350 }
1351 }
1352 return 0;
1353 }
1354
1355 /**
1356 * Called by an application that is administering the device to set the
1357 * minimum number of lower case letters required in the password. After
1358 * setting this, the user will not be able to enter a new password that is
1359 * not at least as restrictive as what has been set. Note that the current
1360 * password will remain until the user has set a new one, so the change does
1361 * not take place immediately. To prompt the user for a new password, use
1362 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1363 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001364 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1365 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001366 * <p>
1367 * The calling device admin must have requested
1368 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1369 * this method; if it has not, a security exception will be thrown.
1370 *
1371 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1372 * with.
1373 * @param length The new desired minimum number of lower case letters
1374 * required in the password. A value of 0 means there is no
1375 * restriction.
1376 */
Robin Lee25e26452015-06-02 09:56:29 -07001377 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001378 if (mService != null) {
1379 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001380 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001381 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001382 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001383 }
1384 }
1385 }
1386
1387 /**
1388 * Retrieve the current number of lower case letters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001389 * password for all admins of this user and its profiles or a particular one.
1390 * This is the same value as set by
1391 * {#link {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001392 * and only applies when the password quality is
1393 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001394 *
Robin Lee25e26452015-06-02 09:56:29 -07001395 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001396 * aggregate all admins.
1397 * @return The minimum number of lower case letters required in the
1398 * password.
1399 */
Robin Lee25e26452015-06-02 09:56:29 -07001400 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001401 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001402 }
1403
1404 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001405 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001406 if (mService != null) {
1407 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001408 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001409 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001410 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001411 }
1412 }
1413 return 0;
1414 }
1415
1416 /**
1417 * Called by an application that is administering the device to set the
1418 * minimum number of letters required in the password. After setting this,
1419 * the user will not be able to enter a new password that is not at least as
1420 * restrictive as what has been set. Note that the current password will
1421 * remain until the user has set a new one, so the change does not take
1422 * place immediately. To prompt the user for a new password, use
1423 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1424 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001425 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1426 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001427 * <p>
1428 * The calling device admin must have requested
1429 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1430 * this method; if it has not, a security exception will be thrown.
1431 *
1432 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1433 * with.
1434 * @param length The new desired minimum number of letters required in the
1435 * password. A value of 0 means there is no restriction.
1436 */
Robin Lee25e26452015-06-02 09:56:29 -07001437 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001438 if (mService != null) {
1439 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001440 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001441 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001442 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 }
1444 }
1445 }
1446
1447 /**
1448 * Retrieve the current number of letters required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001449 * admins or a particular one. This is the same value as
1450 * set by {#link {@link #setPasswordMinimumLetters(ComponentName, int)}
1451 * and only applies when the password quality is
1452 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001453 *
Robin Lee25e26452015-06-02 09:56:29 -07001454 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001455 * aggregate all admins.
1456 * @return The minimum number of letters required in the password.
1457 */
Robin Lee25e26452015-06-02 09:56:29 -07001458 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001459 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001460 }
1461
1462 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001463 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001464 if (mService != null) {
1465 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001466 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001467 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001468 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001469 }
1470 }
1471 return 0;
1472 }
1473
1474 /**
1475 * Called by an application that is administering the device to set the
1476 * minimum number of numerical digits required in the password. After
1477 * setting this, the user will not be able to enter a new password that is
1478 * not at least as restrictive as what has been set. Note that the current
1479 * password will remain until the user has set a new one, so the change does
1480 * not take place immediately. To prompt the user for a new password, use
1481 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1482 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001483 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1484 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001485 * <p>
1486 * The calling device admin must have requested
1487 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1488 * this method; if it has not, a security exception will be thrown.
1489 *
1490 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1491 * with.
1492 * @param length The new desired minimum number of numerical digits required
1493 * in the password. A value of 0 means there is no restriction.
1494 */
Robin Lee25e26452015-06-02 09:56:29 -07001495 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001496 if (mService != null) {
1497 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001498 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001499 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001500 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 }
1502 }
1503 }
1504
1505 /**
1506 * Retrieve the current number of numerical digits required in the password
Jessica Hummel91da58d2014-04-10 17:39:43 +01001507 * for all admins of this user and its profiles or a particular one.
1508 * This is the same value as set by
1509 * {#link {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001510 * and only applies when the password quality is
1511 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001512 *
Robin Lee25e26452015-06-02 09:56:29 -07001513 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001514 * aggregate all admins.
1515 * @return The minimum number of numerical digits required in the password.
1516 */
Robin Lee25e26452015-06-02 09:56:29 -07001517 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001518 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001519 }
1520
1521 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001522 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001523 if (mService != null) {
1524 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001525 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001526 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001527 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001528 }
1529 }
1530 return 0;
1531 }
1532
1533 /**
1534 * Called by an application that is administering the device to set the
1535 * minimum number of symbols required in the password. After setting this,
1536 * the user will not be able to enter a new password that is not at least as
1537 * restrictive as what has been set. Note that the current password will
1538 * remain until the user has set a new one, so the change does not take
1539 * place immediately. To prompt the user for a new password, use
1540 * {@link #ACTION_SET_NEW_PASSWORD} after setting this value. This
1541 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001542 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1543 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001544 * <p>
1545 * The calling device admin must have requested
1546 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1547 * this method; if it has not, a security exception will be thrown.
1548 *
1549 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1550 * with.
1551 * @param length The new desired minimum number of symbols required in the
1552 * password. A value of 0 means there is no restriction.
1553 */
Robin Lee25e26452015-06-02 09:56:29 -07001554 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001555 if (mService != null) {
1556 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001557 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001558 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001559 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001560 }
1561 }
1562 }
1563
1564 /**
1565 * Retrieve the current number of symbols required in the password for all
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001566 * admins or a particular one. This is the same value as
1567 * set by {#link {@link #setPasswordMinimumSymbols(ComponentName, int)}
1568 * and only applies when the password quality is
1569 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001570 *
Robin Lee25e26452015-06-02 09:56:29 -07001571 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001572 * aggregate all admins.
1573 * @return The minimum number of symbols required in the password.
1574 */
Robin Lee25e26452015-06-02 09:56:29 -07001575 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001576 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001577 }
1578
1579 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001580 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001581 if (mService != null) {
1582 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001583 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001584 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001585 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001586 }
1587 }
1588 return 0;
1589 }
1590
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001591 /**
1592 * Called by an application that is administering the device to set the
1593 * minimum number of non-letter characters (numerical digits or symbols)
1594 * required in the password. After setting this, the user will not be able
1595 * to enter a new password that is not at least as restrictive as what has
1596 * been set. Note that the current password will remain until the user has
1597 * set a new one, so the change does not take place immediately. To prompt
1598 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} after
1599 * setting this value. This constraint is only imposed if the administrator
1600 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1601 * {@link #setPasswordQuality}. The default value is 0.
1602 * <p>
1603 * The calling device admin must have requested
1604 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1605 * this method; if it has not, a security exception will be thrown.
1606 *
1607 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1608 * with.
1609 * @param length The new desired minimum number of letters required in the
1610 * password. A value of 0 means there is no restriction.
1611 */
Robin Lee25e26452015-06-02 09:56:29 -07001612 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001613 if (mService != null) {
1614 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001615 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001616 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001617 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001618 }
1619 }
1620 }
1621
1622 /**
1623 * Retrieve the current number of non-letter characters required in the
Jessica Hummel91da58d2014-04-10 17:39:43 +01001624 * password for all admins of this user and its profiles or a particular one.
1625 * This is the same value as set by
1626 * {#link {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001627 * and only applies when the password quality is
1628 * {@link #PASSWORD_QUALITY_COMPLEX}.
1629 *
Robin Lee25e26452015-06-02 09:56:29 -07001630 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001631 * aggregate all admins.
1632 * @return The minimum number of letters required in the password.
1633 */
Robin Lee25e26452015-06-02 09:56:29 -07001634 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001635 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001636 }
1637
1638 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001639 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001640 if (mService != null) {
1641 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001642 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001643 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001644 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001645 }
1646 }
1647 return 0;
1648 }
1649
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001650 /**
1651 * Called by an application that is administering the device to set the length
1652 * of the password history. After setting this, the user will not be able to
1653 * enter a new password that is the same as any password in the history. Note
1654 * that the current password will remain until the user has set a new one, so
1655 * the change does not take place immediately. To prompt the user for a new
1656 * password, use {@link #ACTION_SET_NEW_PASSWORD} after setting this value.
1657 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001658 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1659 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1660 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001661 *
1662 * <p>
1663 * The calling device admin must have requested
1664 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1665 * method; if it has not, a security exception will be thrown.
1666 *
1667 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1668 * with.
1669 * @param length The new desired length of password history. A value of 0
1670 * means there is no restriction.
1671 */
Robin Lee25e26452015-06-02 09:56:29 -07001672 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001673 if (mService != null) {
1674 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001675 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001676 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001677 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001678 }
1679 }
1680 }
1681
1682 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001683 * Called by a device admin to set the password expiration timeout. Calling this method
1684 * will restart the countdown for password expiration for the given admin, as will changing
1685 * the device password (for all admins).
1686 *
1687 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1688 * For example, to have the password expire 5 days from now, timeout would be
1689 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1690 *
1691 * <p>To disable password expiration, a value of 0 may be used for timeout.
1692 *
Jim Millera4e28d12010-11-08 16:15:47 -08001693 * <p>The calling device admin must have requested
1694 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1695 * method; if it has not, a security exception will be thrown.
1696 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001697 * <p> Note that setting the password will automatically reset the expiration time for all
1698 * active admins. Active admins do not need to explicitly call this method in that case.
1699 *
Jim Millera4e28d12010-11-08 16:15:47 -08001700 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1701 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1702 * means there is no restriction (unlimited).
1703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001705 if (mService != null) {
1706 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001707 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001708 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001709 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001710 }
1711 }
1712 }
1713
1714 /**
Jim Miller6b857682011-02-16 16:27:41 -08001715 * Get the password expiration timeout for the given admin. The expiration timeout is the
1716 * recurring expiration timeout provided in the call to
1717 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Robin Lee25e26452015-06-02 09:56:29 -07001718 * aggregate of all policy administrators if {@code admin} is null.
Jim Millera4e28d12010-11-08 16:15:47 -08001719 *
Robin Lee25e26452015-06-02 09:56:29 -07001720 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001721 * @return The timeout for the given admin or the minimum of all timeouts
1722 */
Robin Lee25e26452015-06-02 09:56:29 -07001723 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001724 if (mService != null) {
1725 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001726 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001727 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001728 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001729 }
1730 }
1731 return 0;
1732 }
1733
1734 /**
1735 * Get the current password expiration time for the given admin or an aggregate of
Jessica Hummel91da58d2014-04-10 17:39:43 +01001736 * all admins of this user and its profiles if admin is null. If the password is
1737 * expired, this will return the time since the password expired as a negative number.
1738 * If admin is null, then a composite of all expiration timeouts is returned
1739 * - which will be the minimum of all timeouts.
Jim Millera4e28d12010-11-08 16:15:47 -08001740 *
Robin Lee25e26452015-06-02 09:56:29 -07001741 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001742 * @return The password expiration time, in ms.
1743 */
Robin Lee25e26452015-06-02 09:56:29 -07001744 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001745 if (mService != null) {
1746 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001747 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001748 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001749 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millera4e28d12010-11-08 16:15:47 -08001750 }
1751 }
1752 return 0;
1753 }
1754
1755 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01001756 * Retrieve the current password history length for all admins of this
1757 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001758 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001759 * all admins.
1760 * @return The length of the password history
1761 */
Robin Lee25e26452015-06-02 09:56:29 -07001762 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001763 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001764 }
1765
1766 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001767 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001768 if (mService != null) {
1769 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001770 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001771 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001772 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001773 }
1774 }
1775 return 0;
1776 }
1777
Dianne Hackbornd6847842010-01-12 18:14:19 -08001778 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001779 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001780 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001781 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001782 * @return Returns the maximum length that the user can enter.
1783 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001784 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001785 // Kind-of arbitrary.
1786 return 16;
1787 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001788
Dianne Hackborn254cb442010-01-27 19:23:59 -08001789 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001790 * Determine whether the current password the user has set is sufficient
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001791 * to meet the policy requirements (quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001792 * requested by the admins of this user and its profiles that don't have a separate challenge.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001793 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001794 * <p>The calling device admin must have requested
1795 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1796 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001797 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001798 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001799 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001800 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001801 if (mService != null) {
1802 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001803 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001804 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001805 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001806 }
1807 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001808 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001809 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001810
Dianne Hackbornd6847842010-01-12 18:14:19 -08001811 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001812 * Determine whether the current profile password the user has set is sufficient
1813 * to meet the policy requirements (quality, minimum length) that have been
1814 * requested by the admins of the parent user and its profiles.
1815 *
1816 * @param userHandle the userId of the profile to check the password for.
1817 * @return Returns true if the password would meet the current requirements, else false.
1818 * @hide
1819 */
1820 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1821 if (mService != null) {
1822 try {
1823 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1824 } catch (RemoteException e) {
1825 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
1826 }
1827 }
1828 return false;
1829 }
1830
1831 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001832 * Retrieve the number of times the user has failed at entering a
1833 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001834 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001835 * <p>The calling device admin must have requested
1836 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1837 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001838 */
1839 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001840 return getCurrentFailedPasswordAttempts(myUserId());
1841 }
1842
1843 /**
1844 * Retrieve the number of times the given user has failed at entering a
1845 * password since that last successful password entry.
1846 *
1847 * <p>The calling device admin must have requested
1848 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
1849 * not and it is not the system uid, a security exception will be thrown.
1850 *
1851 * @hide
1852 */
1853 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001854 if (mService != null) {
1855 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001856 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001857 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001858 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001859 }
1860 }
1861 return -1;
1862 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001863
1864 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001865 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001866 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001867 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001868 * @hide
1869 */
1870 public boolean getDoNotAskCredentialsOnBoot() {
1871 if (mService != null) {
1872 try {
1873 return mService.getDoNotAskCredentialsOnBoot();
1874 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001875 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001876 }
1877 }
1878 return false;
1879 }
1880
1881 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08001882 * Setting this to a value greater than zero enables a built-in policy
1883 * that will perform a device wipe after too many incorrect
1884 * device-unlock passwords have been entered. This built-in policy combines
1885 * watching for failed passwords and wiping the device, and requires
1886 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001887 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001888 *
Andrew Stadler88209d12010-02-08 22:59:36 -08001889 * <p>To implement any other policy (e.g. wiping data for a particular
1890 * application only, erasing or revoking credentials, or reporting the
1891 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001892 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08001893 * instead. Do not use this API, because if the maximum count is reached,
1894 * the device will be wiped immediately, and your callback will not be invoked.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001895 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001897 * @param num The number of failed password attempts at which point the
1898 * device will wipe its data.
1899 */
Robin Lee25e26452015-06-02 09:56:29 -07001900 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001901 if (mService != null) {
1902 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001903 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001904 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001905 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001906 }
1907 }
1908 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001909
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001910 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001911 * Retrieve the current maximum number of login attempts that are allowed
Jessica Hummel91da58d2014-04-10 17:39:43 +01001912 * before the device wipes itself, for all admins of this user and its profiles
Dianne Hackborn254cb442010-01-27 19:23:59 -08001913 * or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001914 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001915 * all admins.
1916 */
Robin Lee25e26452015-06-02 09:56:29 -07001917 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001918 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001919 }
1920
1921 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001922 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001923 if (mService != null) {
1924 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001925 return mService.getMaximumFailedPasswordsForWipe(
1926 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001927 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001928 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn254cb442010-01-27 19:23:59 -08001929 }
1930 }
1931 return 0;
1932 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001933
Dianne Hackborn254cb442010-01-27 19:23:59 -08001934 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001935 * Returns the profile with the smallest maximum failed passwords for wipe,
1936 * for the given user. So for primary user, it might return the primary or
1937 * a managed profile. For a secondary user, it would be the same as the
1938 * user passed in.
1939 * @hide Used only by Keyguard
1940 */
1941 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
1942 if (mService != null) {
1943 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001944 return mService.getProfileWithMinimumFailedPasswordsForWipe(
1945 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001946 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08001947 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07001948 }
1949 }
1950 return UserHandle.USER_NULL;
1951 }
1952
1953 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001954 * Flag for {@link #resetPassword}: don't allow other admins to change
1955 * the password again until the user has entered it.
1956 */
1957 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001958
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001959 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001960 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
1961 * If the flag is set, the device can be booted without asking for user password.
1962 * The absence of this flag does not change the current boot requirements. This flag
1963 * can be set by the device owner only. If the app is not the device owner, the flag
1964 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
1965 * device to factory defaults.
1966 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001967 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001968
1969 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001970 * Force a new device unlock password (the password needed to access the
1971 * entire device, not for individual accounts) on the user. This takes
1972 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08001973 *
1974 * <p>Calling this from a managed profile that shares the password with the owner profile
1975 * will throw a security exception.
1976 *
1977 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
1978 * device admins that are not device owner and not profile owner.
1979 * The password can now only be changed if there is currently no password set. Device owner
1980 * and profile owner can still do this.</em>
1981 *
1982 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001983 * current password quality and length constraints as returned by
1984 * {@link #getPasswordQuality(ComponentName)} and
1985 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
1986 * these constraints, then it will be rejected and false returned. Note
1987 * that the password may be a stronger quality (containing alphanumeric
1988 * characters when the requested quality is only numeric), in which case
1989 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001990 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001991 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08001992 * pattern or password if the current password constraints allow it. <em>Note: This will not
1993 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
1994 * device owner and not profile owner. Once set, the password cannot be changed to null or
1995 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01001996 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001997 * <p>The calling device admin must have requested
1998 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
1999 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002000 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002001 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002002 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002003 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002004 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08002005 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002006 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002007 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002008 if (mParentInstance) {
2009 throw new SecurityException("Reset password does not work across profiles.");
2010 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002011 if (mService != null) {
2012 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002013 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002014 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002015 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002016 }
2017 }
2018 return false;
2019 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002020
Dianne Hackbornd6847842010-01-12 18:14:19 -08002021 /**
2022 * Called by an application that is administering the device to set the
2023 * maximum time for user activity until the device will lock. This limits
2024 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002025 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002026 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002027 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002028 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002029 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002031 * @param timeMs The new desired maximum time to lock in milliseconds.
2032 * A value of 0 means there is no restriction.
2033 */
Robin Lee25e26452015-06-02 09:56:29 -07002034 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002035 if (mService != null) {
2036 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002037 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002038 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002039 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002040 }
2041 }
2042 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002043
Dianne Hackbornd6847842010-01-12 18:14:19 -08002044 /**
Jessica Hummel91da58d2014-04-10 17:39:43 +01002045 * Retrieve the current maximum time to unlock for all admins of this user
2046 * and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07002047 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002048 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002049 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002050 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002051 */
Robin Lee25e26452015-06-02 09:56:29 -07002052 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002053 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002054 }
2055
2056 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002057 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002058 if (mService != null) {
2059 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002060 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002061 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002062 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002063 }
2064 }
2065 return 0;
2066 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002067
Dianne Hackbornd6847842010-01-12 18:14:19 -08002068 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002069 * Make the device lock immediately, as if the lock screen timeout has
2070 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002071 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002072 * <p>The calling device admin must have requested
2073 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2074 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002075 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002076 public void lockNow() {
2077 if (mService != null) {
2078 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002079 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002080 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002081 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002082 }
2083 }
2084 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002085
Dianne Hackbornd6847842010-01-12 18:14:19 -08002086 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002087 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002088 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002089 */
2090 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2091
2092 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002093 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2094 * data.
2095 *
Paul Crowley2934b262014-12-02 11:21:13 +00002096 * <p>This flag may only be set by device owner admins; if it is set by
2097 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002098 */
2099 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2100
2101 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002102 * Ask the user data be wiped. Wiping the primary user will cause the
2103 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002104 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002105 * <p>The calling device admin must have requested
2106 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2107 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002108 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002109 * @param flags Bit mask of additional options: currently supported flags
2110 * are {@link #WIPE_EXTERNAL_STORAGE} and
2111 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002112 */
2113 public void wipeData(int flags) {
2114 if (mService != null) {
2115 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002116 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002117 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002118 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002119 }
2120 }
2121 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002122
Dianne Hackbornd6847842010-01-12 18:14:19 -08002123 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002124 * Called by an application that is administering the device to set the
2125 * global proxy and exclusion list.
2126 * <p>
2127 * The calling device admin must have requested
2128 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2129 * this method; if it has not, a security exception will be thrown.
2130 * Only the first device admin can set the proxy. If a second admin attempts
2131 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002132 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002133 * be returned.
2134 * The method can be called repeatedly by the device admin alrady setting the
2135 * proxy to update the proxy and exclusion list.
2136 *
Robin Lee25e26452015-06-02 09:56:29 -07002137 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002138 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2139 * Pass Proxy.NO_PROXY to reset the proxy.
2140 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002141 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2142 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002143 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002144 */
Robin Lee25e26452015-06-02 09:56:29 -07002145 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002146 List<String> exclusionList ) {
2147 if (proxySpec == null) {
2148 throw new NullPointerException();
2149 }
2150 if (mService != null) {
2151 try {
2152 String hostSpec;
2153 String exclSpec;
2154 if (proxySpec.equals(Proxy.NO_PROXY)) {
2155 hostSpec = null;
2156 exclSpec = null;
2157 } else {
2158 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2159 throw new IllegalArgumentException();
2160 }
2161 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2162 String hostName = sa.getHostName();
2163 int port = sa.getPort();
2164 StringBuilder hostBuilder = new StringBuilder();
2165 hostSpec = hostBuilder.append(hostName)
2166 .append(":").append(Integer.toString(port)).toString();
2167 if (exclusionList == null) {
2168 exclSpec = "";
2169 } else {
2170 StringBuilder listBuilder = new StringBuilder();
2171 boolean firstDomain = true;
2172 for (String exclDomain : exclusionList) {
2173 if (!firstDomain) {
2174 listBuilder = listBuilder.append(",");
2175 } else {
2176 firstDomain = false;
2177 }
2178 listBuilder = listBuilder.append(exclDomain.trim());
2179 }
2180 exclSpec = listBuilder.toString();
2181 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002182 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2183 != android.net.Proxy.PROXY_VALID)
2184 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002185 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002186 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002187 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002188 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002189 }
2190 }
2191 return null;
2192 }
2193
2194 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002195 * Set a network-independent global HTTP proxy. This is not normally what you want
2196 * for typical HTTP proxies - they are generally network dependent. However if you're
2197 * doing something unusual like general internal filtering this may be useful. On
2198 * a private network where the proxy is not accessible, you may break HTTP using this.
2199 *
2200 * <p>This method requires the caller to be the device owner.
2201 *
2202 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2203 * @see ProxyInfo
2204 *
2205 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2206 * with.
2207 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2208 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2209 */
Robin Lee25e26452015-06-02 09:56:29 -07002210 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2211 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002212 if (mService != null) {
2213 try {
2214 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2215 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002216 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jason Monk03bc9912014-05-13 09:44:57 -04002217 }
2218 }
2219 }
2220
2221 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002222 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002223 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2224 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002225 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002226 */
2227 public ComponentName getGlobalProxyAdmin() {
2228 if (mService != null) {
2229 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002230 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002231 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002232 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002233 }
2234 }
2235 return null;
2236 }
2237
2238 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002239 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002240 * indicating that encryption is not supported.
2241 */
2242 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2243
2244 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002245 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002246 * indicating that encryption is supported, but is not currently active.
2247 */
2248 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2249
2250 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002251 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002252 * indicating that encryption is not currently active, but is currently
2253 * being activated. This is only reported by devices that support
2254 * encryption of data and only when the storage is currently
2255 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2256 * to become encrypted will never return this value.
2257 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002258 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002259
2260 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002261 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002262 * indicating that encryption is active.
2263 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002264 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002265
2266 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002267 * Result code for {@link #getStorageEncryptionStatus}:
2268 * indicating that encryption is active, but an encryption key has not
2269 * been set by the user.
2270 */
2271 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2272
2273 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002274 * Activity action: begin the process of encrypting data on the device. This activity should
2275 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2276 * After resuming from this activity, use {@link #getStorageEncryption}
2277 * to check encryption status. However, on some devices this activity may never return, as
2278 * it may trigger a reboot and in some cases a complete data wipe of the device.
2279 */
2280 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2281 public static final String ACTION_START_ENCRYPTION
2282 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002283 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002284 * Widgets are enabled in keyguard
2285 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002286 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002287
2288 /**
Jim Miller50e62182014-04-23 17:25:00 -07002289 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002290 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002291 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2292
2293 /**
2294 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2295 */
2296 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2297
2298 /**
Jim Miller50e62182014-04-23 17:25:00 -07002299 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2300 */
2301 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2302
2303 /**
2304 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2305 */
2306 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2307
2308 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002309 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002310 * (e.g. PIN/Pattern/Password).
2311 */
2312 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2313
2314 /**
Jim Miller06e34502014-07-17 14:46:05 -07002315 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2316 */
2317 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2318
2319 /**
Jim Miller35207742012-11-02 15:33:20 -07002320 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002321 */
2322 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002323
2324 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002325 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002326 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002327 *
2328 * <p>When multiple device administrators attempt to control device
2329 * encryption, the most secure, supported setting will always be
2330 * used. If any device administrator requests device encryption,
2331 * it will be enabled; Conversely, if a device administrator
2332 * attempts to disable device encryption while another
2333 * device administrator has enabled it, the call to disable will
2334 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2335 *
2336 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002337 * written to other storage areas may or may not be encrypted, and this policy does not require
2338 * or control the encryption of any other storage areas.
2339 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2340 * {@code true}, then the directory returned by
2341 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2342 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002343 *
2344 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2345 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2346 * the encryption key may not be fully secured. For maximum security, the administrator should
2347 * also require (and check for) a pattern, PIN, or password.
2348 *
2349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2350 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002351 * @return the new request status (for all active admins) - will be one of
2352 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2353 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2354 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002355 */
Robin Lee25e26452015-06-02 09:56:29 -07002356 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002357 if (mService != null) {
2358 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002359 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002360 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002361 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002362 }
2363 }
2364 return ENCRYPTION_STATUS_UNSUPPORTED;
2365 }
2366
2367 /**
2368 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002369 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002370 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2372 * this will return the requested encryption setting as an aggregate of all active
2373 * administrators.
2374 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002375 */
Robin Lee25e26452015-06-02 09:56:29 -07002376 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002377 if (mService != null) {
2378 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002379 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002380 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002381 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002382 }
2383 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002384 return false;
2385 }
2386
2387 /**
2388 * Called by an application that is administering the device to
2389 * determine the current encryption status of the device.
2390 *
2391 * Depending on the returned status code, the caller may proceed in different
2392 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2393 * storage system does not support encryption. If the
2394 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2395 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002396 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2397 * storage system has enabled encryption but no password is set so further action
2398 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002399 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2400 *
Robin Lee7e678712014-07-24 16:41:31 +01002401 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002402 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002403 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2404 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002405 */
2406 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002407 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002408 }
2409
2410 /** @hide per-user version */
2411 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002412 if (mService != null) {
2413 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002414 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002415 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002416 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002417 }
2418 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002419 return ENCRYPTION_STATUS_UNSUPPORTED;
2420 }
2421
2422 /**
Robin Lee7e678712014-07-24 16:41:31 +01002423 * Installs the given certificate as a user CA.
2424 *
Robin Lee25e26452015-06-02 09:56:29 -07002425 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2426 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002427 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002428 *
2429 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002430 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002431 */
Robin Lee25e26452015-06-02 09:56:29 -07002432 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002433 if (mService != null) {
2434 try {
Robin Lee7e678712014-07-24 16:41:31 +01002435 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002436 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002437 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002438 }
2439 }
2440 return false;
2441 }
2442
2443 /**
Robin Lee7e678712014-07-24 16:41:31 +01002444 * Uninstalls the given certificate from trusted user CAs, if present.
2445 *
Robin Lee25e26452015-06-02 09:56:29 -07002446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2447 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002448 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002449 */
Robin Lee25e26452015-06-02 09:56:29 -07002450 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002451 if (mService != null) {
2452 try {
Robin Lee306fe082014-06-19 14:04:24 +00002453 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002454 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002455 } catch (CertificateException e) {
2456 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002457 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002458 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002459 }
2460 }
2461 }
2462
2463 /**
Robin Lee7e678712014-07-24 16:41:31 +01002464 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2465 * If a user has installed any certificates by other means than device policy these will be
2466 * included too.
2467 *
Robin Lee25e26452015-06-02 09:56:29 -07002468 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2469 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002470 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002471 */
Robin Lee25e26452015-06-02 09:56:29 -07002472 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002473 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002474 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002475 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002476 mService.enforceCanManageCaCerts(admin);
2477 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2478 for (String alias : certStore.userAliases()) {
2479 try {
2480 certs.add(certStore.getCertificate(alias).getEncoded());
2481 } catch (CertificateException ce) {
2482 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2483 }
2484 }
2485 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002486 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002487 }
2488 }
2489 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002490 }
2491
2492 /**
Robin Lee7e678712014-07-24 16:41:31 +01002493 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2494 * means other than device policy will also be removed, except for system CA certificates.
2495 *
Robin Lee25e26452015-06-02 09:56:29 -07002496 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2497 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002498 */
Robin Lee25e26452015-06-02 09:56:29 -07002499 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002500 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002501 try {
2502 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2503 .toArray(new String[0]));
2504 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002505 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Robin Lee7e678712014-07-24 16:41:31 +01002506 }
2507 }
2508 }
2509
2510 /**
2511 * Returns whether this certificate is installed as a trusted CA.
2512 *
Robin Lee25e26452015-06-02 09:56:29 -07002513 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2514 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002515 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002516 */
Robin Lee25e26452015-06-02 09:56:29 -07002517 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002518 if (mService != null) {
2519 try {
2520 mService.enforceCanManageCaCerts(admin);
2521 return getCaCertAlias(certBuffer) != null;
2522 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002523 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002524 } catch (CertificateException ce) {
2525 Log.w(TAG, "Could not parse certificate", ce);
2526 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002527 }
2528 return false;
2529 }
2530
2531 /**
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002532 * Called by a device or profile owner to install a certificate and private key pair. The
2533 * keypair will be visible to all apps within the profile.
2534 *
Robin Lee25e26452015-06-02 09:56:29 -07002535 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2536 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002537 * @param privKey The private key to install.
2538 * @param cert The certificate to install.
2539 * @param alias The private key alias under which to install the certificate. If a certificate
2540 * with that alias already exists, it will be overwritten.
2541 * @return {@code true} if the keys were installed, {@code false} otherwise.
2542 */
Robin Leefbc65642015-08-03 16:21:22 +01002543 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2544 @NonNull Certificate cert, @NonNull String alias) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002545 try {
2546 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002547 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2548 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Lee25e26452015-06-02 09:56:29 -07002549 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002550 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002551 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002552 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2553 Log.w(TAG, "Failed to obtain private key material", e);
2554 } catch (CertificateException | IOException e) {
2555 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002556 }
2557 return false;
2558 }
2559
2560 /**
Robin Leefbc65642015-08-03 16:21:22 +01002561 * Called by a device or profile owner to remove all user credentials installed under a given
2562 * alias.
2563 *
2564 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2565 * {@code null} if calling from a delegated certificate installer.
2566 * @param alias The private key alias under which the certificate is installed.
2567 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2568 */
2569 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2570 try {
2571 return mService.removeKeyPair(admin, alias);
2572 } catch (RemoteException e) {
2573 Log.w(TAG, "Failed talking with device policy service", e);
2574 }
2575 return false;
2576 }
2577
2578 /**
Robin Lee25e26452015-06-02 09:56:29 -07002579 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002580 * doesn't exist.
2581 */
2582 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2583 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2584 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2585 new ByteArrayInputStream(certBuffer));
2586 return new TrustedCertificateStore().getCertificateAlias(cert);
2587 }
2588
2589 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002590 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002591 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002592 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002593 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002594 * <p>
2595 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2596 * it is later cleared by calling this method with a null value or uninstallling the certificate
2597 * installer.
Rubin Xuf03d0a62016-02-10 14:54:15 +00002598 *<p>
2599 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2600 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
2601 * supplied certificate installer package must be installed when calling this API,
2602 * otherwise an {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002603 *
Robin Lee25e26452015-06-02 09:56:29 -07002604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002605 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002606 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002607 */
Robin Lee25e26452015-06-02 09:56:29 -07002608 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2609 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002610 if (mService != null) {
2611 try {
Robin Lee25e26452015-06-02 09:56:29 -07002612 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002613 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002614 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002615 }
2616 }
2617 }
2618
2619 /**
2620 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002621 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002622 *
Robin Lee25e26452015-06-02 09:56:29 -07002623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2624 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002625 * if none is set.
2626 */
Robin Lee25e26452015-06-02 09:56:29 -07002627 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002628 if (mService != null) {
2629 try {
Robin Lee25e26452015-06-02 09:56:29 -07002630 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002631 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002632 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Rubin Xuec32b562015-03-03 17:34:05 +00002633 }
2634 }
2635 return null;
2636 }
2637
2638 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002639 * Called by a device or profile owner to configure an always-on VPN connection through a
2640 * specific application for the current user.
2641 * This connection is automatically granted and persisted after a reboot.
2642 *
2643 * <p>The designated package should declare a {@link android.net.VpnService} in its
2644 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2645 * otherwise the call will fail.
2646 *
2647 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2648 * to remove an existing always-on VPN configuration.
2649 *
2650 * @return {@code true} if the package is set as always-on VPN controller;
2651 * {@code false} otherwise.
2652 */
2653 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2654 @Nullable String vpnPackage) {
2655 if (mService != null) {
2656 try {
2657 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2658 } catch (RemoteException e) {
2659 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2660 }
2661 }
2662 return false;
2663 }
2664
2665 /**
2666 * Called by a device or profile owner to read the name of the package administering an
2667 * always-on VPN connection for the current user.
2668 * If there is no such package, or the always-on VPN is provided by the system instead
2669 * of by an application, {@code null} will be returned.
2670 *
2671 * @return Package name of VPN controller responsible for always-on VPN,
2672 * or {@code null} if none is set.
2673 */
2674 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2675 if (mService != null) {
2676 try {
2677 return mService.getAlwaysOnVpnPackage(admin);
2678 } catch (RemoteException e) {
2679 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2680 }
2681 }
2682 return null;
2683 }
2684
2685 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002686 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002687 * on the device, for this user. After setting this, no applications running as this user
2688 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002689 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002690 * <p>If the caller is device owner, then the restriction will be applied to all users.
2691 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002692 * <p>The calling device admin must have requested
2693 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2694 * this method; if it has not, a security exception will be thrown.
2695 *
2696 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2697 * @param disabled Whether or not the camera should be disabled.
2698 */
Robin Lee25e26452015-06-02 09:56:29 -07002699 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002700 if (mService != null) {
2701 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002702 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002703 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002704 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002705 }
2706 }
2707 }
2708
2709 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002710 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002711 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002712 * @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 -07002713 * have disabled the camera
2714 */
Robin Lee25e26452015-06-02 09:56:29 -07002715 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002716 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002717 }
2718
2719 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002720 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002721 if (mService != null) {
2722 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002723 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002724 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002725 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ben Komalo2447edd2011-05-09 16:05:33 -07002726 }
2727 }
2728 return false;
2729 }
2730
2731 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002732 * Called by a device owner to request a bugreport.
2733 *
2734 * <p>There must be only one user on the device, managed by the device owner.
2735 * Otherwise a security exception will be thrown.
2736 *
2737 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2738 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2739 * if it wasn't triggered because a previous bugreport operation is still active
2740 * (either the bugreport is still running or waiting for the user to share or decline)
2741 */
2742 public boolean requestBugreport(@NonNull ComponentName admin) {
2743 if (mService != null) {
2744 try {
2745 return mService.requestBugreport(admin);
2746 } catch (RemoteException e) {
2747 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2748 }
2749 }
2750 return false;
2751 }
2752
2753 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002754 * Determine whether or not creating a guest user has been disabled for the device
2755 *
2756 * @hide
2757 */
2758 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2759 // Currently guest users can always be created if multi-user is enabled
2760 // TODO introduce a policy for guest user creation
2761 return false;
2762 }
2763
2764 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002765 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2766 * screen capture also prevents the content from being shown on display devices that do not have
2767 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2768 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002769 *
2770 * <p>The calling device admin must be a device or profile owner. If it is not, a
2771 * security exception will be thrown.
2772 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002773 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002774 * blocks assist requests for all activities of the relevant user.
2775 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002777 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002778 */
Robin Lee25e26452015-06-02 09:56:29 -07002779 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002780 if (mService != null) {
2781 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002782 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002783 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002784 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002785 }
2786 }
2787 }
2788
2789 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002790 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002791 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002792 * @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 +01002793 * have disabled screen capture.
2794 */
Robin Lee25e26452015-06-02 09:56:29 -07002795 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002796 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002797 }
2798
2799 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002800 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002801 if (mService != null) {
2802 try {
2803 return mService.getScreenCaptureDisabled(admin, userHandle);
2804 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002805 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002806 }
2807 }
2808 return false;
2809 }
2810
2811 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002812 * Called by a device owner to set whether auto time is required. If auto time is
2813 * required the user cannot set the date and time, but has to use network date and time.
2814 *
2815 * <p>Note: if auto time is required the user can still manually set the time zone.
2816 *
2817 * <p>The calling device admin must be a device owner. If it is not, a security exception will
2818 * be thrown.
2819 *
2820 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2821 * @param required Whether auto time is set required or not.
2822 */
Robin Lee25e26452015-06-02 09:56:29 -07002823 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002824 if (mService != null) {
2825 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002826 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002827 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002828 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002829 }
2830 }
2831 }
2832
2833 /**
2834 * @return true if auto time is required.
2835 */
2836 public boolean getAutoTimeRequired() {
2837 if (mService != null) {
2838 try {
2839 return mService.getAutoTimeRequired();
2840 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002841 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002842 }
2843 }
2844 return false;
2845 }
2846
2847 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01002848 * Called by a device owner to set whether all users created on the device should be ephemeral.
2849 *
2850 * <p>The system user is exempt from this policy - it is never ephemeral.
2851 *
2852 * <p>The calling device admin must be the device owner. If it is not, a security exception will
2853 * be thrown.
2854 *
2855 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2856 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
2857 * subsequently created users will be ephemeral.
2858 * @hide
2859 */
2860 public void setForceEphemeralUsers(
2861 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
2862 if (mService != null) {
2863 try {
2864 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
2865 } catch (RemoteException e) {
2866 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2867 }
2868 }
2869 }
2870
2871 /**
2872 * @return true if all users are created ephemeral.
2873 * @hide
2874 */
2875 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
2876 if (mService != null) {
2877 try {
2878 return mService.getForceEphemeralUsers(admin);
2879 } catch (RemoteException e) {
2880 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
2881 }
2882 }
2883 return false;
2884 }
2885
2886 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07002887 * Called by an application that is administering the device to disable keyguard customizations,
2888 * such as widgets. After setting this, keyguard features will be disabled according to the
2889 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002890 *
2891 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07002892 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07002893 * this method; if it has not, a security exception will be thrown.
2894 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002895 * <p>Calling this from a managed profile before version
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002896 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002897 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002898 * <p>From version {@link android.os.Build.VERSION_CODES#M} a profile owner can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002899 * <ul>
2900 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, {@link #KEYGUARD_DISABLE_FINGERPRINT}
2901 * these will affect the profile's parent user.
2902 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} this will affect notifications
2903 * generated by applications in the managed profile.
2904 * </ul>
2905 * <p>Requests to disable other features on a managed profile will be ignored. The admin
2906 * can check which features have been disabled by calling
2907 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07002908 *
Jim Millerb8ec4702012-08-31 17:19:10 -07002909 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07002910 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
2911 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07002912 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00002913 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
2914 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07002915 */
Robin Lee25e26452015-06-02 09:56:29 -07002916 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002917 if (mService != null) {
2918 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002919 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002920 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002921 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002922 }
2923 }
2924 }
2925
2926 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002927 * Determine whether or not features have been disabled in keyguard either by the calling
Jim Millerb8ec4702012-08-31 17:19:10 -07002928 * admin, if specified, or all admins.
Esteban Talavera62399912016-01-11 15:37:55 +00002929 * @param admin The name of the admin component to check, or {@code null} to check whether any
2930 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07002931 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
2932 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07002933 */
Robin Lee25e26452015-06-02 09:56:29 -07002934 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002935 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002936 }
2937
2938 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002939 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07002940 if (mService != null) {
2941 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002942 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07002943 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002944 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Millerb8ec4702012-08-31 17:19:10 -07002945 }
2946 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07002947 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07002948 }
2949
2950 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08002951 * @hide
2952 */
Robin Lee25e26452015-06-02 09:56:29 -07002953 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
2954 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002955 if (mService != null) {
2956 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01002957 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002958 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08002959 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002960 }
2961 }
2962 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002963
Dianne Hackbornd6847842010-01-12 18:14:19 -08002964 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01002965 * @hide
2966 */
Robin Lee25e26452015-06-02 09:56:29 -07002967 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002968 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01002969 }
2970
2971 /**
Robin Lee25e26452015-06-02 09:56:29 -07002972 * Returns the DeviceAdminInfo as defined by the administrator's package info &amp; meta-data
Dianne Hackbornd6847842010-01-12 18:14:19 -08002973 * @hide
2974 */
Robin Lee25e26452015-06-02 09:56:29 -07002975 public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002976 ActivityInfo ai;
2977 try {
2978 ai = mContext.getPackageManager().getReceiverInfo(cn,
2979 PackageManager.GET_META_DATA);
2980 } catch (PackageManager.NameNotFoundException e) {
2981 Log.w(TAG, "Unable to retrieve device policy " + cn, e);
2982 return null;
2983 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002984
Dianne Hackbornd6847842010-01-12 18:14:19 -08002985 ResolveInfo ri = new ResolveInfo();
2986 ri.activityInfo = ai;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002987
Dianne Hackbornd6847842010-01-12 18:14:19 -08002988 try {
2989 return new DeviceAdminInfo(mContext, ri);
Makoto Onuki55c46f22015-11-25 14:56:23 -08002990 } catch (XmlPullParserException | IOException e) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002991 Log.w(TAG, "Unable to parse device policy " + cn, e);
2992 return null;
2993 }
2994 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002995
Dianne Hackbornd6847842010-01-12 18:14:19 -08002996 /**
2997 * @hide
2998 */
Robin Lee25e26452015-06-02 09:56:29 -07002999 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003000 if (mService != null) {
3001 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003002 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003003 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003004 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003005 }
3006 }
3007 }
3008
3009 /**
3010 * @hide
3011 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003012 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003013 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003014 if (mService != null) {
3015 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003016 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003017 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003018 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003019 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003020 }
3021 }
3022 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003023
Dianne Hackbornd6847842010-01-12 18:14:19 -08003024 /**
3025 * @hide
3026 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003027 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003028 if (mService != null) {
3029 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003030 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003031 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003032 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003033 }
3034 }
3035 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003036
Dianne Hackbornd6847842010-01-12 18:14:19 -08003037 /**
3038 * @hide
3039 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003040 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003041 if (mService != null) {
3042 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003043 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003044 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003045 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003046 }
3047 }
3048 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003049
3050 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003051 * @hide
3052 */
3053 public void reportFailedFingerprintAttempt(int userHandle) {
3054 if (mService != null) {
3055 try {
3056 mService.reportFailedFingerprintAttempt(userHandle);
3057 } catch (RemoteException e) {
3058 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3059 }
3060 }
3061 }
3062
3063 /**
3064 * @hide
3065 */
3066 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3067 if (mService != null) {
3068 try {
3069 mService.reportSuccessfulFingerprintAttempt(userHandle);
3070 } catch (RemoteException e) {
3071 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3072 }
3073 }
3074 }
3075
3076 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003077 * Should be called when keyguard has been dismissed.
3078 * @hide
3079 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003080 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003081 if (mService != null) {
3082 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003083 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003084 } catch (RemoteException e) {
3085 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3086 }
3087 }
3088 }
3089
3090 /**
3091 * Should be called when keyguard view has been shown to the user.
3092 * @hide
3093 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003094 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003095 if (mService != null) {
3096 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003097 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003098 } catch (RemoteException e) {
3099 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3100 }
3101 }
3102 }
3103
3104 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003105 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003106 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003107 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3108 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003109 * @return whether the package was successfully registered as the device owner.
3110 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003111 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003112 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003113 public boolean setDeviceOwner(ComponentName who) {
3114 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003115 }
3116
3117 /**
3118 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003119 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003120 public boolean setDeviceOwner(ComponentName who, int userId) {
3121 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003122 }
3123
3124 /**
3125 * @hide
3126 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003127 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3128 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003129 }
3130
3131 /**
3132 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003133 * Sets the given package as the device owner. The package must already be installed. There
3134 * must not already be a device owner.
3135 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3136 * this method.
3137 * Calling this after the setup phase of the primary user has completed is allowed only if
3138 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003139 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003140 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003141 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003142 * @return whether the package was successfully registered as the device owner.
3143 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003144 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003145 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003146 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003147 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003148 if (mService != null) {
3149 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003150 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003151 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003152 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003153 }
3154 }
3155 return false;
3156 }
3157
3158 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003159 * Used to determine if a particular package has been registered as a Device Owner app.
3160 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003161 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003162 * package is currently registered as the device owner app, pass in the package name from
3163 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003164 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003165 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3166 * the setup process.
3167 * @param packageName the package name of the app, to compare with the registered device owner
3168 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003169 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003170 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003171 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003172 return isDeviceOwnerAppOnCallingUser(packageName);
3173 }
3174
3175 /**
3176 * @return true if a package is registered as device owner, only when it's running on the
3177 * calling user.
3178 *
3179 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3180 * @hide
3181 */
3182 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3183 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3184 }
3185
3186 /**
3187 * @return true if a package is registered as device owner, even if it's running on a different
3188 * user.
3189 *
3190 * <p>Requires the MANAGE_USERS permission.
3191 *
3192 * @hide
3193 */
3194 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3195 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3196 }
3197
3198 /**
3199 * @return device owner component name, only when it's running on the calling user.
3200 *
3201 * @hide
3202 */
3203 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3204 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3205 }
3206
3207 /**
3208 * @return device owner component name, even if it's running on a different user.
3209 *
3210 * <p>Requires the MANAGE_USERS permission.
3211 *
3212 * @hide
3213 */
3214 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3215 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3216 }
3217
3218 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003219 if (packageName == null) {
3220 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003221 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003222 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003223 if (deviceOwner == null) {
3224 return false;
3225 }
3226 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003227 }
3228
Makoto Onukic8a5a552015-11-19 14:29:12 -08003229 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3230 if (mService != null) {
3231 try {
3232 return mService.getDeviceOwnerComponent(callingUserOnly);
3233 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003234 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003235 }
3236 }
3237 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003238 }
3239
Jason Monkb0dced82014-06-06 14:36:20 -04003240 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003241 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3242 * no device owner.
3243 *
3244 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003245 *
3246 * @hide
3247 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003248 public int getDeviceOwnerUserId() {
3249 if (mService != null) {
3250 try {
3251 return mService.getDeviceOwnerUserId();
3252 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003253 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukic8a5a552015-11-19 14:29:12 -08003254 }
3255 }
3256 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003257 }
3258
3259 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003260 * Clears the current device owner. The caller must be the device owner.
3261 *
3262 * This function should be used cautiously as once it is called it cannot
3263 * be undone. The device owner can only be set as a part of device setup
3264 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003265 *
3266 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003267 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003268 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003269 if (mService != null) {
3270 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003271 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003272 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003273 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monkb0dced82014-06-06 14:36:20 -04003274 }
3275 }
3276 }
3277
Makoto Onukia52562c2015-10-01 16:12:31 -07003278 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003279 * Returns the device owner package name, only if it's running on the calling user.
3280 *
3281 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003282 *
3283 * @hide
3284 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003285 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003286 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003287 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3288 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003289 }
3290
3291 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003292 * @return true if the device is managed by any device owner.
3293 *
3294 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003295 *
3296 * @hide
3297 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003298 public boolean isDeviceManaged() {
3299 return getDeviceOwnerComponentOnAnyUser() != null;
3300 }
3301
3302 /**
3303 * Returns the device owner name. Note this method *will* return the device owner
3304 * name when it's running on a different user.
3305 *
3306 * <p>Requires the MANAGE_USERS permission.
3307 *
3308 * @hide
3309 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003310 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003311 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003312 if (mService != null) {
3313 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003314 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003315 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003316 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003317 }
3318 }
3319 return null;
3320 }
Adam Connors776c5552014-01-09 10:42:56 +00003321
3322 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003323 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003324 * @deprecated Do not use
3325 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003326 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003327 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003328 @SystemApi
3329 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003330 return null;
3331 }
3332
3333 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003334 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003335 * @deprecated Do not use
3336 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003337 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003338 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003339 @SystemApi
3340 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003341 return null;
3342 }
3343
Julia Reynolds20118f12015-02-11 12:34:08 -05003344 /**
Adam Connors776c5552014-01-09 10:42:56 +00003345 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003346 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303347 * Sets the given component as an active admin and registers the package as the profile
3348 * owner for this user. The package must already be installed and there shouldn't be
3349 * an existing profile owner registered for this user. Also, this method must be called
3350 * before the user setup has been completed.
3351 * <p>
3352 * This method can only be called by system apps that hold MANAGE_USERS permission and
3353 * MANAGE_DEVICE_ADMINS permission.
3354 * @param admin The component to register as an active admin and profile owner.
3355 * @param ownerName The user-visible name of the entity that is managing this user.
3356 * @return whether the admin was successfully registered as the profile owner.
3357 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3358 * the user has already been set up.
3359 */
Justin Morey80440cc2014-07-24 09:16:35 -05003360 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003361 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303362 throws IllegalArgumentException {
3363 if (mService != null) {
3364 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003365 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303366 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003367 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303368 } catch (RemoteException re) {
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303369 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3370 }
3371 }
3372 return false;
3373 }
3374
3375 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003376 * Clears the active profile owner and removes all user restrictions. The caller must
3377 * be from the same package as the active profile owner for this user, otherwise a
3378 * SecurityException will be thrown.
3379 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003380 * <p>This doesn't work for managed profile owners.
3381 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003382 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003383 */
Robin Lee25e26452015-06-02 09:56:29 -07003384 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003385 if (mService != null) {
3386 try {
3387 mService.clearProfileOwner(admin);
3388 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003389 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003390 }
3391 }
3392 }
3393
3394 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003395 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003396 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003397 */
3398 public boolean hasUserSetupCompleted() {
3399 if (mService != null) {
3400 try {
3401 return mService.hasUserSetupCompleted();
3402 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003403 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003404 }
3405 }
3406 return true;
3407 }
3408
3409 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003410 * @hide
3411 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003412 * already be installed. There must not already be a profile owner for this user.
3413 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3414 * this method.
3415 * Calling this after the setup phase of the specified user has completed is allowed only if:
3416 * - the caller is SYSTEM_UID.
3417 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003418 * @param admin the component name to be registered as profile owner.
3419 * @param ownerName the human readable name of the organisation associated with this DPM.
3420 * @param userHandle the userId to set the profile owner for.
3421 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003422 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3423 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003424 */
Robin Lee25e26452015-06-02 09:56:29 -07003425 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003426 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003427 if (mService != null) {
3428 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003429 if (ownerName == null) {
3430 ownerName = "";
3431 }
3432 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003433 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003434 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003435 throw new IllegalArgumentException("Couldn't set profile owner.", re);
3436 }
3437 }
3438 return false;
3439 }
3440
3441 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003442 * Sets the device owner information to be shown on the lock screen.
3443 *
3444 * <p>If the device owner information is {@code null} or empty then the device owner info is
3445 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003446 * <p>If the device owner information contains only whitespaces then the message on the lock
3447 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003448 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003449 * <p>If the device owner information needs to be localized, it is the responsibility of the
3450 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3451 * and set a new version of this string accordingly.
3452 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003453 * @param admin The name of the admin component to check.
3454 * @param info Device owner information which will be displayed instead of the user
3455 * owner info.
3456 * @return Whether the device owner information has been set.
3457 */
3458 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3459 if (mService != null) {
3460 try {
3461 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3462 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003463 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003464 }
3465 }
3466 return false;
3467 }
3468
3469 /**
3470 * @return The device owner information. If it is not set returns {@code null}.
3471 */
3472 public String getDeviceOwnerLockScreenInfo() {
3473 if (mService != null) {
3474 try {
3475 return mService.getDeviceOwnerLockScreenInfo();
3476 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003477 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003478 }
3479 }
3480 return null;
3481 }
3482
3483 /**
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003484 * Called by device or profile owners for setting the package suspended for this user.
3485 * A suspended package will not be started by the package manager, its notifications will
3486 * be hidden and it will not show up in recents. The package must already be installed.
3487 *
3488 * @param admin The name of the admin component to check.
3489 * @param packageName The package name of the app to suspend or unsuspend.
3490 * @param suspended If set to {@code true} than the package will be suspended, if set to
3491 * {@code false} the package will be unsuspended.
3492 * @return boolean {@code true} if the operation was successfully performed, {@code false}
3493 * otherwise.
3494 */
3495 public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
3496 boolean suspended) {
3497 if (mService != null) {
3498 try {
3499 return mService.setPackageSuspended(admin, packageName, suspended);
3500 } catch (RemoteException re) {
3501 Log.w(TAG, "Failed talking with device policy service", re);
3502 }
3503 }
3504 return false;
3505 }
3506
3507 /**
3508 * Called by device or profile owners to determine if a package is suspended.
3509 *
3510 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3511 * @param packageName The name of the package to retrieve the suspended status of.
3512 * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
3513 */
3514 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3515 if (mService != null) {
3516 try {
3517 return mService.getPackageSuspended(admin, packageName);
3518 } catch (RemoteException e) {
3519 Log.w(TAG, "Failed talking with device policy service", e);
3520 }
3521 }
3522 return false;
3523 }
3524
3525 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003526 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3527 * be used. Only the profile owner can call this.
3528 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003529 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003530 *
3531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3532 */
Robin Lee25e26452015-06-02 09:56:29 -07003533 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003534 if (mService != null) {
3535 try {
3536 mService.setProfileEnabled(admin);
3537 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003538 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003539 }
3540 }
3541 }
3542
3543 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003544 * Sets the name of the profile. In the device owner case it sets the name of the user
3545 * 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 +01003546 * never called by the profile or device owner, the name will be set to default values.
3547 *
3548 * @see #isProfileOwnerApp
3549 * @see #isDeviceOwnerApp
3550 *
Robin Lee25e26452015-06-02 09:56:29 -07003551 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003552 * @param profileName The name of the profile.
3553 */
Robin Lee25e26452015-06-02 09:56:29 -07003554 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003555 if (mService != null) {
3556 try {
Robin Lee25e26452015-06-02 09:56:29 -07003557 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003558 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003559 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003560 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003561 }
3562 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003563
3564 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003565 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003566 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003567 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003568 *
3569 * @param packageName The package name of the app to compare with the registered profile owner.
3570 * @return Whether or not the package is registered as the profile owner.
3571 */
3572 public boolean isProfileOwnerApp(String packageName) {
3573 if (mService != null) {
3574 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003575 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003576 return profileOwner != null
3577 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003578 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003579 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003580 }
3581 }
3582 return false;
3583 }
3584
3585 /**
3586 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003587 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003588 * owner has been set for that user.
3589 * @throws IllegalArgumentException if the userId is invalid.
3590 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003591 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003592 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003593 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3594 }
3595
3596 /**
3597 * @see #getProfileOwner()
3598 * @hide
3599 */
3600 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003601 if (mService != null) {
3602 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003603 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003604 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003605 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003606 throw new IllegalArgumentException(
3607 "Requested profile owner for invalid userId", re);
3608 }
3609 }
3610 return null;
3611 }
3612
3613 /**
3614 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003615 * @return the human readable name of the organisation associated with this DPM or {@code null}
3616 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003617 * @throws IllegalArgumentException if the userId is invalid.
3618 */
3619 public String getProfileOwnerName() throws IllegalArgumentException {
3620 if (mService != null) {
3621 try {
3622 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3623 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003624 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Adam Connors776c5552014-01-09 10:42:56 +00003625 throw new IllegalArgumentException(
3626 "Requested profile owner for invalid userId", re);
3627 }
3628 }
3629 return null;
3630 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003631
3632 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003633 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003634 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003635 * @return the human readable name of the organisation associated with this profile owner or
3636 * null if one is not set.
3637 * @throws IllegalArgumentException if the userId is invalid.
3638 */
3639 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003640 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003641 if (mService != null) {
3642 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003643 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003644 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003645 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003646 throw new IllegalArgumentException(
3647 "Requested profile owner for invalid userId", re);
3648 }
3649 }
3650 return null;
3651 }
3652
3653 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003654 * Called by a profile owner or device owner to add a default intent handler activity for
3655 * intents that match a certain intent filter. This activity will remain the default intent
3656 * handler even if the set of potential event handlers for the intent filter changes and if
3657 * the intent preferences are reset.
3658 *
3659 * <p>The default disambiguation mechanism takes over if the activity is not installed
3660 * (anymore). When the activity is (re)installed, it is automatically reset as default
3661 * intent handler for the filter.
3662 *
3663 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3664 * security exception will be thrown.
3665 *
3666 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3667 * @param filter The IntentFilter for which a default handler is added.
3668 * @param activity The Activity that is added as default intent handler.
3669 */
Robin Lee25e26452015-06-02 09:56:29 -07003670 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3671 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003672 if (mService != null) {
3673 try {
3674 mService.addPersistentPreferredActivity(admin, filter, activity);
3675 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003676 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003677 }
3678 }
3679 }
3680
3681 /**
3682 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003683 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003684 *
3685 * <p>The calling device admin must be a profile owner. If it is not, a security
3686 * exception will be thrown.
3687 *
3688 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3689 * @param packageName The name of the package for which preferences are removed.
3690 */
Robin Lee25e26452015-06-02 09:56:29 -07003691 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003692 String packageName) {
3693 if (mService != null) {
3694 try {
3695 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3696 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003697 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003698 }
3699 }
3700 }
Robin Lee66e5d962014-04-09 16:44:21 +01003701
3702 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003703 * Called by a profile owner or device owner to grant permission to a package to manage
3704 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3705 * {@link #getApplicationRestrictions}.
3706 * <p>
3707 * This permission is persistent until it is later cleared by calling this method with a
3708 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00003709 * <p>
3710 * The supplied application restriction managing package must be installed when calling this
3711 * API, otherwise an {@link IllegalArgumentException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00003712 *
3713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3714 * @param packageName The package name which will be given access to application restrictions
3715 * APIs. If {@code null} is given the current package will be cleared.
3716 */
3717 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3718 @Nullable String packageName) {
3719 if (mService != null) {
3720 try {
3721 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3722 } catch (RemoteException e) {
3723 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3724 }
3725 }
3726 }
3727
3728 /**
3729 * Called by a profile owner or device owner to retrieve the application restrictions managing
3730 * package for the current user, or {@code null} if none is set.
3731 *
3732 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3733 * @return The package name allowed to manage application restrictions on the current user, or
3734 * {@code null} if none is set.
3735 */
3736 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3737 if (mService != null) {
3738 try {
3739 return mService.getApplicationRestrictionsManagingPackage(admin);
3740 } catch (RemoteException e) {
3741 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3742 }
3743 }
3744 return null;
3745 }
3746
3747 /**
3748 * Returns {@code true} if the calling package has been granted permission via
3749 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3750 * restrictions for the calling user.
3751 */
3752 public boolean isCallerApplicationRestrictionsManagingPackage() {
3753 if (mService != null) {
3754 try {
3755 return mService.isCallerApplicationRestrictionsManagingPackage();
3756 } catch (RemoteException e) {
3757 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3758 }
3759 }
3760 return false;
3761 }
3762
3763 /**
3764 * Sets the application restrictions for a given target application running in the calling user.
3765 *
3766 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3767 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3768 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003769 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003770 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3771 * <ul>
3772 * <li>{@code boolean}
3773 * <li>{@code int}
3774 * <li>{@code String} or {@code String[]}
3775 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3776 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003777 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003778 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003779 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003780 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3781 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003782 * <p>The application restrictions are only made visible to the target application via
3783 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3784 * device owner, and the application restrictions managing package via
3785 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003786 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3788 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003789 * @param packageName The name of the package to update restricted settings for.
3790 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3791 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003792 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003793 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003794 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003795 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003796 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003797 Bundle settings) {
3798 if (mService != null) {
3799 try {
3800 mService.setApplicationRestrictions(admin, packageName, settings);
3801 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003802 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01003803 }
3804 }
3805 }
3806
3807 /**
Jim Millere303bf42014-08-26 17:12:29 -07003808 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3809 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3810 * trust agents but those enabled by this function call. If flag
3811 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003812 *
3813 * <p>The calling device admin must have requested
3814 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003815 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003816 *
3817 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003818 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003819 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003820 * will be strictly disabled according to the state of the
3821 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3822 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3823 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3824 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003825 */
Robin Lee25e26452015-06-02 09:56:29 -07003826 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3827 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07003828 if (mService != null) {
3829 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003830 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07003831 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003832 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003833 }
3834 }
3835 }
3836
3837 /**
Jim Millere303bf42014-08-26 17:12:29 -07003838 * Gets configuration for the given trust agent based on aggregating all calls to
3839 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
3840 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07003841 *
Jim Millerb5db57a2015-01-14 18:17:19 -08003842 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3843 * this function returns a list of configurations for all admins that declare
3844 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
3845 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
3846 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
3847 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07003848 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07003849 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07003850 */
Robin Lee25e26452015-06-02 09:56:29 -07003851 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3852 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003853 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07003854 }
3855
3856 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003857 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
3858 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07003859 if (mService != null) {
3860 try {
Jim Millere303bf42014-08-26 17:12:29 -07003861 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07003862 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003863 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Jim Miller604e7552014-07-18 19:00:02 -07003864 }
3865 }
Jim Millere303bf42014-08-26 17:12:29 -07003866 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07003867 }
3868
3869 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003870 * Called by a profile owner of a managed profile to set whether caller-Id information from
3871 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01003872 *
3873 * <p>The calling device admin must be a profile owner. If it is not, a
3874 * security exception will be thrown.
3875 *
Robin Lee25e26452015-06-02 09:56:29 -07003876 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003877 * @param disabled If true caller-Id information in the managed profile is not displayed.
3878 */
Robin Lee25e26452015-06-02 09:56:29 -07003879 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01003880 if (mService != null) {
3881 try {
Robin Lee25e26452015-06-02 09:56:29 -07003882 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01003883 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003884 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003885 }
3886 }
3887 }
3888
3889 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003890 * Called by a profile owner of a managed profile to determine whether or not caller-Id
3891 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01003892 *
3893 * <p>The calling device admin must be a profile owner. If it is not, a
3894 * security exception will be thrown.
3895 *
Robin Lee25e26452015-06-02 09:56:29 -07003896 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01003897 */
Robin Lee25e26452015-06-02 09:56:29 -07003898 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01003899 if (mService != null) {
3900 try {
Robin Lee25e26452015-06-02 09:56:29 -07003901 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01003902 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003903 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors210fe212014-07-17 15:41:43 +01003904 }
3905 }
3906 return false;
3907 }
3908
3909 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07003910 * Determine whether or not caller-Id information has been disabled.
3911 *
3912 * @param userHandle The user for whom to check the caller-id permission
3913 * @hide
3914 */
3915 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
3916 if (mService != null) {
3917 try {
3918 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
3919 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003920 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasani570002f2014-07-18 15:48:54 -07003921 }
3922 }
3923 return false;
3924 }
3925
3926 /**
Victor Chang1060c6182016-01-04 20:16:23 +00003927 * Called by a profile owner of a managed profile to set whether contacts search from
3928 * the managed profile will be shown in the parent profile, for incoming calls.
3929 *
3930 * <p>The calling device admin must be a profile owner. If it is not, a
3931 * security exception will be thrown.
3932 *
3933 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3934 * @param disabled If true contacts search in the managed profile is not displayed.
3935 */
3936 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
3937 boolean disabled) {
3938 if (mService != null) {
3939 try {
3940 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
3941 } catch (RemoteException e) {
3942 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3943 }
3944 }
3945 }
3946
3947 /**
3948 * Called by a profile owner of a managed profile to determine whether or not contacts search
3949 * has been disabled.
3950 *
3951 * <p>The calling device admin must be a profile owner. If it is not, a
3952 * security exception will be thrown.
3953 *
3954 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3955 */
3956 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
3957 if (mService != null) {
3958 try {
3959 return mService.getCrossProfileContactsSearchDisabled(admin);
3960 } catch (RemoteException e) {
3961 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3962 }
3963 }
3964 return false;
3965 }
3966
3967
3968 /**
3969 * Determine whether or not contacts search has been disabled.
3970 *
3971 * @param userHandle The user for whom to check the contacts search permission
3972 * @hide
3973 */
3974 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
3975 if (mService != null) {
3976 try {
3977 return mService
3978 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
3979 } catch (RemoteException e) {
3980 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
3981 }
3982 }
3983 return false;
3984 }
3985
3986 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003987 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00003988 *
Makoto Onuki1040da12015-03-19 11:24:00 -07003989 * @hide
3990 */
3991 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00003992 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07003993 if (mService != null) {
3994 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00003995 mService.startManagedQuickContact(actualLookupKey, actualContactId,
3996 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07003997 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08003998 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki1040da12015-03-19 11:24:00 -07003999 }
4000 }
4001 }
4002
4003 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004004 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004005 * @hide
4006 */
4007 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4008 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004009 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004010 originalIntent);
4011 }
4012
4013 /**
Ricky Wai778ba132015-03-31 14:21:22 +01004014 * Called by a profile owner of a managed profile to set whether bluetooth
4015 * devices can access enterprise contacts.
4016 * <p>
4017 * The calling device admin must be a profile owner. If it is not, a
4018 * security exception will be thrown.
4019 * <p>
4020 * This API works on managed profile only.
4021 *
Robin Lee25e26452015-06-02 09:56:29 -07004022 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004023 * with.
4024 * @param disabled If true, bluetooth devices cannot access enterprise
4025 * contacts.
4026 */
Robin Lee25e26452015-06-02 09:56:29 -07004027 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004028 if (mService != null) {
4029 try {
Robin Lee25e26452015-06-02 09:56:29 -07004030 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004031 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004032 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004033 }
4034 }
4035 }
4036
4037 /**
4038 * Called by a profile owner of a managed profile to determine whether or
4039 * not Bluetooth devices cannot access enterprise contacts.
4040 * <p>
4041 * The calling device admin must be a profile owner. If it is not, a
4042 * security exception will be thrown.
4043 * <p>
4044 * This API works on managed profile only.
4045 *
Robin Lee25e26452015-06-02 09:56:29 -07004046 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004047 * with.
4048 */
Robin Lee25e26452015-06-02 09:56:29 -07004049 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004050 if (mService != null) {
4051 try {
Robin Lee25e26452015-06-02 09:56:29 -07004052 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004053 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004054 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004055 }
4056 }
4057 return true;
4058 }
4059
4060 /**
4061 * Determine whether or not Bluetooth devices cannot access contacts.
4062 * <p>
4063 * This API works on managed profile UserHandle only.
4064 *
4065 * @param userHandle The user for whom to check the caller-id permission
4066 * @hide
4067 */
4068 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4069 if (mService != null) {
4070 try {
4071 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4072 .getIdentifier());
4073 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004074 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Ricky Wai778ba132015-03-31 14:21:22 +01004075 }
4076 }
4077 return true;
4078 }
4079
4080 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004081 * Called by the profile owner of a managed profile so that some intents sent in the managed
4082 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004083 * Only activity intents are supported.
4084 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004085 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004086 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4087 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004088 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4089 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004090 */
Robin Lee25e26452015-06-02 09:56:29 -07004091 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004092 if (mService != null) {
4093 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004094 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004095 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004096 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004097 }
4098 }
4099 }
4100
4101 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004102 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4103 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004104 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4106 */
Robin Lee25e26452015-06-02 09:56:29 -07004107 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004108 if (mService != null) {
4109 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004110 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004111 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004112 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004113 }
4114 }
4115 }
4116
4117 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004118 * Called by a profile or device owner to set the permitted accessibility services. When
4119 * set by a device owner or profile owner the restriction applies to all profiles of the
4120 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004121 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004122 * By default the user can use any accessiblity service. When zero or more packages have
4123 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004124 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004125 *
4126 * <p> Calling with a null value for the list disables the restriction so that all services
4127 * can be used, calling with an empty list only allows the builtin system's services.
4128 *
4129 * <p> System accesibility services are always available to the user the list can't modify
4130 * this.
4131 *
4132 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4133 * @param packageNames List of accessibility service package names.
4134 *
4135 * @return true if setting the restriction succeeded. It fail if there is
4136 * one or more non-system accessibility services enabled, that are not in the list.
4137 */
Robin Lee25e26452015-06-02 09:56:29 -07004138 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004139 List<String> packageNames) {
4140 if (mService != null) {
4141 try {
4142 return mService.setPermittedAccessibilityServices(admin, packageNames);
4143 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004144 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004145 }
4146 }
4147 return false;
4148 }
4149
4150 /**
4151 * Returns the list of permitted accessibility services set by this device or profile owner.
4152 *
4153 * <p>An empty list means no accessibility services except system services are allowed.
4154 * Null means all accessibility services are allowed.
4155 *
4156 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4157 * @return List of accessiblity service package names.
4158 */
Robin Lee25e26452015-06-02 09:56:29 -07004159 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004160 if (mService != null) {
4161 try {
4162 return mService.getPermittedAccessibilityServices(admin);
4163 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004164 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004165 }
4166 }
4167 return null;
4168 }
4169
4170 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004171 * Called by the system to check if a specific accessibility service is disabled by admin.
4172 *
4173 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4174 * @param packageName Accessibility service package name that needs to be checked.
4175 * @param userHandle user id the admin is running as.
4176 * @return true if the accessibility service is permitted, otherwise false.
4177 *
4178 * @hide
4179 */
4180 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4181 @NonNull String packageName, int userHandle) {
4182 if (mService != null) {
4183 try {
4184 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4185 userHandle);
4186 } catch (RemoteException e) {
4187 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4188 }
4189 }
4190 return false;
4191 }
4192
4193 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004194 * Returns the list of accessibility services permitted by the device or profiles
4195 * owners of this user.
4196 *
4197 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4198 * it will contain the intersection of the permitted lists for any device or profile
4199 * owners that apply to this user. It will also include any system accessibility services.
4200 *
4201 * @param userId which user to check for.
4202 * @return List of accessiblity service package names.
4203 * @hide
4204 */
4205 @SystemApi
4206 public List<String> getPermittedAccessibilityServices(int userId) {
4207 if (mService != null) {
4208 try {
4209 return mService.getPermittedAccessibilityServicesForUser(userId);
4210 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004211 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004212 }
4213 }
4214 return null;
4215 }
4216
4217 /**
4218 * Called by a profile or device owner to set the permitted input methods services. When
4219 * set by a device owner or profile owner the restriction applies to all profiles of the
4220 * user the device owner or profile owner is an admin for.
4221 *
4222 * By default the user can use any input method. When zero or more packages have
4223 * been added, input method that are not in the list and not part of the system
4224 * can not be enabled by the user.
4225 *
4226 * This method will fail if it is called for a admin that is not for the foreground user
4227 * or a profile of the foreground user.
4228 *
4229 * <p> Calling with a null value for the list disables the restriction so that all input methods
4230 * can be used, calling with an empty list disables all but the system's own input methods.
4231 *
4232 * <p> System input methods are always available to the user this method can't modify this.
4233 *
4234 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4235 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004236 * @return true if setting the restriction succeeded. It will fail if there are
4237 * one or more non-system input methods currently enabled that are not in
4238 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004239 */
Robin Lee25e26452015-06-02 09:56:29 -07004240 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004241 if (mService != null) {
4242 try {
4243 return mService.setPermittedInputMethods(admin, packageNames);
4244 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004245 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004246 }
4247 }
4248 return false;
4249 }
4250
4251
4252 /**
4253 * Returns the list of permitted input methods set by this device or profile owner.
4254 *
4255 * <p>An empty list means no input methods except system input methods are allowed.
4256 * Null means all input methods are allowed.
4257 *
4258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4259 * @return List of input method package names.
4260 */
Robin Lee25e26452015-06-02 09:56:29 -07004261 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004262 if (mService != null) {
4263 try {
4264 return mService.getPermittedInputMethods(admin);
4265 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004266 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004267 }
4268 }
4269 return null;
4270 }
4271
4272 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004273 * Called by the system to check if a specific input method is disabled by admin.
4274 *
4275 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4276 * @param packageName Input method package name that needs to be checked.
4277 * @param userHandle user id the admin is running as.
4278 * @return true if the input method is permitted, otherwise false.
4279 *
4280 * @hide
4281 */
4282 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4283 @NonNull String packageName, int userHandle) {
4284 if (mService != null) {
4285 try {
4286 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4287 } catch (RemoteException e) {
4288 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
4289 }
4290 }
4291 return false;
4292 }
4293
4294 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004295 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004296 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004297 *
4298 * <p>Null means all input methods are allowed, if a non-null list is returned
4299 * it will contain the intersection of the permitted lists for any device or profile
4300 * owners that apply to this user. It will also include any system input methods.
4301 *
4302 * @return List of input method package names.
4303 * @hide
4304 */
4305 @SystemApi
4306 public List<String> getPermittedInputMethodsForCurrentUser() {
4307 if (mService != null) {
4308 try {
4309 return mService.getPermittedInputMethodsForCurrentUser();
4310 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004311 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004312 }
4313 }
4314 return null;
4315 }
4316
4317 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004318 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4319 * currently installed it.
4320 *
4321 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4322 *
4323 * @return List of package names to keep cached.
4324 * @hide
4325 */
4326 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4327 if (mService != null) {
4328 try {
4329 return mService.getKeepUninstalledPackages(admin);
4330 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004331 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004332 }
4333 }
4334 return null;
4335 }
4336
4337 /**
4338 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4339 * currently installed it.
4340 *
4341 * <p>Please note that setting this policy does not imply that specified apps will be
4342 * automatically pre-cached.</p>
4343 *
4344 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4345 * @param packageNames List of package names to keep cached.
4346 * @hide
4347 */
4348 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4349 @NonNull List<String> packageNames) {
4350 if (mService != null) {
4351 try {
4352 mService.setKeepUninstalledPackages(admin, packageNames);
4353 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004354 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004355 }
4356 }
4357 }
4358
4359 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004360 * Called by a device owner to create a user with the specified name. The UserHandle returned
4361 * by this method should not be persisted as user handles are recycled as users are removed and
4362 * created. If you need to persist an identifier for this user, use
4363 * {@link UserManager#getSerialNumberForUser}.
4364 *
4365 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4366 * @param name the user's name
4367 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004368 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4369 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004370 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004371 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Julia Reynolds1e958392014-05-16 14:25:21 -04004372 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004373 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004374 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004375 try {
4376 return mService.createUser(admin, name);
4377 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004378 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004379 }
4380 return null;
4381 }
4382
4383 /**
Jason Monk03978a42014-06-10 15:05:30 -04004384 * Called by a device owner to create a user with the specified name. The UserHandle returned
4385 * by this method should not be persisted as user handles are recycled as users are removed and
4386 * created. If you need to persist an identifier for this user, use
4387 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4388 * immediately.
4389 *
4390 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4391 * as registered as an active admin on the new user. The profile owner package will be
4392 * installed on the new user if it already is installed on the device.
4393 *
4394 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4395 * profileOwnerComponent when onEnable is called.
4396 *
4397 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4398 * @param name the user's name
4399 * @param ownerName the human readable name of the organisation associated with this DPM.
4400 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4401 * the user.
4402 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4403 * on the new user.
4404 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004405 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4406 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004407 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004408 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
Jason Monk03978a42014-06-10 15:05:30 -04004409 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004410 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004411 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4412 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004413 try {
4414 return mService.createAndInitializeUser(admin, name, ownerName, profileOwnerComponent,
4415 adminExtras);
4416 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004417 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk03978a42014-06-10 15:05:30 -04004418 }
4419 return null;
4420 }
4421
4422 /**
phweissa92e1212016-01-25 17:14:10 +01004423 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004424 */
4425 public static final int SKIP_SETUP_WIZARD = 0x0001;
4426
4427 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004428 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4429 * ephemeral.
4430 * @hide
4431 */
4432 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4433
4434 /**
phweissa92e1212016-01-25 17:14:10 +01004435 * Called by a device owner to create a user with the specified name and a given component of
4436 * the calling package as profile owner. The UserHandle returned by this method should not be
4437 * persisted as user handles are recycled as users are removed and created. If you need to
4438 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4439 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004440 *
phweissa92e1212016-01-25 17:14:10 +01004441 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4442 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4443 * will be registered as an active admin on the new user. The profile owner package will be
4444 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004445 *
4446 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4447 * started for the first time. Then the extras will be passed to the admin when
4448 * onEnable is called.
4449 *
4450 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4451 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004452 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4453 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4454 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004455 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4456 * user.
phweissa92e1212016-01-25 17:14:10 +01004457 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004458 * @see UserHandle
4459 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4460 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004461 */
4462 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004463 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4464 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004465 try {
phweissa92e1212016-01-25 17:14:10 +01004466 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004467 } catch (RemoteException re) {
4468 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
4469 }
4470 return null;
4471 }
4472
4473 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004474 * Called by a device owner to remove a user and all associated data. The primary user can
4475 * not be removed.
4476 *
4477 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4478 * @param userHandle the user to remove.
4479 * @return {@code true} if the user was removed, {@code false} otherwise.
4480 */
Robin Lee25e26452015-06-02 09:56:29 -07004481 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004482 try {
4483 return mService.removeUser(admin, userHandle);
4484 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004485 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds1e958392014-05-16 14:25:21 -04004486 return false;
4487 }
4488 }
4489
4490 /**
Jason Monk582d9112014-07-09 19:57:08 -04004491 * Called by a device owner to switch the specified user to the foreground.
4492 *
4493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4494 * @param userHandle the user to switch to; null will switch to primary.
4495 * @return {@code true} if the switch was successful, {@code false} otherwise.
4496 *
4497 * @see Intent#ACTION_USER_FOREGROUND
4498 */
Robin Lee25e26452015-06-02 09:56:29 -07004499 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004500 try {
4501 return mService.switchUser(admin, userHandle);
4502 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004503 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Jason Monk582d9112014-07-09 19:57:08 -04004504 return false;
4505 }
4506 }
4507
4508 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004509 * Retrieves the application restrictions for a given target application running in the calling
4510 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004511 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004512 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4513 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4514 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004515 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4517 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004518 * @param packageName The name of the package to fetch restricted settings of.
4519 * @return {@link Bundle} of settings corresponding to what was set last time
4520 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4521 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004522 *
4523 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004524 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004525 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004526 if (mService != null) {
4527 try {
4528 return mService.getApplicationRestrictions(admin, packageName);
4529 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004530 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Robin Lee66e5d962014-04-09 16:44:21 +01004531 }
4532 }
4533 return null;
4534 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004535
4536 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004537 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004538 * <p>
4539 * The calling device admin must be a profile or device owner; if it is not,
4540 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004541 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004542 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4543 * with.
4544 * @param key The key of the restriction. See the constants in
4545 * {@link android.os.UserManager} for the list of keys.
4546 */
Robin Lee25e26452015-06-02 09:56:29 -07004547 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004548 if (mService != null) {
4549 try {
4550 mService.setUserRestriction(admin, key, true);
4551 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004552 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004553 }
4554 }
4555 }
4556
4557 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004558 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004559 * <p>
4560 * The calling device admin must be a profile or device owner; if it is not,
4561 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004562 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004563 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4564 * with.
4565 * @param key The key of the restriction. See the constants in
4566 * {@link android.os.UserManager} for the list of keys.
4567 */
Robin Lee25e26452015-06-02 09:56:29 -07004568 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004569 if (mService != null) {
4570 try {
4571 mService.setUserRestriction(admin, key, false);
4572 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004573 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Amith Yamasanibe465322014-04-24 13:45:17 -07004574 }
4575 }
4576 }
Adam Connors010cfd42014-04-16 12:48:13 +01004577
4578 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004579 * Called by a profile or device owner to get user restrictions set with
4580 * {@link #addUserRestriction(ComponentName, String)}.
4581 * <p>
4582 * The target user may have more restrictions set by the system or other device owner / profile
4583 * owner. To get all the user restrictions currently set, use
4584 * {@link UserManager#getUserRestrictions()}.
4585 *
4586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004587 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004588 */
4589 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004590 return getUserRestrictions(admin, myUserId());
4591 }
4592
4593 /** @hide per-user version */
4594 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004595 Bundle ret = null;
4596 if (mService != null) {
4597 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004598 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004599 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004600 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004601 }
4602 }
4603 return ret == null ? new Bundle() : ret;
4604 }
4605
4606 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004607 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004608 * is unavailable for use, but the data and actual package file remain.
4609 *
4610 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004611 * @param packageName The name of the package to hide or unhide.
4612 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4613 * unhidden.
4614 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004615 */
Robin Lee25e26452015-06-02 09:56:29 -07004616 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004617 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004618 if (mService != null) {
4619 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004620 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004621 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004622 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004623 }
4624 }
4625 return false;
4626 }
4627
4628 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004629 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004630 *
4631 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004632 * @param packageName The name of the package to retrieve the hidden status of.
4633 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004634 */
Robin Lee25e26452015-06-02 09:56:29 -07004635 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004636 if (mService != null) {
4637 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004638 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004639 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynolds966881e2014-05-14 12:23:08 -04004641 }
4642 }
4643 return false;
4644 }
4645
4646 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004647 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004648 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004649 *
4650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004651 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004652 */
Robin Lee25e26452015-06-02 09:56:29 -07004653 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004654 if (mService != null) {
4655 try {
4656 mService.enableSystemApp(admin, packageName);
4657 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004658 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004659 }
4660 }
4661 }
4662
4663 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004664 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004665 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004666 *
4667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4668 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004669 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004670 * @return int The number of activities that matched the intent and were installed.
4671 */
Robin Lee25e26452015-06-02 09:56:29 -07004672 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004673 if (mService != null) {
4674 try {
4675 return mService.enableSystemAppWithIntent(admin, intent);
4676 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004677 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Adam Connors655be2a2014-07-14 09:01:25 +00004678 }
4679 }
4680 return 0;
4681 }
4682
4683 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004684 * Called by a device owner or profile owner to disable account management for a specific type
4685 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004686 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004687 * <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 +01004688 * security exception will be thrown.
4689 *
4690 * <p>When account management is disabled for an account type, adding or removing an account
4691 * of that type will not be possible.
4692 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004693 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4694 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4695 * management for a specific type is disabled.
4696 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4698 * @param accountType For which account management is disabled or enabled.
4699 * @param disabled The boolean indicating that account management will be disabled (true) or
4700 * enabled (false).
4701 */
Robin Lee25e26452015-06-02 09:56:29 -07004702 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004703 boolean disabled) {
4704 if (mService != null) {
4705 try {
4706 mService.setAccountManagementDisabled(admin, accountType, disabled);
4707 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004708 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse650c3342014-05-08 18:00:50 +01004709 }
4710 }
4711 }
4712
4713 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004714 * Gets the array of accounts for which account management is disabled by the profile owner.
4715 *
4716 * <p> Account management can be disabled/enabled by calling
4717 * {@link #setAccountManagementDisabled}.
4718 *
4719 * @return a list of account types for which account management has been disabled.
4720 *
4721 * @see #setAccountManagementDisabled
4722 */
4723 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004724 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004725 }
4726
4727 /**
4728 * @see #getAccountTypesWithManagementDisabled()
4729 * @hide
4730 */
4731 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004732 if (mService != null) {
4733 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004734 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004735 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004736 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004737 }
4738 }
4739
4740 return null;
4741 }
justinzhang511e0d82014-03-24 16:09:24 -04004742
4743 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004744 * Sets which packages may enter lock task mode.
4745 *
4746 * <p>Any packages that shares uid with an allowed package will also be allowed
4747 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004748 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004749 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004750 * package list results in locked tasks belonging to those packages to be finished.
4751 *
Jason Monkc5185f22014-06-24 11:12:42 -04004752 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004753 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004755 *
4756 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004757 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4758 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004759 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004760 */
Robin Lee25e26452015-06-02 09:56:29 -07004761 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004762 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004763 if (mService != null) {
4764 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004765 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004766 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004767 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004768 }
4769 }
4770 }
4771
4772 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004773 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004774 *
4775 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004776 * @hide
4777 */
Robin Lee25e26452015-06-02 09:56:29 -07004778 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004779 if (mService != null) {
4780 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004781 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004782 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004783 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004784 }
4785 }
4786 return null;
4787 }
4788
4789 /**
4790 * This function lets the caller know whether the given component is allowed to start the
4791 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004792 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004793 */
Jason Monkd7b86212014-06-16 13:15:38 -04004794 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004795 if (mService != null) {
4796 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004797 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004798 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004799 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
justinzhang511e0d82014-03-24 16:09:24 -04004800 }
4801 }
4802 return false;
4803 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004804
4805 /**
4806 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4807 * 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 -04004808 * <p>The settings that can be updated with this method are:
4809 * <ul>
4810 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4811 * <li>{@link Settings.Global#AUTO_TIME}</li>
4812 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004813 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004814 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004815 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004816 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004817 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004818 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004819 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004820 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004821 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004822 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004823 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004824 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004825 * <ul>
4826 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4827 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4828 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4829 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4830 * <li>{@link Settings.Global#MODE_RINGER}.
4831 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4832 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4833 * <li>{@link Settings.Global#WIFI_ON}.
4834 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4835 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004836 *
4837 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4838 * @param setting The name of the setting to update.
4839 * @param value The value to update the setting to.
4840 */
Robin Lee25e26452015-06-02 09:56:29 -07004841 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004842 if (mService != null) {
4843 try {
4844 mService.setGlobalSetting(admin, setting, value);
4845 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004846 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004847 }
4848 }
4849 }
4850
4851 /**
4852 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
4853 * that the value of the setting is in the correct form for the setting type should be performed
4854 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04004855 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004856 * <ul>
4857 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07004858 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004859 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
4860 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04004861 * <p>A device owner can additionally update the following settings:
4862 * <ul>
4863 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
4864 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4866 * @param setting The name of the setting to update.
4867 * @param value The value to update the setting to.
4868 */
Robin Lee25e26452015-06-02 09:56:29 -07004869 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04004870 if (mService != null) {
4871 try {
4872 mService.setSecureSetting(admin, setting, value);
4873 } catch (RemoteException e) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004874 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
Julia Reynoldsda551652014-05-14 17:15:16 -04004875 }
4876 }
4877 }
4878
Amith Yamasanif20d6402014-05-24 15:34:37 -07004879 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004880 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07004881 * making permission requests of a local or remote administrator of the user.
4882 * <p/>
4883 * Only a profile owner can designate the restrictions provider.
4884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004885 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07004886 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07004887 * it removes the restrictions provider previously assigned.
4888 */
Robin Lee25e26452015-06-02 09:56:29 -07004889 public void setRestrictionsProvider(@NonNull ComponentName admin,
4890 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07004891 if (mService != null) {
4892 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07004893 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004894 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004895 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanif20d6402014-05-24 15:34:37 -07004896 }
4897 }
4898 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04004899
4900 /**
4901 * Called by profile or device owners to set the master volume mute on or off.
4902 *
4903 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4904 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
4905 */
Robin Lee25e26452015-06-02 09:56:29 -07004906 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004907 if (mService != null) {
4908 try {
4909 mService.setMasterVolumeMuted(admin, on);
4910 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004911 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004912 }
4913 }
4914 }
4915
4916 /**
4917 * Called by profile or device owners to check whether the master volume mute is on or off.
4918 *
4919 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4920 * @return {@code true} if master volume is muted, {@code false} if it's not.
4921 */
Robin Lee25e26452015-06-02 09:56:29 -07004922 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04004923 if (mService != null) {
4924 try {
4925 return mService.isMasterVolumeMuted(admin);
4926 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004927 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynolds4a21b252014-06-04 11:11:43 -04004928 }
4929 }
4930 return false;
4931 }
Kenny Guyc13053b2014-05-29 14:17:17 +01004932
4933 /**
4934 * Called by profile or device owners to change whether a user can uninstall
4935 * a package.
4936 *
4937 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4938 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004939 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01004940 */
Robin Lee25e26452015-06-02 09:56:29 -07004941 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004942 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004943 if (mService != null) {
4944 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01004945 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01004946 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004947 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004948 }
4949 }
4950 }
4951
4952 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004953 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00004954 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00004955 * <p>
4956 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07004957 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00004958 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07004959 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01004960 *
Robin Lee25e26452015-06-02 09:56:29 -07004961 * @param admin The name of the admin component whose blocking policy will be checked, or
4962 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01004963 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00004964 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01004965 */
Robin Lee25e26452015-06-02 09:56:29 -07004966 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01004967 if (mService != null) {
4968 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01004969 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01004970 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004971 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Kenny Guyc13053b2014-05-29 14:17:17 +01004972 }
4973 }
4974 return false;
4975 }
Svetoslav976e8bd2014-07-16 15:12:03 -07004976
4977 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004978 * Called by the profile owner of a managed profile to enable widget providers from a
4979 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07004980 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004981 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07004982 * a package may have zero or more provider components, where each component
4983 * provides a different widget type.
4984 * <p>
4985 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07004986 *
4987 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4988 * @param packageName The package from which widget providers are white-listed.
4989 * @return Whether the package was added.
4990 *
4991 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
4992 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
4993 */
Robin Lee25e26452015-06-02 09:56:29 -07004994 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07004995 if (mService != null) {
4996 try {
4997 return mService.addCrossProfileWidgetProvider(admin, packageName);
4998 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08004999 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005000 }
5001 }
5002 return false;
5003 }
5004
5005 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005006 * Called by the profile owner of a managed profile to disable widget providers from a given
5007 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07005008 * package should have been added via {@link #addCrossProfileWidgetProvider(
5009 * android.content.ComponentName, String)}.
5010 * <p>
5011 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005012 *
5013 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5014 * @param packageName The package from which widget providers are no longer
5015 * white-listed.
5016 * @return Whether the package was removed.
5017 *
5018 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5019 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5020 */
Esteban Talavera62399912016-01-11 15:37:55 +00005021 public boolean removeCrossProfileWidgetProvider(
5022 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005023 if (mService != null) {
5024 try {
5025 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5026 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005027 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005028 }
5029 }
5030 return false;
5031 }
5032
5033 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005034 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005035 * available in the parent profile.
5036 *
5037 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5038 * @return The white-listed package list.
5039 *
5040 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5041 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5042 */
Robin Lee25e26452015-06-02 09:56:29 -07005043 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005044 if (mService != null) {
5045 try {
5046 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5047 if (providers != null) {
5048 return providers;
5049 }
5050 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005051 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Svetoslav976e8bd2014-07-16 15:12:03 -07005052 }
5053 }
5054 return Collections.emptyList();
5055 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005056
5057 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005058 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005059 *
5060 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5061 * @param icon the bitmap to set as the photo.
5062 */
Robin Lee25e26452015-06-02 09:56:29 -07005063 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005064 try {
5065 mService.setUserIcon(admin, icon);
5066 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005067 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005068 }
5069 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005070
5071 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005072 * Called by device owners to set a local system update policy. When a new policy is set,
5073 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005074 *
Robin Lee25e26452015-06-02 09:56:29 -07005075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5076 * components in the device owner package can set system update policies and the
5077 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005078 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005079 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005080 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005081 */
Robin Lee25e26452015-06-02 09:56:29 -07005082 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005083 if (mService != null) {
5084 try {
Robin Lee25e26452015-06-02 09:56:29 -07005085 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005086 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005087 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005088 }
5089 }
5090 }
5091
5092 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005093 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005094 *
Robin Lee25e26452015-06-02 09:56:29 -07005095 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005096 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005097 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005098 if (mService != null) {
5099 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005100 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005101 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005102 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005103 }
5104 }
5105 return null;
5106 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005107
5108 /**
5109 * Called by a device owner to disable the keyguard altogether.
5110 *
5111 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5112 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5113 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5114 * being disabled.
5115 *
5116 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005117 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005118 *
5119 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005120 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005121 */
Robin Lee25e26452015-06-02 09:56:29 -07005122 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005123 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005124 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005125 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005126 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franze36087e2015-04-07 16:40:34 +01005127 return false;
5128 }
5129 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005130
5131 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005132 * Called by device owner to disable the status bar. Disabling the status bar blocks
5133 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005134 * a single use device.
5135 *
5136 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005137 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5138 *
5139 * @return {@code false} if attempting to disable the status bar failed.
5140 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005141 */
Robin Lee25e26452015-06-02 09:56:29 -07005142 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005143 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005144 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005145 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005146 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Benjamin Franzbece8062015-05-06 12:14:31 +01005147 return false;
Benjamin Franzea2ec972015-03-16 17:18:09 +00005148 }
5149 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005150
5151 /**
5152 * Callable by the system update service to notify device owners about pending updates.
5153 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5154 * permission.
5155 *
5156 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5157 * when the current pending update was first available. -1 if no update is available.
5158 * @hide
5159 */
5160 @SystemApi
5161 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5162 if (mService != null) {
5163 try {
5164 mService.notifyPendingSystemUpdate(updateReceivedTime);
5165 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005166 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Rubin Xudc105cc2015-04-14 23:38:01 +01005167 }
5168 }
5169 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005170
5171 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005172 * Called by profile or device owners to set the default response for future runtime permission
5173 * requests by applications. The policy can allow for normal operation which prompts the
5174 * user to grant a permission, or can allow automatic granting or denying of runtime
5175 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005176 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5177 * the permission grant state via {@link #setPermissionGrantState}.
5178 *
5179 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005180 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005181 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005182 * @param admin Which profile or device owner this request is associated with.
5183 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5184 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005185 *
5186 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005187 */
Robin Lee25e26452015-06-02 09:56:29 -07005188 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005189 try {
5190 mService.setPermissionPolicy(admin, policy);
5191 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005192 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005193 }
5194 }
5195
5196 /**
5197 * Returns the current runtime permission policy set by the device or profile owner. The
5198 * default is {@link #PERMISSION_POLICY_PROMPT}.
5199 * @param admin Which profile or device owner this request is associated with.
5200 * @return the current policy for future permission requests.
5201 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005202 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005203 try {
5204 return mService.getPermissionPolicy(admin);
5205 } catch (RemoteException re) {
5206 return PERMISSION_POLICY_PROMPT;
5207 }
5208 }
5209
5210 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005211 * Sets the grant state of a runtime permission for a specific application. The state
5212 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5213 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5214 * is denied and the user cannot manage it through the UI, and {@link
5215 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5216 * user cannot manage it through the UI. This might affect all permissions in a
5217 * group that the runtime permission belongs to. This method can only be called
5218 * by a profile or device owner.
5219 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005220 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5221 * revoke the permission. It retains the previous grant, if any.
5222 *
5223 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005224 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005225 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005226 * @param admin Which profile or device owner this request is associated with.
5227 * @param packageName The application to grant or revoke a permission to.
5228 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005229 * @param grantState The permission grant state which is one of {@link
5230 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5231 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5232 * @return whether the permission was successfully granted or revoked.
5233 *
5234 * @see #PERMISSION_GRANT_STATE_DENIED
5235 * @see #PERMISSION_GRANT_STATE_DEFAULT
5236 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005237 */
Robin Lee25e26452015-06-02 09:56:29 -07005238 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005239 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005240 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005241 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005242 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005243 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005244 return false;
5245 }
5246 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005247
5248 /**
5249 * Returns the current grant state of a runtime permission for a specific application.
5250 *
5251 * @param admin Which profile or device owner this request is associated with.
5252 * @param packageName The application to check the grant state for.
5253 * @param permission The permission to check for.
5254 * @return the current grant state specified by device policy. If the profile or device owner
5255 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5256 * This does not indicate whether or not the permission is currently granted for the package.
5257 *
5258 * <p/>If a grant state was set by the profile or device owner, then the return value will
5259 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5260 * which indicates if the permission is currently denied or granted.
5261 *
5262 * @see #setPermissionGrantState(ComponentName, String, String, int)
5263 * @see PackageManager#checkPermission(String, String)
5264 */
Robin Lee25e26452015-06-02 09:56:29 -07005265 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005266 String permission) {
5267 try {
5268 return mService.getPermissionGrantState(admin, packageName, permission);
5269 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005270 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Amith Yamasani184b3752015-05-22 13:00:51 -07005271 return PERMISSION_GRANT_STATE_DEFAULT;
5272 }
5273 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005274
5275 /**
5276 * Returns if provisioning a managed profile or device is possible or not.
5277 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5278 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5279 * Note that even if this method returns true, there is a slight possibility that the
5280 * provisioning will not be allowed when it is actually initiated because some event has
5281 * happened in between.
5282 * @return if provisioning a managed profile or device is possible or not.
5283 * @throws IllegalArgumentException if the supplied action is not valid.
5284 */
5285 public boolean isProvisioningAllowed(String action) {
5286 try {
5287 return mService.isProvisioningAllowed(action);
5288 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005289 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005290 return false;
5291 }
5292 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005293
5294 /**
5295 * @hide
5296 * Return if this user is a managed profile of another user. An admin can become the profile
5297 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5298 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5299 * @param admin Which profile owner this request is associated with.
5300 * @return if this user is a managed profile of another user.
5301 */
5302 public boolean isManagedProfile(@NonNull ComponentName admin) {
5303 try {
5304 return mService.isManagedProfile(admin);
5305 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005306 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005307 return false;
5308 }
5309 }
5310
5311 /**
5312 * @hide
5313 * Return if this user is a system-only user. An admin can manage a device from a system only
5314 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5315 * @param admin Which device owner this request is associated with.
5316 * @return if this user is a system-only user.
5317 */
5318 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5319 try {
5320 return mService.isSystemOnlyUser(admin);
5321 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005322 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005323 return false;
5324 }
5325 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005326
5327 /**
5328 * Called by device owner to get the MAC address of the Wi-Fi device.
5329 *
5330 * @return the MAC address of the Wi-Fi device, or null when the information is not
5331 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5332 *
5333 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5334 */
5335 public String getWifiMacAddress() {
5336 try {
5337 return mService.getWifiMacAddress();
5338 } catch (RemoteException re) {
Makoto Onuki55c46f22015-11-25 14:56:23 -08005339 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005340 return null;
5341 }
5342 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005343
5344 /**
5345 * Called by device owner to reboot the device.
5346 */
5347 public void reboot(@NonNull ComponentName admin) {
5348 try {
5349 mService.reboot(admin);
5350 } catch (RemoteException re) {
5351 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5352 }
5353 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005354
5355 /**
5356 * Called by a device admin to set the short support message. This will
5357 * be displayed to the user in settings screens where funtionality has
5358 * been disabled by the admin.
5359 *
5360 * The message should be limited to a short statement such as
5361 * "This setting is disabled by your administrator. Contact someone@example.com
5362 * for support."
5363 * If the message is longer than 200 characters it may be truncated.
5364 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005365 * <p>If the short support message needs to be localized, it is the responsibility of the
5366 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5367 * and set a new version of this string accordingly.
5368 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005369 * @see #setLongSupportMessage
5370 *
5371 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5372 * @param message Short message to be displayed to the user in settings or null to
5373 * clear the existing message.
5374 */
5375 public void setShortSupportMessage(@NonNull ComponentName admin,
5376 @Nullable String message) {
5377 if (mService != null) {
5378 try {
5379 mService.setShortSupportMessage(admin, message);
5380 } catch (RemoteException e) {
5381 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5382 }
5383 }
5384 }
5385
5386 /**
5387 * Called by a device admin to get the short support message.
5388 *
5389 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5390 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5391 * or null if no message has been set.
5392 */
5393 public String getShortSupportMessage(@NonNull ComponentName admin) {
5394 if (mService != null) {
5395 try {
5396 return mService.getShortSupportMessage(admin);
5397 } catch (RemoteException e) {
5398 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5399 }
5400 }
5401 return null;
5402 }
5403
5404 /**
5405 * Called by a device admin to set the long support message. This will
5406 * be displayed to the user in the device administators settings screen.
5407 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005408 * <p>If the long support message needs to be localized, it is the responsibility of the
5409 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5410 * and set a new version of this string accordingly.
5411 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005412 * @see #setShortSupportMessage
5413 *
5414 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5415 * @param message Long message to be displayed to the user in settings or null to
5416 * clear the existing message.
5417 */
5418 public void setLongSupportMessage(@NonNull ComponentName admin,
5419 @Nullable String message) {
5420 if (mService != null) {
5421 try {
5422 mService.setLongSupportMessage(admin, message);
5423 } catch (RemoteException e) {
5424 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5425 }
5426 }
5427 }
5428
5429 /**
5430 * Called by a device admin to get the long support message.
5431 *
5432 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5433 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5434 * or null if no message has been set.
5435 */
5436 public String getLongSupportMessage(@NonNull ComponentName admin) {
5437 if (mService != null) {
5438 try {
5439 return mService.getLongSupportMessage(admin);
5440 } catch (RemoteException e) {
5441 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5442 }
5443 }
5444 return null;
5445 }
5446
5447 /**
5448 * Called by the system to get the short support message.
5449 *
5450 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5451 * @param userHandle user id the admin is running as.
5452 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5453 *
5454 * @hide
5455 */
5456 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5457 if (mService != null) {
5458 try {
5459 return mService.getShortSupportMessageForUser(admin, userHandle);
5460 } catch (RemoteException e) {
5461 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5462 }
5463 }
5464 return null;
5465 }
5466
5467
5468 /**
5469 * Called by the system to get the long support message.
5470 *
5471 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5472 * @param userHandle user id the admin is running as.
5473 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5474 *
5475 * @hide
5476 */
5477 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5478 if (mService != null) {
5479 try {
5480 return mService.getLongSupportMessageForUser(admin, userHandle);
5481 } catch (RemoteException e) {
5482 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5483 }
5484 }
5485 return null;
5486 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005487
5488 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005489 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5490 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005491 *
5492 * <p> Note only some methods will work on the parent Manager.
5493 *
5494 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5495 */
5496 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5497 try {
5498 if (!mService.isManagedProfile(admin)) {
5499 throw new SecurityException("The current user does not have a parent profile.");
5500 }
5501 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005502 } catch (RemoteException e) {
5503 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5504 return null;
5505 }
5506 }
5507
5508 /**
5509 * Called by device owner to control the device logging feature. Logging can only be
5510 * enabled on single user devices where the sole user is managed by the device owner.
5511 *
5512 * <p> Device logs contain various information intended for security auditing purposes.
5513 * See {@link SecurityEvent} for details.
5514 *
5515 * @param admin Which device owner this request is associated with.
5516 * @param enabled whether device logging should be enabled or not.
5517 * @see #retrieveDeviceLogs
5518 */
5519 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5520 try {
5521 mService.setDeviceLoggingEnabled(admin, enabled);
5522 } catch (RemoteException re) {
5523 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5524 }
5525 }
5526
5527 /**
5528 * Return whether device logging is enabled or not by the device owner.
5529 *
5530 * @param admin Which device owner this request is associated with.
5531 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5532 */
5533 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5534 try {
5535 return mService.getDeviceLoggingEnabled(admin);
5536 } catch (RemoteException re) {
5537 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5538 return false;
5539 }
5540 }
5541
5542 /**
5543 * Called by device owner to retrieve all new device logging entries since the last call to
5544 * this API after device boots.
5545 *
5546 * <p> Access to the logs is rate limited and it will only return new logs after the device
5547 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5548 *
5549 * @param admin Which device owner this request is associated with.
5550 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5551 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5552 */
5553 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5554 try {
5555 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5556 if (list != null) {
5557 return list.getList();
5558 } else {
5559 // Rate limit exceeded.
5560 return null;
5561 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005562 } catch (RemoteException re) {
5563 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5564 return null;
5565 }
5566 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005567
5568 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005569 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5570 * profile.
5571 *
5572 * @hide
5573 */
5574 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5575 mContext.checkSelfPermission(
5576 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5577 if (!uInfo.isManagedProfile()) {
5578 throw new SecurityException("The user " + uInfo.id
5579 + " does not have a parent profile.");
5580 }
5581 return new DevicePolicyManager(mContext, true);
5582 }
5583
5584 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005585 * Called by device owners to retrieve device logs from before the device's last reboot.
5586 *
5587 * <p>
5588 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5589 * corruption-free during power cycles, due to hardware variations and limitations. As a
5590 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5591 * </strong>
5592 *
5593 * @param admin Which device owner this request is associated with.
5594 * @return Device logs from before the latest reboot of the system.
5595 */
5596 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5597 try {
5598 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5599 return list.getList();
5600 } catch (RemoteException re) {
5601 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5602 return Collections.<SecurityEvent>emptyList();
5603 }
5604 }
5605
5606 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005607 * Called by a profile owner of a managed profile to set the color used for customization.
5608 * This color is used as background color of the confirm credentials screen for that user.
5609 * The default color is {@link android.graphics.Color#GRAY}.
5610 *
5611 * <p>The confirm credentials screen can be created using
5612 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5613 *
5614 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5615 * @param color The 32bit representation of the color to be used.
5616 */
5617 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5618 try {
5619 mService.setOrganizationColor(admin, color);
5620 } catch (RemoteException re) {
5621 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5622 }
5623 }
5624
5625 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005626 * @hide
5627 *
5628 * Sets the color used for customization.
5629 *
5630 * @param color The 32bit representation of the color to be used.
5631 * @param userId which user to set the color to.
5632 * @RequiresPermission(allOf = {
5633 * Manifest.permission.MANAGE_USERS,
5634 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5635 */
5636 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5637 try {
5638 mService.setOrganizationColorForUser(color, userId);
5639 } catch (RemoteException re) {
5640 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5641 }
5642 }
5643
5644 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005645 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5646 * This color is used as background color of the confirm credentials screen for that user.
5647 *
5648 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5649 * @return The 32bit representation of the color to be used.
5650 */
5651 public int getOrganizationColor(@NonNull ComponentName admin) {
5652 try {
5653 return mService.getOrganizationColor(admin);
5654 } catch (RemoteException re) {
5655 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5656 return 0;
5657 }
5658 }
5659
5660 /**
5661 * @hide
5662 * Retrieve the customization color for a given user.
5663 *
5664 * @param userHandle The user id of the user we're interested in.
5665 * @return The 32bit representation of the color to be used.
5666 */
5667 public int getOrganizationColorForUser(int userHandle) {
5668 try {
5669 return mService.getOrganizationColorForUser(userHandle);
5670 } catch (RemoteException re) {
5671 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5672 return 0;
5673 }
5674 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005675
5676 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005677 * Called by a profile owner of a managed profile to set the name of the organization under
5678 * management.
5679 *
5680 * <p>If the organization name needs to be localized, it is the responsibility of the
5681 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5682 * and set a new version of this string accordingly.
5683 *
5684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5685 * @param title The organization name or {@code null} to clear a previously set name.
5686 */
5687 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5688 try {
5689 mService.setOrganizationName(admin, title);
5690 } catch (RemoteException re) {
5691 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5692 }
5693 }
5694
5695 /**
5696 * Called by a profile owner of a managed profile to retrieve the name of the organization
5697 * under management.
5698 *
5699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5700 * @return The organization name or {@code null} if none is set.
5701 */
5702 public String getOrganizationName(@NonNull ComponentName admin) {
5703 try {
5704 return mService.getOrganizationName(admin);
5705 } catch (RemoteException re) {
5706 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5707 return null;
5708 }
5709 }
5710
5711 /**
5712 * Retrieve the default title message used in the confirm credentials screen for a given user.
5713 *
5714 * @param userHandle The user id of the user we're interested in.
5715 * @return The organization name or {@code null} if none is set.
5716 *
5717 * @hide
5718 */
5719 public String getOrganizationNameForUser(int userHandle) {
5720 try {
5721 return mService.getOrganizationNameForUser(userHandle);
5722 } catch (RemoteException re) {
5723 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE);
5724 return null;
5725 }
5726 }
5727
5728 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005729 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5730 * return {@link #STATE_USER_UNMANAGED}
5731 * @hide
5732 */
5733 @UserProvisioningState
5734 public int getUserProvisioningState() {
5735 if (mService != null) {
5736 try {
5737 return mService.getUserProvisioningState();
5738 } catch (RemoteException e) {
5739 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5740 }
5741 }
5742 return STATE_USER_UNMANAGED;
5743 }
5744
5745 /**
5746 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5747 *
5748 * @param state to store
5749 * @param userHandle for user
5750 * @hide
5751 */
5752 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5753 if (mService != null) {
5754 try {
5755 mService.setUserProvisioningState(state, userHandle);
5756 } catch (RemoteException e) {
5757 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
5758 }
5759 }
5760 }
5761
5762 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005763 * @hide
5764 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5765 * affiliated if it is managed by the same entity as the device.
5766 *
5767 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5768 * user/profile is considered affiliated if the following conditions are both met:
5769 * <ul>
5770 * <li>The device owner and the user's/profile's profile owner have called this method,
5771 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5772 * and a profile owner intersect, they must have come from the same source, which means that
5773 * the device owner and profile owner are controlled by the same entity.</li>
5774 * <li>The device owner's and profile owner's package names are the same.</li>
5775 * </ul>
5776 *
5777 * @param admin Which profile or device owner this request is associated with.
5778 * @param ids A set of opaque affiliation ids.
5779 */
5780 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5781 try {
5782 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5783 } catch (RemoteException e) {
5784 Log.w(TAG, "Failed talking with device policy service", e);
5785 }
5786 }
5787
5788 /**
5789 * @hide
5790 * Returns whether this user/profile is affiliated with the device. See
5791 * {@link #setAffiliationIds} for the definition of affiliation.
5792 *
5793 * @return whether this user/profile is affiliated with the device.
5794 */
5795 public boolean isAffiliatedUser() {
5796 try {
5797 return mService != null && mService.isAffiliatedUser();
5798 } catch (RemoteException e) {
5799 Log.w(TAG, "Failed talking with device policy service", e);
5800 return false;
5801 }
5802 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005803
5804 /**
5805 * @hide
5806 * Returns whether the uninstall for {@code packageName} for the current user is in queue
5807 * to be started
5808 * @param packageName the package to check for
5809 * @return whether the uninstall intent for {@code packageName} is pending
5810 */
5811 public boolean isUninstallInQueue(String packageName) {
5812 try {
5813 return mService.isUninstallInQueue(packageName);
5814 } catch (RemoteException re) {
5815 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5816 return false;
5817 }
5818 }
5819
5820 /**
5821 * @hide
5822 * @param packageName the package containing active DAs to be uninstalled
5823 */
5824 public void uninstallPackageWithActiveAdmins(String packageName) {
5825 try {
5826 mService.uninstallPackageWithActiveAdmins(packageName);
5827 } catch (RemoteException re) {
5828 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
5829 }
5830 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005831}