blob: 5285d52099d90ea922741981de760292a1bf89c2 [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
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000103 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000104 this(context,
105 IDevicePolicyManager.Stub.asInterface(
106 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
107 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108 }
109
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800110 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000112 protected DevicePolicyManager(
113 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 mContext = context;
115 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000116 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 }
118
119 /** @hide */
120 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000121 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800122 return me.mService != null ? me : null;
123 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700124
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700125 /** @hide test will override it. */
126 @VisibleForTesting
127 protected int myUserId() {
128 return UserHandle.myUserId();
129 }
130
Dianne Hackbornd6847842010-01-12 18:14:19 -0800131 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000132 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000133 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 * <p>A managed profile allows data separation for example for the usage of a
135 * device as a personal and corporate device. The user which provisioning is started from and
136 * the managed profile share a launcher.
137 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800138 * <p>This intent will typically be sent by a mobile device management application (MDM).
139 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
140 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100141 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000142 * <p>It is possible to check if provisioning is allowed or not by querying the method
143 * {@link #isProvisioningAllowed(String)}.
144 *
145 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000146 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700147 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000148 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
149 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000150 *
151 * <p> The intent may also contain the following extras:
152 * <ul>
153 * <li> {@link #EXTRA_PROVISIONING_LOGO_URI}, optional </li>
154 * <li> {@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional </li>
155 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156 *
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000157 * <p> When managed provisioning has completed, broadcasts are sent to the application specified
158 * in the provisioning intent. The
159 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
160 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
161 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100162 *
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100163 * <p> If provisioning fails, the managedProfile is removed so the device returns to its
164 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100165 *
166 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
167 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
168 * the provisioning flow was successful, although this doesn't guarantee the full flow will
169 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
170 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000171 */
172 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
173 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100174 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000175
176 /**
Mahaver Chopra5e732562015-11-05 11:55:12 +0000177 * @hide
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000178 * Activity action: Starts the provisioning flow which sets up a managed user.
179 *
180 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800181 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000182 * owner who has full control over the user. Provisioning can only happen before user setup has
183 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
184 * allowed.
185 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000186 * <p>This intent should contain the extra
187 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000188 *
189 * <p> If provisioning fails, the device returns to its previous state.
190 *
191 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
192 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
193 * the provisioning flow was successful, although this doesn't guarantee the full flow will
194 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
195 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Mahaver Chopra5e732562015-11-05 11:55:12 +0000196 */
197 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
198 public static final String ACTION_PROVISION_MANAGED_USER
199 = "android.app.action.PROVISION_MANAGED_USER";
200
201 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100202 * Activity action: Starts the provisioning flow which sets up a managed device.
203 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
204 *
205 * <p> During device owner provisioning a device admin app is set as the owner of the device.
206 * A device owner has full control over the device. The device owner can not be modified by the
207 * user.
208 *
209 * <p> A typical use case would be a device that is owned by a company, but used by either an
210 * employee or client.
211 *
212 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000213 * It is possible to check if provisioning is allowed or not by querying the method
214 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100215 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000216 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100217 * <ul>
218 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
219 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
220 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100221 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000222 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000223 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100224 * </ul>
225 *
226 * <p> When device owner provisioning has completed, an intent of the type
227 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
228 * device owner.
229 *
230 * <p> If provisioning fails, the device is factory reset.
231 *
Alan Treadway4582f812015-07-28 11:49:35 +0100232 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
233 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
234 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
235 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100236 */
237 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
238 public static final String ACTION_PROVISION_MANAGED_DEVICE
239 = "android.app.action.PROVISION_MANAGED_DEVICE";
240
241 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000242 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000243 *
244 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
245 * the device. A device owner has full control over the device. The device owner can not be
246 * modified by the user and the only way of resetting the device is via factory reset.
247 *
248 * <p>A typical use case would be a device that is owned by a company, but used by either an
249 * employee or client.
250 *
251 * <p>The provisioning message should be sent to an unprovisioned device.
252 *
253 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
254 * by a privileged app with the permission
255 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
256 *
257 * <p>The provisioning intent contains the following properties:
258 * <ul>
259 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
260 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
261 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
263 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
275 *
276 * @hide
277 */
278 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
279 @SystemApi
280 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
281 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
282
283 /**
284 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000285 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
286 *
287 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
288 * management state that is distinct from that reached by
289 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
290 * user, and only has control over device-wide policies, not individual users and their data.
291 * The primary benefit is that multiple non-system users are supported when provisioning using
292 * this form of device management.
293 *
294 * <p> During device owner provisioning a device admin app is set as the owner of the device.
295 * A device owner has full control over the device. The device owner can not be modified by the
296 * user.
297 *
298 * <p> A typical use case would be a device that is owned by a company, but used by either an
299 * employee or client.
300 *
301 * <p> An intent with this action can be sent only on an unprovisioned device.
302 * It is possible to check if provisioning is allowed or not by querying the method
303 * {@link #isProvisioningAllowed(String)}.
304 *
305 * <p>The intent contains the following extras:
306 * <ul>
307 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
308 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
309 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
310 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
311 * </ul>
312 *
313 * <p> When device owner provisioning has completed, an intent of the type
314 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
315 * device owner.
316 *
317 * <p> If provisioning fails, the device is factory reset.
318 *
319 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
320 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
321 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
322 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
323 *
324 * @hide
325 */
326 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
327 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
328 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
329
330 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000331 * Activity action: Finalizes management provisioning, should be used after user-setup
332 * has been completed and {@link #getUserProvisioningState()} returns one of:
333 * <ul>
334 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
335 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
336 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
337 * </ul>
338 *
339 * @hide
340 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000341 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000342 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
343 public static final String ACTION_PROVISION_FINALIZATION
344 = "android.app.action.PROVISION_FINALIZATION";
345
346 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100347 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100348 * allows a mobile device management application or NFC programmer application which starts
349 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100350 * <p>
351 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
352 * sends the intent to pass data to itself on the newly created profile.
353 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
354 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100355 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
356 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
357 * message should contain a stringified {@link java.util.Properties} instance, whose string
358 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
359 * management application after provisioning.
360 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100361 * <p>
362 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700363 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
364 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100365 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100366 */
367 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100368 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100369
370 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100371 * A String extra holding the package name of the mobile device management application that
372 * will be set as the profile owner or device owner.
373 *
374 * <p>If an application starts provisioning directly via an intent with action
375 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
376 * application that started provisioning. The package will be set as profile owner in that case.
377 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000378 * <p>This package is set as device owner when device owner provisioning is started by an NFC
379 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000380 *
381 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700382 * This receiver will be set as the profile or device owner and active admin.
Nicolas Prevot18440252015-03-09 14:07:17 +0000383
384 * @see DeviceAdminReceiver
385 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100386 * supported, but only if there is only one device admin receiver in the package that requires
387 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000388 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000389 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000390 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100391 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000392
393 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000394 * A ComponentName extra indicating the device admin receiver of the mobile device management
395 * application that will be set as the profile owner or device owner and active admin.
396 *
397 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100398 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
399 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
400 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000401 *
402 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100403 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
404 * message containing an NFC record with MIME type
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400405 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name should be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000406 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000407 *
408 * @see DeviceAdminReceiver
409 */
410 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
411 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
412
413 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000414 * An {@link android.accounts.Account} extra holding the account to migrate during managed
415 * profile provisioning. If the account supplied is present in the primary user, it will be
416 * copied, along with its credentials to the managed profile and removed from the primary user.
417 *
418 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
419 */
420
421 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
422 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
423
424 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100425 * A String extra that, holds the email address of the account which a managed profile is
426 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
427 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100428 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100429 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
430 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100431 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
432 * contains this extra, it is forwarded in the
433 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
434 * device management application that was set as the profile owner during provisioning.
435 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100436 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100437 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
438 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100439
440 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000441 * A integer extra indicating the predominant color to show during the provisioning.
442 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000443 *
444 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
445 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
446 */
447 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
448 "android.app.extra.PROVISIONING_MAIN_COLOR";
449
450 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000451 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700452 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000453 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100454 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
455 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000456 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000457 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
458 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000459
460 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100461 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
462 * will be set to.
463 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000464 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
465 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100466 */
467 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100468 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100469
470 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100471 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
472 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100473 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000474 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
475 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100476 */
477 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100478 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100479
480 /**
481 * A String extra holding the {@link java.util.Locale} that the device will be set to.
482 * Format: xx_yy, where xx is the language code, and yy the country code.
483 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000484 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
485 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100486 */
487 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100488 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100489
490 /**
491 * A String extra holding the ssid of the wifi network that should be used during nfc device
492 * owner provisioning for downloading the mobile device management application.
493 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000494 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
495 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100496 */
497 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100498 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100499
500 /**
501 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
502 * is hidden or not.
503 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000504 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
505 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100506 */
507 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100508 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100509
510 /**
511 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100512 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
513 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100514 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000515 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
516 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100517 */
518 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100519 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100520
521 /**
522 * A String extra holding the password of the wifi network in
523 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
524 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000525 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
526 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100527 */
528 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100529 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100530
531 /**
532 * A String extra holding the proxy host for the wifi network in
533 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
534 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000535 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
536 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100537 */
538 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100539 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100540
541 /**
542 * An int extra holding the proxy port for the wifi network in
543 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
544 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000545 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
546 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100547 */
548 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100549 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100550
551 /**
552 * A String extra holding the proxy bypass for the wifi network in
553 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
554 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000555 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
556 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100557 */
558 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100559 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100560
561 /**
562 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
563 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
564 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
566 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100567 */
568 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100569 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100570
571 /**
572 * A String extra holding a url that specifies the download location of the device admin
573 * package. When not provided it is assumed that the device admin package is already installed.
574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
576 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577 */
578 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100579 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580
581 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400582 * An int extra holding a minimum required version code for the device admin package. If the
583 * device admin is already installed on the device, it will only be re-downloaded from
584 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
585 * installed package is less than this version code.
586 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400588 * provisioning via an NFC bump.
589 */
590 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
591 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
592
593 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100594 * A String extra holding a http cookie header which should be used in the http request to the
595 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
596 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000597 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
598 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100599 */
600 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100602
603 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100604 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
605 * the file at download location specified in
606 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100607 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100608 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} should be
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100609 * present. The provided checksum should match the checksum of the file at the download
610 * location. If the checksum doesn't match an error will be shown to the user and the user will
611 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000613 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
614 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100615 *
616 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
617 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700618 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100619 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 */
621 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100622 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623
624 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100625 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100626 * android package archive at the download location specified in {@link
627 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
628 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100629 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100630 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
631 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
632 *
633 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} should be
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100634 * present. The provided checksum should match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100635 * the download location. If the checksum does not match an error will be shown to the user and
636 * the user will be asked to factory reset the device.
637 *
638 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
639 * provisioning via an NFC bump.
640 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100641 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
642 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100643
644 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000645 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
646 * has completed successfully.
647 *
648 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700649 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000650 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800651 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000652 * corresponds to the account requested to be migrated at provisioning time, if any.
653 */
654 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
655 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
656 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
657
658 /**
Julia Reynolds2f46d942015-05-05 11:44:20 -0400659 * A boolean extra indicating whether device encryption can be skipped as part of Device Owner
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500660 * provisioning.
661 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400662 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100663 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500664 */
665 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
666 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
667
668 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000669 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
670 * provisioning. If this extra is not passed, a default image will be shown.
671 * <h5>The following URI schemes are accepted:</h5>
672 * <ul>
673 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
674 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
675 * </ul>
676 *
677 * <p> It is the responsability of the caller to provide an image with a reasonable
678 * pixed density for the device.
679 *
680 * <p> If a content: URI is passed, the intent should have the flag
681 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
682 * {@link android.content.ClipData} of the intent too.
683 *
684 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
685 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
686 */
687 public static final String EXTRA_PROVISIONING_LOGO_URI =
688 "android.app.extra.PROVISIONING_LOGO_URI";
689
690 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000691 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
692 * during setup-wizard.
693 *
694 * <p>If unspecified, defaults to {@code true} to match the behavior in
695 * {@link android.os.Build.VERSION_CODES#M} and earlier.
696 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000697 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
698 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000699 *
700 * @hide
701 */
702 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
703 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
704
705 /**
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400706 * This MIME type is used for starting the Device Owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100707 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400708 * <p>During device owner provisioning a device admin app is set as the owner of the device.
709 * A device owner has full control over the device. The device owner can not be modified by the
710 * user and the only way of resetting the device is if the device owner app calls a factory
711 * reset.
712 *
713 * <p> A typical use case would be a device that is owned by a company, but used by either an
714 * employee or client.
715 *
716 * <p> The NFC message should be send to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100717 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000718 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100719 * contains the following properties:
720 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400721 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
722 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100723 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400724 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100725 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
726 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
727 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
728 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
729 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
730 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
731 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
732 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
733 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
734 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100735 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
736 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
737 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100738 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000739 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700740 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400741 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
742 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
743 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400744 */
745 public static final String MIME_TYPE_PROVISIONING_NFC
746 = "application/com.android.managedprovisioning";
747
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100748 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800749 * Activity action: ask the user to add a new device administrator to the system.
750 * The desired policy is the ComponentName of the policy in the
751 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
752 * bring the user through adding the device administrator to the system (or
753 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700754 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800755 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
756 * field to provide the user with additional explanation (in addition
757 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800758 *
759 * <p>If your administrator is already active, this will ordinarily return immediately (without
760 * user intervention). However, if your administrator has been updated and is requesting
761 * additional uses-policy flags, the user will be presented with the new list. New policies
762 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800763 */
764 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
765 public static final String ACTION_ADD_DEVICE_ADMIN
766 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700767
Dianne Hackbornd6847842010-01-12 18:14:19 -0800768 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700769 * @hide
770 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700771 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700772 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700773 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
774 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700775 * to remotely control restrictions on the user.
776 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800777 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700778 * result of whether or not the user approved the action. If approved, the result will
779 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
780 * as a profile owner.
781 *
782 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
783 * field to provide the user with additional explanation (in addition
784 * to your component's description) about what is being added.
785 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700786 * <p>If there is already a profile owner active or the caller is not a system app, the
787 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700788 */
789 @SystemApi
790 public static final String ACTION_SET_PROFILE_OWNER
791 = "android.app.action.SET_PROFILE_OWNER";
792
793 /**
794 * @hide
795 * Name of the profile owner admin that controls the user.
796 */
797 @SystemApi
798 public static final String EXTRA_PROFILE_OWNER_NAME
799 = "android.app.extra.PROFILE_OWNER_NAME";
800
801 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100802 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700803 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700804 *
Jim Miller284b62e2010-06-08 14:27:42 -0700805 * @hide
806 */
807 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
808 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
809
810 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100811 * Broadcast action: sent when the device owner is set or changed.
812 *
813 * This broadcast is sent only to the primary user.
814 * @see #ACTION_PROVISION_MANAGED_DEVICE
815 */
816 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
817 public static final String ACTION_DEVICE_OWNER_CHANGED
818 = "android.app.action.DEVICE_OWNER_CHANGED";
819
820 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800821 * The ComponentName of the administrator component.
822 *
823 * @see #ACTION_ADD_DEVICE_ADMIN
824 */
825 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700826
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800828 * An optional CharSequence providing additional explanation for why the
829 * admin is being added.
830 *
831 * @see #ACTION_ADD_DEVICE_ADMIN
832 */
833 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700834
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800835 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700836 * Activity action: have the user enter a new password. This activity should
837 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
838 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
839 * enter a new password that meets the current requirements. You can use
840 * {@link #isActivePasswordSufficient()} to determine whether you need to
841 * have the user select a new password in order to meet the current
842 * constraints. Upon being resumed from this activity, you can check the new
843 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000844 *
845 * If the intent is launched from within a managed profile with a profile
846 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
847 * this will trigger entering a new password for the parent of the profile.
848 * For all other cases it will trigger entering a new password for the user
849 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000850 *
851 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
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 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000933 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000934 public static final int STATE_USER_UNMANAGED = 0;
935
936 /**
937 * Management partially setup, user setup needs to be completed.
938 * @hide
939 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000940 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000941 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
942
943 /**
944 * Management partially setup, user setup completed.
945 * @hide
946 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000947 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000948 public static final int STATE_USER_SETUP_COMPLETE = 2;
949
950 /**
951 * Management setup and active on current user.
952 * @hide
953 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000954 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000955 public static final int STATE_USER_SETUP_FINALIZED = 3;
956
957 /**
958 * Management partially setup on a managed profile.
959 * @hide
960 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000961 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000962 public static final int STATE_USER_PROFILE_COMPLETE = 4;
963
964 /**
965 * @hide
966 */
967 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
968 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
969 @Retention(RetentionPolicy.SOURCE)
970 public @interface UserProvisioningState {}
971
972 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800973 * Return true if the given administrator component is currently
974 * active (enabled) in the system.
975 */
Robin Lee25e26452015-06-02 09:56:29 -0700976 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700977 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +0100978 }
979
980 /**
981 * @see #isAdminActive(ComponentName)
982 * @hide
983 */
Robin Lee25e26452015-06-02 09:56:29 -0700984 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -0800985 if (mService != null) {
986 try {
Robin Lee25e26452015-06-02 09:56:29 -0700987 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800988 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -0700989 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800990 }
991 }
992 return false;
993 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -0800994 /**
995 * Return true if the given administrator component is currently being removed
996 * for the user.
997 * @hide
998 */
Robin Lee25e26452015-06-02 09:56:29 -0700999 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001000 if (mService != null) {
1001 try {
Robin Lee25e26452015-06-02 09:56:29 -07001002 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001003 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001004 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001005 }
1006 }
1007 return false;
1008 }
1009
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001010
Dianne Hackbornd6847842010-01-12 18:14:19 -08001011 /**
Robin Lee25e26452015-06-02 09:56:29 -07001012 * Return a list of all currently active device administrators' component
1013 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001014 * returned.
1015 */
1016 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001017 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001018 }
1019
1020 /**
1021 * @see #getActiveAdmins()
1022 * @hide
1023 */
1024 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001025 if (mService != null) {
1026 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001027 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001028 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001029 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001030 }
1031 }
1032 return null;
1033 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001034
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001035 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001036 * Used by package administration code to determine if a package can be stopped
1037 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001038 * @hide
1039 */
1040 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001041 return packageHasActiveAdmins(packageName, myUserId());
1042 }
1043
1044 /**
1045 * Used by package administration code to determine if a package can be stopped
1046 * or uninstalled.
1047 * @hide
1048 */
1049 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001050 if (mService != null) {
1051 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001052 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001053 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001054 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001055 }
1056 }
1057 return false;
1058 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001059
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001060 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001061 * Remove a current administration component. This can only be called
1062 * by the application that owns the administration component; if you
1063 * try to remove someone else's component, a security exception will be
1064 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001065 *
1066 * <p>Note that the operation is not synchronous and the admin might still be active (as
1067 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 */
Robin Lee25e26452015-06-02 09:56:29 -07001069 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001070 if (mService != null) {
1071 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001072 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001073 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001074 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001075 }
1076 }
1077 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001078
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 /**
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001080 * Returns true if an administrator has been granted a particular device policy. This can
Robin Lee25e26452015-06-02 09:56:29 -07001081 * be used to check whether the administrator was activated under an earlier set of policies,
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001082 * but requires additional policies after an upgrade.
1083 *
1084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be
1085 * an active administrator, or an exception will be thrown.
1086 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
1087 */
Robin Lee25e26452015-06-02 09:56:29 -07001088 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001089 if (mService != null) {
1090 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001091 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001092 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001093 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001094 }
1095 }
1096 return false;
1097 }
1098
1099 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001100 * Returns true if the Profile Challenge is available to use for the given profile user.
1101 *
1102 * @hide
1103 */
1104 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1105 if (mService != null) {
1106 try {
1107 return mService.isSeparateProfileChallengeAllowed(userHandle);
1108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001109 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001110 }
1111 }
1112 return false;
1113 }
1114
1115 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001116 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1117 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001118 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001119 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001120 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001121
Dianne Hackbornd6847842010-01-12 18:14:19 -08001122 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001123 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1124 * recognition technology. This implies technologies that can recognize the identity of
1125 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1126 * Note that quality constants are ordered so that higher values are more restrictive.
1127 */
1128 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1129
1130 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001131 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001132 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001133 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001134 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001135 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001136
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001137 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001138 * Constant for {@link #setPasswordQuality}: the user must have entered a
1139 * password containing at least numeric characters. Note that quality
1140 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001141 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001142 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001143
Dianne Hackbornd6847842010-01-12 18:14:19 -08001144 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001145 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001146 * password containing at least numeric characters with no repeating (4444)
1147 * or ordered (1234, 4321, 2468) sequences. Note that quality
1148 * constants are ordered so that higher values are more restrictive.
1149 */
1150 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1151
1152 /**
1153 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001154 * password containing at least alphabetic (or other symbol) characters.
1155 * Note that quality constants are ordered so that higher values are more
1156 * restrictive.
1157 */
1158 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001160 /**
1161 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001162 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001163 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001164 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001165 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001166 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001167
Dianne Hackbornd6847842010-01-12 18:14:19 -08001168 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001169 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001170 * password containing at least a letter, a numerical digit and a special
1171 * symbol, by default. With this password quality, passwords can be
1172 * restricted to contain various sets of characters, like at least an
1173 * uppercase letter, etc. These are specified using various methods,
1174 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1175 * that quality constants are ordered so that higher values are more
1176 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001177 */
1178 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1179
1180 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001181 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1182 * modify password. In case this password quality is set, the password is
1183 * managed by a profile owner. The profile owner can set any password,
1184 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1185 * that quality constants are ordered so that higher values are more
1186 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1187 * the highest.
1188 * @hide
1189 */
1190 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1191
1192 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001193 * Called by an application that is administering the device to set the
1194 * password restrictions it is imposing. After setting this, the user
1195 * will not be able to enter a new password that is not at least as
1196 * restrictive as what has been set. Note that the current password
1197 * will remain until the user has set a new one, so the change does not
1198 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001199 * {@link #ACTION_SET_NEW_PASSWORD} or
1200 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001201 *
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001202 * <p>Quality constants are ordered so that higher values are more restrictive;
1203 * thus the highest requested quality constant (between the policy set here,
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001204 * the user's preference, and any other considerations) is the one that
1205 * is in effect.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001206 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001207 * <p>The calling device admin must have requested
1208 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1209 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001210 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001211 * <p>This method can be called on the {@link DevicePolicyManager} instance
1212 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1213 * restrictions on the parent profile.
1214 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001216 * @param quality The new desired quality. One of
1217 * {@link #PASSWORD_QUALITY_UNSPECIFIED}, {@link #PASSWORD_QUALITY_SOMETHING},
Jim Miller85516d02014-01-31 17:08:37 -08001218 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1219 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1220 * or {@link #PASSWORD_QUALITY_COMPLEX}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001221 */
Robin Lee25e26452015-06-02 09:56:29 -07001222 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001223 if (mService != null) {
1224 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001225 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001226 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001227 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001228 }
1229 }
1230 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001231
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001233 * Retrieve the current minimum password quality for a particular admin or all admins that set
1234 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1235 * a separate challenge are not taken into account.
1236 *
1237 * <p>This method can be called on the {@link DevicePolicyManager} instance
1238 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1239 * restrictions on the parent profile.
1240 *
Robin Lee25e26452015-06-02 09:56:29 -07001241 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001242 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001243 */
Robin Lee25e26452015-06-02 09:56:29 -07001244 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001245 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001246 }
1247
1248 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001249 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 if (mService != null) {
1251 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001252 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001254 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001255 }
1256 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001257 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001258 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001259
Dianne Hackbornd6847842010-01-12 18:14:19 -08001260 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001261 * Called by an application that is administering the device to set the
1262 * minimum allowed password length. After setting this, the user
1263 * will not be able to enter a new password that is not at least as
1264 * restrictive as what has been set. Note that the current password
1265 * will remain until the user has set a new one, so the change does not
1266 * take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001267 * {@link #ACTION_SET_NEW_PASSWORD} or
1268 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Dianne Hackbornd6847842010-01-12 18:14:19 -08001269 * constraint is only imposed if the administrator has also requested either
Jim Miller85516d02014-01-31 17:08:37 -08001270 * {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX},
1271 * {@link #PASSWORD_QUALITY_ALPHABETIC}, {@link #PASSWORD_QUALITY_ALPHANUMERIC},
1272 * or {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001273 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001274 * <p>The calling device admin must have requested
1275 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1276 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001277 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001278 * <p>This method can be called on the {@link DevicePolicyManager} instance
1279 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1280 * restrictions on the parent profile.
1281 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001282 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001283 * @param length The new desired minimum password length. A value of 0
1284 * means there is no restriction.
1285 */
Robin Lee25e26452015-06-02 09:56:29 -07001286 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001287 if (mService != null) {
1288 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001289 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001291 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001292 }
1293 }
1294 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001295
Dianne Hackbornd6847842010-01-12 18:14:19 -08001296 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001297 * Retrieve the current minimum password length for a particular admin or all admins that set
1298 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1299 * a separate challenge are not taken into account.
1300 *
1301 * <p>This method can be called on the {@link DevicePolicyManager} instance
1302 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1303 * restrictions on the parent profile.
1304 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001305 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001306 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001307 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001308 */
Robin Lee25e26452015-06-02 09:56:29 -07001309 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001310 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001311 }
1312
1313 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001314 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001315 if (mService != null) {
1316 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001317 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001318 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001319 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001320 }
1321 }
1322 return 0;
1323 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001324
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001325 /**
1326 * Called by an application that is administering the device to set the
1327 * minimum number of upper case letters required in the password. After
1328 * setting this, the user will not be able to enter a new password that is
1329 * not at least as restrictive as what has been set. Note that the current
1330 * password will remain until the user has set a new one, so the change does
1331 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001332 * {@link #ACTION_SET_NEW_PASSWORD} or
1333 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001334 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001335 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1336 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001337 * <p>
1338 * The calling device admin must have requested
1339 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1340 * this method; if it has not, a security exception will be thrown.
1341 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001342 * <p>This method can be called on the {@link DevicePolicyManager} instance
1343 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1344 * restrictions on the parent profile.
1345 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001346 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1347 * with.
1348 * @param length The new desired minimum number of upper case letters
1349 * required in the password. A value of 0 means there is no
1350 * restriction.
1351 */
Robin Lee25e26452015-06-02 09:56:29 -07001352 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001353 if (mService != null) {
1354 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001355 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001356 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001357 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001358 }
1359 }
1360 }
1361
1362 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001363 * Retrieve the current number of upper case letters required in the password
1364 * for a particular admin or all admins that set retrictions on this user and
1365 * its participating profiles. Restrictions on profiles that have a separate challenge
1366 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001367 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001368 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001369 * and only applies when the password quality is
1370 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001371 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001372 * <p>This method can be called on the {@link DevicePolicyManager} instance
1373 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1374 * restrictions on the parent profile.
1375 *
Robin Lee25e26452015-06-02 09:56:29 -07001376 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001377 * aggregate all admins.
1378 * @return The minimum number of upper case letters required in the
1379 * password.
1380 */
Robin Lee25e26452015-06-02 09:56:29 -07001381 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001382 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001383 }
1384
1385 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001386 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001387 if (mService != null) {
1388 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001389 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001391 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001392 }
1393 }
1394 return 0;
1395 }
1396
1397 /**
1398 * Called by an application that is administering the device to set the
1399 * minimum number of lower case letters required in the password. After
1400 * setting this, the user will not be able to enter a new password that is
1401 * not at least as restrictive as what has been set. Note that the current
1402 * password will remain until the user has set a new one, so the change does
1403 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001404 * {@link #ACTION_SET_NEW_PASSWORD} or
1405 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001406 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001407 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1408 * default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001409 * <p>
1410 * The calling device admin must have requested
1411 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1412 * this method; if it has not, a security exception will be thrown.
1413 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001414 * <p>This method can be called on the {@link DevicePolicyManager} instance
1415 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1416 * restrictions on the parent profile.
1417 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001418 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1419 * with.
1420 * @param length The new desired minimum number of lower case letters
1421 * required in the password. A value of 0 means there is no
1422 * restriction.
1423 */
Robin Lee25e26452015-06-02 09:56:29 -07001424 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001425 if (mService != null) {
1426 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001427 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001428 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001429 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001430 }
1431 }
1432 }
1433
1434 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001435 * Retrieve the current number of lower case letters required in the password
1436 * for a particular admin or all admins that set retrictions on this user
1437 * and its participating profiles. Restrictions on profiles that have
1438 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001439 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001440 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001441 * and only applies when the password quality is
1442 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001443 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001444 * <p>This method can be called on the {@link DevicePolicyManager} instance
1445 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1446 * restrictions on the parent profile.
1447 *
Robin Lee25e26452015-06-02 09:56:29 -07001448 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001449 * aggregate all admins.
1450 * @return The minimum number of lower case letters required in the
1451 * password.
1452 */
Robin Lee25e26452015-06-02 09:56:29 -07001453 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001454 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001455 }
1456
1457 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001458 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001459 if (mService != null) {
1460 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001461 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001462 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001463 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001464 }
1465 }
1466 return 0;
1467 }
1468
1469 /**
1470 * Called by an application that is administering the device to set the
1471 * minimum number of letters required in the password. After setting this,
1472 * the user will not be able to enter a new password that is not at least as
1473 * restrictive as what has been set. Note that the current password will
1474 * remain until the user has set a new one, so the change does not take
1475 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001476 * {@link #ACTION_SET_NEW_PASSWORD} or
1477 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001478 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001479 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1480 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001481 * <p>
1482 * The calling device admin must have requested
1483 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1484 * this method; if it has not, a security exception will be thrown.
1485 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001486 * <p>This method can be called on the {@link DevicePolicyManager} instance
1487 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1488 * restrictions on the parent profile.
1489 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001490 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1491 * with.
1492 * @param length The new desired minimum number of letters required in the
1493 * password. A value of 0 means there is no restriction.
1494 */
Robin Lee25e26452015-06-02 09:56:29 -07001495 public void setPasswordMinimumLetters(@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.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001499 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001500 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001501 }
1502 }
1503 }
1504
1505 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001506 * Retrieve the current number of letters required in the password
1507 * for a particular admin or all admins that set retrictions on this user
1508 * and its participating profiles. Restrictions on profiles that have
1509 * a separate challenge are not taken into account.
1510 * This is the same value as set by
1511 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001512 * and only applies when the password quality is
1513 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001514 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001515 * <p>This method can be called on the {@link DevicePolicyManager} instance
1516 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1517 * restrictions on the parent profile.
1518 *
Robin Lee25e26452015-06-02 09:56:29 -07001519 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001520 * aggregate all admins.
1521 * @return The minimum number of letters required in the password.
1522 */
Robin Lee25e26452015-06-02 09:56:29 -07001523 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001524 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001525 }
1526
1527 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001528 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001529 if (mService != null) {
1530 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001531 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001532 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001533 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001534 }
1535 }
1536 return 0;
1537 }
1538
1539 /**
1540 * Called by an application that is administering the device to set the
1541 * minimum number of numerical digits required in the password. After
1542 * setting this, the user will not be able to enter a new password that is
1543 * not at least as restrictive as what has been set. Note that the current
1544 * password will remain until the user has set a new one, so the change does
1545 * not take place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001546 * {@link #ACTION_SET_NEW_PASSWORD} or
1547 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001548 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001549 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1550 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001551 * <p>
1552 * The calling device admin must have requested
1553 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1554 * this method; if it has not, a security exception will be thrown.
1555 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001556 * <p>This method can be called on the {@link DevicePolicyManager} instance
1557 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1558 * restrictions on the parent profile.
1559 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001560 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1561 * with.
1562 * @param length The new desired minimum number of numerical digits required
1563 * in the password. A value of 0 means there is no restriction.
1564 */
Robin Lee25e26452015-06-02 09:56:29 -07001565 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001566 if (mService != null) {
1567 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001568 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001569 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001570 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001571 }
1572 }
1573 }
1574
1575 /**
1576 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001577 * for a particular admin or all admins that set retrictions on this user
1578 * and its participating profiles. Restrictions on profiles that have
1579 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001580 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001581 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001582 * and only applies when the password quality is
1583 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001584 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001585 * <p>This method can be called on the {@link DevicePolicyManager} instance
1586 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1587 * restrictions on the parent profile.
1588 *
Robin Lee25e26452015-06-02 09:56:29 -07001589 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001590 * aggregate all admins.
1591 * @return The minimum number of numerical digits required in the password.
1592 */
Robin Lee25e26452015-06-02 09:56:29 -07001593 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001594 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001595 }
1596
1597 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001598 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001599 if (mService != null) {
1600 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001601 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001602 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001603 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001604 }
1605 }
1606 return 0;
1607 }
1608
1609 /**
1610 * Called by an application that is administering the device to set the
1611 * minimum number of symbols required in the password. After setting this,
1612 * the user will not be able to enter a new password that is not at least as
1613 * restrictive as what has been set. Note that the current password will
1614 * remain until the user has set a new one, so the change does not take
1615 * place immediately. To prompt the user for a new password, use
Esteban Talaverac1c83592016-02-17 17:56:15 +00001616 * {@link #ACTION_SET_NEW_PASSWORD} or
1617 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001618 * constraint is only imposed if the administrator has also requested
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001619 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The
1620 * default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001621 * <p>
1622 * The calling device admin must have requested
1623 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1624 * this method; if it has not, a security exception will be thrown.
1625 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001626 * <p>This method can be called on the {@link DevicePolicyManager} instance
1627 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1628 * restrictions on the parent profile.
1629 *
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001630 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1631 * with.
1632 * @param length The new desired minimum number of symbols required in the
1633 * password. A value of 0 means there is no restriction.
1634 */
Robin Lee25e26452015-06-02 09:56:29 -07001635 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001636 if (mService != null) {
1637 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001638 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001640 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001641 }
1642 }
1643 }
1644
1645 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001646 * Retrieve the current number of symbols required in the password
1647 * for a particular admin or all admins that set retrictions on this user
1648 * and its participating profiles. Restrictions on profiles that have
1649 * a separate challenge are not taken into account. This is the same value as
1650 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001651 * and only applies when the password quality is
1652 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001653 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001654 * <p>This method can be called on the {@link DevicePolicyManager} instance
1655 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1656 * restrictions on the parent profile.
1657 *
Robin Lee25e26452015-06-02 09:56:29 -07001658 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001659 * aggregate all admins.
1660 * @return The minimum number of symbols required in the password.
1661 */
Robin Lee25e26452015-06-02 09:56:29 -07001662 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001663 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001664 }
1665
1666 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001667 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001668 if (mService != null) {
1669 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001670 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001671 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001672 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001673 }
1674 }
1675 return 0;
1676 }
1677
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001678 /**
1679 * Called by an application that is administering the device to set the
1680 * minimum number of non-letter characters (numerical digits or symbols)
1681 * required in the password. After setting this, the user will not be able
1682 * to enter a new password that is not at least as restrictive as what has
1683 * been set. Note that the current password will remain until the user has
1684 * set a new one, so the change does not take place immediately. To prompt
Esteban Talaverac1c83592016-02-17 17:56:15 +00001685 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1686 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001687 * setting this value. This constraint is only imposed if the administrator
1688 * has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1689 * {@link #setPasswordQuality}. The default value is 0.
1690 * <p>
1691 * The calling device admin must have requested
1692 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1693 * this method; if it has not, a security exception will be thrown.
1694 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001695 * <p>This method can be called on the {@link DevicePolicyManager} instance
1696 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1697 * restrictions on the parent profile.
1698 *
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001699 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1700 * with.
1701 * @param length The new desired minimum number of letters required in the
1702 * password. A value of 0 means there is no restriction.
1703 */
Robin Lee25e26452015-06-02 09:56:29 -07001704 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001705 if (mService != null) {
1706 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001707 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001709 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001710 }
1711 }
1712 }
1713
1714 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001715 * Retrieve the current number of non-letter characters required in the password
1716 * for a particular admin or all admins that set retrictions on this user
1717 * and its participating profiles. Restrictions on profiles that have
1718 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001719 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001720 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001721 * and only applies when the password quality is
1722 * {@link #PASSWORD_QUALITY_COMPLEX}.
1723 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001724 * <p>This method can be called on the {@link DevicePolicyManager} instance
1725 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1726 * restrictions on the parent profile.
1727 *
Robin Lee25e26452015-06-02 09:56:29 -07001728 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001729 * aggregate all admins.
1730 * @return The minimum number of letters required in the password.
1731 */
Robin Lee25e26452015-06-02 09:56:29 -07001732 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001733 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001734 }
1735
1736 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001737 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001738 if (mService != null) {
1739 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001740 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001741 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001742 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001743 }
1744 }
1745 return 0;
1746 }
1747
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001748 /**
1749 * Called by an application that is administering the device to set the length
1750 * of the password history. After setting this, the user will not be able to
1751 * enter a new password that is the same as any password in the history. Note
1752 * that the current password will remain until the user has set a new one, so
1753 * the change does not take place immediately. To prompt the user for a new
Esteban Talaverac1c83592016-02-17 17:56:15 +00001754 * password, use {@link #ACTION_SET_NEW_PASSWORD} or
1755 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001756 * This constraint is only imposed if the administrator has also requested
Jim Miller85516d02014-01-31 17:08:37 -08001757 * either {@link #PASSWORD_QUALITY_NUMERIC}, {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}
1758 * {@link #PASSWORD_QUALITY_ALPHABETIC}, or {@link #PASSWORD_QUALITY_ALPHANUMERIC}
1759 * with {@link #setPasswordQuality}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001760 *
1761 * <p>
1762 * The calling device admin must have requested
1763 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this
1764 * method; if it has not, a security exception will be thrown.
1765 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001766 * <p>This method can be called on the {@link DevicePolicyManager} instance
1767 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1768 * restrictions on the parent profile.
1769 *
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001770 * @param admin Which {@link DeviceAdminReceiver} this request is associated
1771 * with.
1772 * @param length The new desired length of password history. A value of 0
1773 * means there is no restriction.
1774 */
Robin Lee25e26452015-06-02 09:56:29 -07001775 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001776 if (mService != null) {
1777 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001778 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001779 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001780 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001781 }
1782 }
1783 }
1784
1785 /**
Jim Millera4e28d12010-11-08 16:15:47 -08001786 * Called by a device admin to set the password expiration timeout. Calling this method
1787 * will restart the countdown for password expiration for the given admin, as will changing
1788 * the device password (for all admins).
1789 *
1790 * <p>The provided timeout is the time delta in ms and will be added to the current time.
1791 * For example, to have the password expire 5 days from now, timeout would be
1792 * 5 * 86400 * 1000 = 432000000 ms for timeout.
1793 *
1794 * <p>To disable password expiration, a value of 0 may be used for timeout.
1795 *
Jim Millera4e28d12010-11-08 16:15:47 -08001796 * <p>The calling device admin must have requested
1797 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
1798 * method; if it has not, a security exception will be thrown.
1799 *
Jessica Hummel9da60392014-05-21 12:32:57 +01001800 * <p> Note that setting the password will automatically reset the expiration time for all
1801 * active admins. Active admins do not need to explicitly call this method in that case.
1802 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001803 * <p>This method can be called on the {@link DevicePolicyManager} instance
1804 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
1805 * restrictions on the parent profile.
1806 *
Jim Millera4e28d12010-11-08 16:15:47 -08001807 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1808 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0
1809 * means there is no restriction (unlimited).
1810 */
Robin Lee25e26452015-06-02 09:56:29 -07001811 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001812 if (mService != null) {
1813 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001814 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001816 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001817 }
1818 }
1819 }
1820
1821 /**
Jim Miller6b857682011-02-16 16:27:41 -08001822 * Get the password expiration timeout for the given admin. The expiration timeout is the
1823 * recurring expiration timeout provided in the call to
1824 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001825 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1826 * have set restrictions on profiles that have a separate challenge are not taken into account.
1827 *
1828 * <p>This method can be called on the {@link DevicePolicyManager} instance
1829 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1830 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001831 *
Robin Lee25e26452015-06-02 09:56:29 -07001832 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001833 * @return The timeout for the given admin or the minimum of all timeouts
1834 */
Robin Lee25e26452015-06-02 09:56:29 -07001835 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001836 if (mService != null) {
1837 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001838 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001839 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001840 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001841 }
1842 }
1843 return 0;
1844 }
1845
1846 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001847 * Get the current password expiration time for a particular admin or all admins that set
1848 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1849 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1850 * of all expiration times is returned - which will be the minimum of all of them.
1851 *
1852 * <p>This method can be called on the {@link DevicePolicyManager} instance
1853 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1854 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001855 *
Robin Lee25e26452015-06-02 09:56:29 -07001856 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001857 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001858 */
Robin Lee25e26452015-06-02 09:56:29 -07001859 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001860 if (mService != null) {
1861 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001862 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001863 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001864 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001865 }
1866 }
1867 return 0;
1868 }
1869
1870 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001871 * Retrieve the current password history length for a particular admin or all admins that
1872 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1873 * have a separate challenge are not taken into account.
1874 *
1875 * <p>This method can be called on the {@link DevicePolicyManager} instance
1876 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1877 * restrictions on the parent profile.
1878 *
Robin Lee25e26452015-06-02 09:56:29 -07001879 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001880 * all admins.
1881 * @return The length of the password history
1882 */
Robin Lee25e26452015-06-02 09:56:29 -07001883 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001884 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001885 }
1886
1887 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001888 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001889 if (mService != null) {
1890 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001891 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001892 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001893 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001894 }
1895 }
1896 return 0;
1897 }
1898
Dianne Hackbornd6847842010-01-12 18:14:19 -08001899 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001900 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001901 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001902 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001903 * @return Returns the maximum length that the user can enter.
1904 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001905 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001906 // Kind-of arbitrary.
1907 return 16;
1908 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001909
Dianne Hackborn254cb442010-01-27 19:23:59 -08001910 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001911 * Determine whether the current password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001912 * to meet the policy requirements (e.g. quality, minimum length) that have been
1913 * requested by the admins of this user and its participating profiles.
1914 * Restrictions on profiles that have a separate challenge are not taken into account.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001915 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001916 * <p>The calling device admin must have requested
1917 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
1918 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001919 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001920 * <p>This method can be called on the {@link DevicePolicyManager} instance
1921 * returned by {@link #getParentProfileInstance(ComponentName)} in order to determine
1922 * if the password set on the parent profile is sufficient.
1923 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001924 * @return Returns true if the password meets the current requirements, else false.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001925 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001926 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001927 if (mService != null) {
1928 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001929 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001931 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001932 }
1933 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001934 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001935 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001936
Dianne Hackbornd6847842010-01-12 18:14:19 -08001937 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00001938 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00001939 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00001940 * requested by the admins of the parent user and its profiles.
1941 *
1942 * @param userHandle the userId of the profile to check the password for.
1943 * @return Returns true if the password would meet the current requirements, else false.
1944 * @hide
1945 */
1946 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
1947 if (mService != null) {
1948 try {
1949 return mService.isProfileActivePasswordSufficientForParent(userHandle);
1950 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001951 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00001952 }
1953 }
1954 return false;
1955 }
1956
1957 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001958 * Retrieve the number of times the user has failed at entering a
1959 * password since that last successful password entry.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001960 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001961 * <p>This method can be called on the {@link DevicePolicyManager} instance
1962 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1963 * the number of failed password attemts for the parent user.
1964 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08001965 * <p>The calling device admin must have requested
1966 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call
1967 * this method; if it has not, a security exception will be thrown.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001968 */
1969 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001970 return getCurrentFailedPasswordAttempts(myUserId());
1971 }
1972
1973 /**
1974 * Retrieve the number of times the given user has failed at entering a
1975 * password since that last successful password entry.
1976 *
1977 * <p>The calling device admin must have requested
1978 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
1979 * not and it is not the system uid, a security exception will be thrown.
1980 *
1981 * @hide
1982 */
1983 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001984 if (mService != null) {
1985 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00001986 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001987 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001988 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001989 }
1990 }
1991 return -1;
1992 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001993
1994 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001995 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001996 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04001997 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04001998 * @hide
1999 */
2000 public boolean getDoNotAskCredentialsOnBoot() {
2001 if (mService != null) {
2002 try {
2003 return mService.getDoNotAskCredentialsOnBoot();
2004 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002005 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002006 }
2007 }
2008 return false;
2009 }
2010
2011 /**
Andrew Stadler88209d12010-02-08 22:59:36 -08002012 * Setting this to a value greater than zero enables a built-in policy
Esteban Talaverac1c83592016-02-17 17:56:15 +00002013 * that will perform a device or profile wipe after too many incorrect
Andrew Stadler88209d12010-02-08 22:59:36 -08002014 * device-unlock passwords have been entered. This built-in policy combines
2015 * watching for failed passwords and wiping the device, and requires
2016 * that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002017 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002018 *
Andrew Stadler88209d12010-02-08 22:59:36 -08002019 * <p>To implement any other policy (e.g. wiping data for a particular
2020 * application only, erasing or revoking credentials, or reporting the
2021 * failure to a server), you should implement
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002022 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)}
Andrew Stadler88209d12010-02-08 22:59:36 -08002023 * instead. Do not use this API, because if the maximum count is reached,
Esteban Talaverac1c83592016-02-17 17:56:15 +00002024 * the device or profile will be wiped immediately, and your callback will not be invoked.
2025 *
2026 * <p>This method can be called on the {@link DevicePolicyManager} instance
2027 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2028 * a value on the parent profile.
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 Hackborn8ea138c2010-01-26 18:01:04 -08002031 * @param num The number of failed password attempts at which point the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002032 * device or profile will be wiped.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002033 */
Robin Lee25e26452015-06-02 09:56:29 -07002034 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002035 if (mService != null) {
2036 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002037 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002039 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002040 }
2041 }
2042 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002043
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002044 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002045 * Retrieve the current maximum number of login attempts that are allowed before the device
2046 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2047 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2048 * not taken into account.
2049 *
2050 * <p>This method can be called on the {@link DevicePolicyManager} instance
2051 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2052 * the value for the parent profile.
2053 *
Robin Lee25e26452015-06-02 09:56:29 -07002054 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002055 * all admins.
2056 */
Robin Lee25e26452015-06-02 09:56:29 -07002057 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002058 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002059 }
2060
2061 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002062 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002063 if (mService != null) {
2064 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002065 return mService.getMaximumFailedPasswordsForWipe(
2066 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002067 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002068 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002069 }
2070 }
2071 return 0;
2072 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002073
Dianne Hackborn254cb442010-01-27 19:23:59 -08002074 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002075 * Returns the profile with the smallest maximum failed passwords for wipe,
2076 * for the given user. So for primary user, it might return the primary or
2077 * a managed profile. For a secondary user, it would be the same as the
2078 * user passed in.
2079 * @hide Used only by Keyguard
2080 */
2081 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2082 if (mService != null) {
2083 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002084 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2085 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002086 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002087 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002088 }
2089 }
2090 return UserHandle.USER_NULL;
2091 }
2092
2093 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002094 * Flag for {@link #resetPassword}: don't allow other admins to change
2095 * the password again until the user has entered it.
2096 */
2097 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002098
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002099 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002100 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2101 * If the flag is set, the device can be booted without asking for user password.
2102 * The absence of this flag does not change the current boot requirements. This flag
2103 * can be set by the device owner only. If the app is not the device owner, the flag
2104 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2105 * device to factory defaults.
2106 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002107 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002108
2109 /**
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002110 * Force a new device unlock password (the password needed to access the
2111 * entire device, not for individual accounts) on the user. This takes
2112 * effect immediately.
Makoto Onuki70f929e2015-11-11 12:40:15 -08002113 *
2114 * <p>Calling this from a managed profile that shares the password with the owner profile
2115 * will throw a security exception.
2116 *
2117 * <p><em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
2118 * device admins that are not device owner and not profile owner.
2119 * The password can now only be changed if there is currently no password set. Device owner
2120 * and profile owner can still do this.</em>
2121 *
2122 * <p>The given password must be sufficient for the
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002123 * current password quality and length constraints as returned by
2124 * {@link #getPasswordQuality(ComponentName)} and
2125 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet
2126 * these constraints, then it will be rejected and false returned. Note
2127 * that the password may be a stronger quality (containing alphanumeric
2128 * characters when the requested quality is only numeric), in which case
2129 * the currently active quality will be increased to match.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002130 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002131 * <p>Calling with a null or empty password will clear any existing PIN,
Makoto Onuki70f929e2015-11-11 12:40:15 -08002132 * pattern or password if the current password constraints allow it. <em>Note: This will not
2133 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2134 * device owner and not profile owner. Once set, the password cannot be changed to null or
2135 * empty, except by device owner or profile owner.</em>
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002136 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002137 * <p>The calling device admin must have requested
2138 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
2139 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002140 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002141 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002142 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002143 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002144 * @return Returns true if the password was applied, or false if it is
Makoto Onuki70f929e2015-11-11 12:40:15 -08002145 * not acceptable for the current constraints or if the user has not been decrypted yet.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002146 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002147 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002148 if (mParentInstance) {
2149 throw new SecurityException("Reset password does not work across profiles.");
2150 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002151 if (mService != null) {
2152 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002153 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002155 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002156 }
2157 }
2158 return false;
2159 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002160
Dianne Hackbornd6847842010-01-12 18:14:19 -08002161 /**
2162 * Called by an application that is administering the device to set the
2163 * maximum time for user activity until the device will lock. This limits
2164 * the length that the user can set. It takes effect immediately.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002165 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002166 * <p>The calling device admin must have requested
Dianne Hackborn315ada72010-02-11 12:14:08 -08002167 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002168 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002169 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002170 * <p>This method can be called on the {@link DevicePolicyManager} instance
2171 * returned by {@link #getParentProfileInstance(ComponentName)} in order to set
2172 * restrictions on the parent profile.
2173 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002174 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002175 * @param timeMs The new desired maximum time to lock in milliseconds.
2176 * A value of 0 means there is no restriction.
2177 */
Robin Lee25e26452015-06-02 09:56:29 -07002178 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002179 if (mService != null) {
2180 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002181 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002182 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002183 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002184 }
2185 }
2186 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002187
Dianne Hackbornd6847842010-01-12 18:14:19 -08002188 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002189 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2190 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2191 * a separate challenge are not taken into account.
2192 *
2193 * <p>This method can be called on the {@link DevicePolicyManager} instance
2194 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2195 * restrictions on the parent profile.
2196 *
Robin Lee25e26452015-06-02 09:56:29 -07002197 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002198 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002199 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002200 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002201 */
Robin Lee25e26452015-06-02 09:56:29 -07002202 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002203 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002204 }
2205
2206 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002207 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002208 if (mService != null) {
2209 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002210 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002211 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002212 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002213 }
2214 }
2215 return 0;
2216 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002217
Dianne Hackbornd6847842010-01-12 18:14:19 -08002218 /**
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002219 * Make the device lock immediately, as if the lock screen timeout has
2220 * expired at the point of this call.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002221 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002222 * <p>The calling device admin must have requested
2223 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} to be able to call
2224 * this method; if it has not, a security exception will be thrown.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002225 *
2226 * <p>This method can be called on the {@link DevicePolicyManager} instance
2227 * returned by {@link #getParentProfileInstance(ComponentName)} in order to lock
2228 * the parent profile.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002229 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002230 public void lockNow() {
2231 if (mService != null) {
2232 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002233 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002235 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002236 }
2237 }
2238 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002239
Dianne Hackbornd6847842010-01-12 18:14:19 -08002240 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002241 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002242 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002243 */
2244 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2245
2246 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002247 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2248 * data.
2249 *
Paul Crowley2934b262014-12-02 11:21:13 +00002250 * <p>This flag may only be set by device owner admins; if it is set by
2251 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002252 */
2253 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2254
2255 /**
Robin Lee85bd63f2015-02-10 11:51:00 +00002256 * Ask the user data be wiped. Wiping the primary user will cause the
2257 * device to reboot, erasing all user data while next booting up.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002258 *
Dianne Hackborn8aa2e892010-01-22 11:31:30 -08002259 * <p>The calling device admin must have requested
2260 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to be able to call
2261 * this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002262 *
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002263 * @param flags Bit mask of additional options: currently supported flags
2264 * are {@link #WIPE_EXTERNAL_STORAGE} and
2265 * {@link #WIPE_RESET_PROTECTION_DATA}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002266 */
2267 public void wipeData(int flags) {
2268 if (mService != null) {
2269 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002270 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002271 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002272 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002273 }
2274 }
2275 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002276
Dianne Hackbornd6847842010-01-12 18:14:19 -08002277 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002278 * Called by an application that is administering the device to set the
2279 * global proxy and exclusion list.
2280 * <p>
2281 * The calling device admin must have requested
2282 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2283 * this method; if it has not, a security exception will be thrown.
2284 * Only the first device admin can set the proxy. If a second admin attempts
2285 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002286 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002287 * be returned.
2288 * The method can be called repeatedly by the device admin alrady setting the
2289 * proxy to update the proxy and exclusion list.
2290 *
Robin Lee25e26452015-06-02 09:56:29 -07002291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002292 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2293 * Pass Proxy.NO_PROXY to reset the proxy.
2294 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002295 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2296 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002297 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002298 */
Robin Lee25e26452015-06-02 09:56:29 -07002299 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002300 List<String> exclusionList ) {
2301 if (proxySpec == null) {
2302 throw new NullPointerException();
2303 }
2304 if (mService != null) {
2305 try {
2306 String hostSpec;
2307 String exclSpec;
2308 if (proxySpec.equals(Proxy.NO_PROXY)) {
2309 hostSpec = null;
2310 exclSpec = null;
2311 } else {
2312 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2313 throw new IllegalArgumentException();
2314 }
2315 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2316 String hostName = sa.getHostName();
2317 int port = sa.getPort();
2318 StringBuilder hostBuilder = new StringBuilder();
2319 hostSpec = hostBuilder.append(hostName)
2320 .append(":").append(Integer.toString(port)).toString();
2321 if (exclusionList == null) {
2322 exclSpec = "";
2323 } else {
2324 StringBuilder listBuilder = new StringBuilder();
2325 boolean firstDomain = true;
2326 for (String exclDomain : exclusionList) {
2327 if (!firstDomain) {
2328 listBuilder = listBuilder.append(",");
2329 } else {
2330 firstDomain = false;
2331 }
2332 listBuilder = listBuilder.append(exclDomain.trim());
2333 }
2334 exclSpec = listBuilder.toString();
2335 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002336 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2337 != android.net.Proxy.PROXY_VALID)
2338 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002339 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002340 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002342 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002343 }
2344 }
2345 return null;
2346 }
2347
2348 /**
Jason Monk03bc9912014-05-13 09:44:57 -04002349 * Set a network-independent global HTTP proxy. This is not normally what you want
2350 * for typical HTTP proxies - they are generally network dependent. However if you're
2351 * doing something unusual like general internal filtering this may be useful. On
2352 * a private network where the proxy is not accessible, you may break HTTP using this.
2353 *
2354 * <p>This method requires the caller to be the device owner.
2355 *
2356 * <p>This proxy is only a recommendation and it is possible that some apps will ignore it.
2357 * @see ProxyInfo
2358 *
2359 * @param admin Which {@link DeviceAdminReceiver} this request is associated
2360 * with.
2361 * @param proxyInfo The a {@link ProxyInfo} object defining the new global
2362 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
2363 */
Robin Lee25e26452015-06-02 09:56:29 -07002364 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2365 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002366 if (mService != null) {
2367 try {
2368 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2369 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002370 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002371 }
2372 }
2373 }
2374
2375 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002376 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002377 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2378 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002379 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002380 */
2381 public ComponentName getGlobalProxyAdmin() {
2382 if (mService != null) {
2383 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002384 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002385 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002386 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002387 }
2388 }
2389 return null;
2390 }
2391
2392 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002393 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002394 * indicating that encryption is not supported.
2395 */
2396 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2397
2398 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002399 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002400 * indicating that encryption is supported, but is not currently active.
2401 */
2402 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2403
2404 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002405 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002406 * indicating that encryption is not currently active, but is currently
2407 * being activated. This is only reported by devices that support
2408 * encryption of data and only when the storage is currently
2409 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2410 * to become encrypted will never return this value.
2411 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002412 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002413
2414 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002415 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002416 * indicating that encryption is active.
2417 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002418 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002419
2420 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002421 * Result code for {@link #getStorageEncryptionStatus}:
2422 * indicating that encryption is active, but an encryption key has not
2423 * been set by the user.
2424 */
2425 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2426
2427 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002428 * Activity action: begin the process of encrypting data on the device. This activity should
2429 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2430 * After resuming from this activity, use {@link #getStorageEncryption}
2431 * to check encryption status. However, on some devices this activity may never return, as
2432 * it may trigger a reboot and in some cases a complete data wipe of the device.
2433 */
2434 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2435 public static final String ACTION_START_ENCRYPTION
2436 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002437 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002438 * Widgets are enabled in keyguard
2439 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002440 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002441
2442 /**
Jim Miller50e62182014-04-23 17:25:00 -07002443 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002444 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002445 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2446
2447 /**
2448 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2449 */
2450 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2451
2452 /**
Jim Miller50e62182014-04-23 17:25:00 -07002453 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2454 */
2455 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2456
2457 /**
2458 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2459 */
2460 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2461
2462 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002463 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002464 * (e.g. PIN/Pattern/Password).
2465 */
2466 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2467
2468 /**
Jim Miller06e34502014-07-17 14:46:05 -07002469 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2470 */
2471 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2472
2473 /**
Jim Miller35207742012-11-02 15:33:20 -07002474 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002475 */
2476 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002477
2478 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002479 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002480 * request that the storage system be encrypted.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002481 *
2482 * <p>When multiple device administrators attempt to control device
2483 * encryption, the most secure, supported setting will always be
2484 * used. If any device administrator requests device encryption,
2485 * it will be enabled; Conversely, if a device administrator
2486 * attempts to disable device encryption while another
2487 * device administrator has enabled it, the call to disable will
2488 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
2489 *
2490 * <p>This policy controls encryption of the secure (application data) storage area. Data
Andy Stadler50c294f2011-03-07 19:13:42 -08002491 * written to other storage areas may or may not be encrypted, and this policy does not require
2492 * or control the encryption of any other storage areas.
2493 * There is one exception: If {@link android.os.Environment#isExternalStorageEmulated()} is
2494 * {@code true}, then the directory returned by
2495 * {@link android.os.Environment#getExternalStorageDirectory()} must be written to disk
2496 * within the encrypted storage area.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002497 *
2498 * <p>Important Note: On some devices, it is possible to encrypt storage without requiring
2499 * the user to create a device PIN or Password. In this case, the storage is encrypted, but
2500 * the encryption key may not be fully secured. For maximum security, the administrator should
2501 * also require (and check for) a pattern, PIN, or password.
2502 *
2503 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2504 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002505 * @return the new request status (for all active admins) - will be one of
2506 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2507 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2508 * {@link #getStorageEncryptionStatus()} to query the actual device state.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002509 */
Robin Lee25e26452015-06-02 09:56:29 -07002510 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002511 if (mService != null) {
2512 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002513 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002514 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002515 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002516 }
2517 }
2518 return ENCRYPTION_STATUS_UNSUPPORTED;
2519 }
2520
2521 /**
2522 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002523 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002524 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2526 * this will return the requested encryption setting as an aggregate of all active
2527 * administrators.
2528 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002529 */
Robin Lee25e26452015-06-02 09:56:29 -07002530 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002531 if (mService != null) {
2532 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002533 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002534 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002535 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002536 }
2537 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002538 return false;
2539 }
2540
2541 /**
2542 * Called by an application that is administering the device to
2543 * determine the current encryption status of the device.
2544 *
2545 * Depending on the returned status code, the caller may proceed in different
2546 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2547 * storage system does not support encryption. If the
2548 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2549 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002550 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2551 * storage system has enabled encryption but no password is set so further action
2552 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002553 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2554 *
Robin Lee7e678712014-07-24 16:41:31 +01002555 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002556 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002557 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2558 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002559 */
2560 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002561 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002562 }
2563
2564 /** @hide per-user version */
2565 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002566 if (mService != null) {
2567 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002568 return mService.getStorageEncryptionStatus(userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002569 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002570 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002571 }
2572 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002573 return ENCRYPTION_STATUS_UNSUPPORTED;
2574 }
2575
2576 /**
Robin Lee7e678712014-07-24 16:41:31 +01002577 * Installs the given certificate as a user CA.
2578 *
Robin Lee25e26452015-06-02 09:56:29 -07002579 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2580 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002581 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002582 *
2583 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002584 * interrupted, true otherwise.
Maggie Benthallda51e682013-08-08 22:35:44 -04002585 */
Robin Lee25e26452015-06-02 09:56:29 -07002586 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002587 if (mService != null) {
2588 try {
Robin Lee7e678712014-07-24 16:41:31 +01002589 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002591 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002592 }
2593 }
2594 return false;
2595 }
2596
2597 /**
Robin Lee7e678712014-07-24 16:41:31 +01002598 * Uninstalls the given certificate from trusted user CAs, if present.
2599 *
Robin Lee25e26452015-06-02 09:56:29 -07002600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2601 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002602 * @param certBuffer encoded form of the certificate to remove.
Maggie Benthallda51e682013-08-08 22:35:44 -04002603 */
Robin Lee25e26452015-06-02 09:56:29 -07002604 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002605 if (mService != null) {
2606 try {
Robin Lee306fe082014-06-19 14:04:24 +00002607 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002608 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002609 } catch (CertificateException e) {
2610 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002611 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002612 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002613 }
2614 }
2615 }
2616
2617 /**
Robin Lee7e678712014-07-24 16:41:31 +01002618 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2619 * If a user has installed any certificates by other means than device policy these will be
2620 * included too.
2621 *
Robin Lee25e26452015-06-02 09:56:29 -07002622 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2623 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002624 * @return a List of byte[] arrays, each encoding one user CA certificate.
Maggie Benthallda51e682013-08-08 22:35:44 -04002625 */
Robin Lee25e26452015-06-02 09:56:29 -07002626 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002627 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002628 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002629 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002630 mService.enforceCanManageCaCerts(admin);
2631 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2632 for (String alias : certStore.userAliases()) {
2633 try {
2634 certs.add(certStore.getCertificate(alias).getEncoded());
2635 } catch (CertificateException ce) {
2636 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2637 }
2638 }
2639 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002640 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002641 }
2642 }
2643 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002644 }
2645
2646 /**
Robin Lee7e678712014-07-24 16:41:31 +01002647 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2648 * means other than device policy will also be removed, except for system CA certificates.
2649 *
Robin Lee25e26452015-06-02 09:56:29 -07002650 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2651 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002652 */
Robin Lee25e26452015-06-02 09:56:29 -07002653 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002654 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002655 try {
2656 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2657 .toArray(new String[0]));
2658 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002659 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002660 }
2661 }
2662 }
2663
2664 /**
2665 * Returns whether this certificate is installed as a trusted CA.
2666 *
Robin Lee25e26452015-06-02 09:56:29 -07002667 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2668 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002669 * @param certBuffer encoded form of the certificate to look up.
Maggie Benthallda51e682013-08-08 22:35:44 -04002670 */
Robin Lee25e26452015-06-02 09:56:29 -07002671 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002672 if (mService != null) {
2673 try {
2674 mService.enforceCanManageCaCerts(admin);
2675 return getCaCertAlias(certBuffer) != null;
2676 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002677 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002678 } catch (CertificateException ce) {
2679 Log.w(TAG, "Could not parse certificate", ce);
2680 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002681 }
2682 return false;
2683 }
2684
2685 /**
Robin Leece3399f2016-02-24 12:08:32 +00002686 * Called by a device or profile owner, or delegated certificate installer, to install a
2687 * certificate and corresponding private key. All apps within the profile will be able to access
2688 * the certificate and use the private key, given direct user approval.
2689 *
2690 * <p>Access to the installed credentials will not be granted to the caller of this API without
2691 * direct user approval. This is for security - should a certificate installer become
2692 * compromised, certificates it had already installed will be protected.
2693 *
2694 * <p>If the installer must have access to the credentials, call
2695 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002696 *
Robin Lee25e26452015-06-02 09:56:29 -07002697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2698 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002699 * @param privKey The private key to install.
2700 * @param cert The certificate to install.
2701 * @param alias The private key alias under which to install the certificate. If a certificate
2702 * with that alias already exists, it will be overwritten.
2703 * @return {@code true} if the keys were installed, {@code false} otherwise.
2704 */
Robin Leefbc65642015-08-03 16:21:22 +01002705 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2706 @NonNull Certificate cert, @NonNull String alias) {
Robin Leece3399f2016-02-24 12:08:32 +00002707 return installKeyPair(admin, privKey, cert, alias, false);
2708 }
2709
2710 /**
2711 * Called by a device or profile owner, or delegated certificate installer, to install a
2712 * certificate and corresponding private key. All apps within the profile will be able to access
2713 * the certificate and use the private key, given direct user approval.
2714 *
2715 * <p>The caller of this API may grant itself access to the credential immediately, without user
2716 * approval. It is a best practice not to request this unless strictly necessary since it opens
2717 * up additional security vulnerabilities.
2718 *
2719 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2720 * {@code null} if calling from a delegated certificate installer.
2721 * @param privKey The private key to install.
2722 * @param cert The certificate to install.
2723 * @param alias The private key alias under which to install the certificate. If a certificate
2724 * with that alias already exists, it will be overwritten.
2725 * @param requestAccess {@code true} to request that the calling app be granted access to the
2726 * credentials immediately. Otherwise, access to the credentials will be gated by user approval.
2727 * @return {@code true} if the keys were installed, {@code false} otherwise.
2728 */
2729 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2730 @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002731 try {
2732 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002733 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2734 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Leece3399f2016-02-24 12:08:32 +00002735 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002736 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002737 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01002738 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2739 Log.w(TAG, "Failed to obtain private key material", e);
2740 } catch (CertificateException | IOException e) {
2741 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002742 }
2743 return false;
2744 }
2745
2746 /**
Robin Leece3399f2016-02-24 12:08:32 +00002747 * Called by a device or profile owner, or delegated certificate installer, to remove all user
2748 * credentials installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002749 *
2750 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2751 * {@code null} if calling from a delegated certificate installer.
2752 * @param alias The private key alias under which the certificate is installed.
2753 * @return {@code true} if the keys were both removed, {@code false} otherwise.
2754 */
2755 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2756 try {
2757 return mService.removeKeyPair(admin, alias);
2758 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002759 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01002760 }
Robin Leefbc65642015-08-03 16:21:22 +01002761 }
2762
2763 /**
Robin Lee25e26452015-06-02 09:56:29 -07002764 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002765 * doesn't exist.
2766 */
2767 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2768 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2769 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2770 new ByteArrayInputStream(certBuffer));
2771 return new TrustedCertificateStore().getCertificateAlias(cert);
2772 }
2773
2774 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002775 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002776 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002777 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002778 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002779 * <p>
2780 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2781 * it is later cleared by calling this method with a null value or uninstallling the certificate
2782 * installer.
Rubin Xuf03d0a62016-02-10 14:54:15 +00002783 *<p>
2784 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2785 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
2786 * supplied certificate installer package must be installed when calling this API,
2787 * otherwise an {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002788 *
Robin Lee25e26452015-06-02 09:56:29 -07002789 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002790 * @param installerPackage The package name of the certificate installer which will be given
Robin Lee25e26452015-06-02 09:56:29 -07002791 * access. If {@code null} is given the current package will be cleared.
Rubin Xuec32b562015-03-03 17:34:05 +00002792 */
Robin Lee25e26452015-06-02 09:56:29 -07002793 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2794 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002795 if (mService != null) {
2796 try {
Robin Lee25e26452015-06-02 09:56:29 -07002797 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002798 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002799 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002800 }
2801 }
2802 }
2803
2804 /**
2805 * Called by a profile owner or device owner to retrieve the certificate installer for the
Makoto Onuki32b30572015-12-11 14:29:51 -08002806 * user. null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002807 *
Robin Lee25e26452015-06-02 09:56:29 -07002808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2809 * @return The package name of the current delegated certificate installer, or {@code null}
Rubin Xuec32b562015-03-03 17:34:05 +00002810 * if none is set.
2811 */
Robin Lee25e26452015-06-02 09:56:29 -07002812 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002813 if (mService != null) {
2814 try {
Robin Lee25e26452015-06-02 09:56:29 -07002815 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002816 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002817 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002818 }
2819 }
2820 return null;
2821 }
2822
2823 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002824 * Called by a device or profile owner to configure an always-on VPN connection through a
2825 * specific application for the current user.
2826 * This connection is automatically granted and persisted after a reboot.
2827 *
2828 * <p>The designated package should declare a {@link android.net.VpnService} in its
2829 * manifest guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE},
2830 * otherwise the call will fail.
2831 *
2832 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null}
2833 * to remove an existing always-on VPN configuration.
2834 *
2835 * @return {@code true} if the package is set as always-on VPN controller;
2836 * {@code false} otherwise.
2837 */
2838 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2839 @Nullable String vpnPackage) {
2840 if (mService != null) {
2841 try {
2842 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2843 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002844 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002845 }
2846 }
2847 return false;
2848 }
2849
2850 /**
2851 * Called by a device or profile owner to read the name of the package administering an
2852 * always-on VPN connection for the current user.
2853 * If there is no such package, or the always-on VPN is provided by the system instead
2854 * of by an application, {@code null} will be returned.
2855 *
2856 * @return Package name of VPN controller responsible for always-on VPN,
2857 * or {@code null} if none is set.
2858 */
2859 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2860 if (mService != null) {
2861 try {
2862 return mService.getAlwaysOnVpnPackage(admin);
2863 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002864 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002865 }
2866 }
2867 return null;
2868 }
2869
2870 /**
Ben Komalo2447edd2011-05-09 16:05:33 -07002871 * Called by an application that is administering the device to disable all cameras
Amith Yamasani242f4b12014-10-14 16:06:13 -07002872 * on the device, for this user. After setting this, no applications running as this user
2873 * will be able to access any cameras on the device.
Ben Komalo2447edd2011-05-09 16:05:33 -07002874 *
Makoto Onuki759a7632015-10-28 16:43:10 -07002875 * <p>If the caller is device owner, then the restriction will be applied to all users.
2876 *
Ben Komalo2447edd2011-05-09 16:05:33 -07002877 * <p>The calling device admin must have requested
2878 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call
2879 * this method; if it has not, a security exception will be thrown.
2880 *
2881 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2882 * @param disabled Whether or not the camera should be disabled.
2883 */
Robin Lee25e26452015-06-02 09:56:29 -07002884 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002885 if (mService != null) {
2886 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002887 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002888 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002889 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07002890 }
2891 }
2892 }
2893
2894 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002895 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002896 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002897 * @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 -07002898 * have disabled the camera
2899 */
Robin Lee25e26452015-06-02 09:56:29 -07002900 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002901 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002902 }
2903
2904 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002905 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002906 if (mService != null) {
2907 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002908 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07002909 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002910 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07002911 }
2912 }
2913 return false;
2914 }
2915
2916 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002917 * Called by a device owner to request a bugreport.
2918 *
2919 * <p>There must be only one user on the device, managed by the device owner.
Michal Karpinskib58e4962016-03-01 14:55:10 +00002920 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002921 *
2922 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2923 * @return {@code true} if the bugreport collection started successfully, or {@code false}
2924 * if it wasn't triggered because a previous bugreport operation is still active
2925 * (either the bugreport is still running or waiting for the user to share or decline)
2926 */
2927 public boolean requestBugreport(@NonNull ComponentName admin) {
2928 if (mService != null) {
2929 try {
2930 return mService.requestBugreport(admin);
2931 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002932 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00002933 }
2934 }
2935 return false;
2936 }
2937
2938 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07002939 * Determine whether or not creating a guest user has been disabled for the device
2940 *
2941 * @hide
2942 */
2943 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
2944 // Currently guest users can always be created if multi-user is enabled
2945 // TODO introduce a policy for guest user creation
2946 return false;
2947 }
2948
2949 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01002950 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
2951 * screen capture also prevents the content from being shown on display devices that do not have
2952 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
2953 * secure surfaces and secure displays.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002954 *
2955 * <p>The calling device admin must be a device or profile owner. If it is not, a
2956 * security exception will be thrown.
2957 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07002958 * <p>From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also
Benjamin Franzc200f442015-06-25 18:20:04 +01002959 * blocks assist requests for all activities of the relevant user.
2960 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002962 * @param disabled Whether screen capture is disabled or not.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002963 */
Robin Lee25e26452015-06-02 09:56:29 -07002964 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002965 if (mService != null) {
2966 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002967 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002968 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002969 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002970 }
2971 }
2972 }
2973
2974 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08002975 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002976 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002977 * @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 +01002978 * have disabled screen capture.
2979 */
Robin Lee25e26452015-06-02 09:56:29 -07002980 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002981 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002982 }
2983
2984 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002985 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002986 if (mService != null) {
2987 try {
2988 return mService.getScreenCaptureDisabled(admin, userHandle);
2989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002990 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01002991 }
2992 }
2993 return false;
2994 }
2995
2996 /**
Sander Alewijnse0ced6272014-08-26 11:18:26 +01002997 * Called by a device owner to set whether auto time is required. If auto time is
2998 * required the user cannot set the date and time, but has to use network date and time.
2999 *
3000 * <p>Note: if auto time is required the user can still manually set the time zone.
3001 *
3002 * <p>The calling device admin must be a device owner. If it is not, a security exception will
3003 * be thrown.
3004 *
3005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3006 * @param required Whether auto time is set required or not.
3007 */
Robin Lee25e26452015-06-02 09:56:29 -07003008 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003009 if (mService != null) {
3010 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003011 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003012 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003013 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003014 }
3015 }
3016 }
3017
3018 /**
3019 * @return true if auto time is required.
3020 */
3021 public boolean getAutoTimeRequired() {
3022 if (mService != null) {
3023 try {
3024 return mService.getAutoTimeRequired();
3025 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003026 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003027 }
3028 }
3029 return false;
3030 }
3031
3032 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003033 * Called by a device owner to set whether all users created on the device should be ephemeral.
3034 *
3035 * <p>The system user is exempt from this policy - it is never ephemeral.
3036 *
3037 * <p>The calling device admin must be the device owner. If it is not, a security exception will
3038 * be thrown.
3039 *
3040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3041 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
3042 * subsequently created users will be ephemeral.
3043 * @hide
3044 */
3045 public void setForceEphemeralUsers(
3046 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3047 if (mService != null) {
3048 try {
3049 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3050 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003051 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003052 }
3053 }
3054 }
3055
3056 /**
3057 * @return true if all users are created ephemeral.
3058 * @hide
3059 */
3060 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3061 if (mService != null) {
3062 try {
3063 return mService.getForceEphemeralUsers(admin);
3064 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003065 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003066 }
3067 }
3068 return false;
3069 }
3070
3071 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003072 * Called by an application that is administering the device to disable keyguard customizations,
3073 * such as widgets. After setting this, keyguard features will be disabled according to the
3074 * provided feature list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003075 *
3076 * <p>The calling device admin must have requested
Jim Miller48b9b0d2012-09-19 23:16:50 -07003077 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millerb8ec4702012-08-31 17:19:10 -07003078 * this method; if it has not, a security exception will be thrown.
3079 *
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003080 * <p>Calling this from a managed profile before version
Esteban Talaverac1c83592016-02-17 17:56:15 +00003081 * {@link android.os.Build.VERSION_CODES#M} will throw a security exception. From version
3082 * {@link android.os.Build.VERSION_CODES#M} the profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003083 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003084 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
3085 * is no separate challenge set on the managed profile.
3086 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
3087 * there is one, or the parent user otherwise.
3088 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications
3089 * generated by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003090 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003091 *
3092 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3093 * set on the {@link DevicePolicyManager} instance returned by
3094 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the
3095 * parent profile.
3096 *
3097 * <p>Requests to disable other features on a managed profile will be ignored.
3098 *
3099 * <p>The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003100 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003101 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003102 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003103 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
3104 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
Jim Miller50e62182014-04-23 17:25:00 -07003105 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003106 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, {@link #KEYGUARD_DISABLE_FINGERPRINT},
3107 * {@link #KEYGUARD_DISABLE_FEATURES_ALL}
Jim Millerb8ec4702012-08-31 17:19:10 -07003108 */
Robin Lee25e26452015-06-02 09:56:29 -07003109 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003110 if (mService != null) {
3111 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003112 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003114 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003115 }
3116 }
3117 }
3118
3119 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003120 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003121 * admin, if specified, or all admins that set retrictions on this user and its participating
3122 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3123 *
3124 * <p>This method can be called on the {@link DevicePolicyManager} instance
3125 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3126 * restrictions on the parent profile.
3127 *
Esteban Talavera62399912016-01-11 15:37:55 +00003128 * @param admin The name of the admin component to check, or {@code null} to check whether any
3129 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003130 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3131 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003132 */
Robin Lee25e26452015-06-02 09:56:29 -07003133 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003134 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003135 }
3136
3137 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003138 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003139 if (mService != null) {
3140 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003141 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003142 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003143 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003144 }
3145 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003146 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003147 }
3148
3149 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003150 * @hide
3151 */
Robin Lee25e26452015-06-02 09:56:29 -07003152 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3153 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003154 if (mService != null) {
3155 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003156 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003157 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003158 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003159 }
3160 }
3161 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003162
Dianne Hackbornd6847842010-01-12 18:14:19 -08003163 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003164 * @hide
3165 */
Robin Lee25e26452015-06-02 09:56:29 -07003166 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003167 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003168 }
3169
3170 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003171 * @hide
3172 */
Robin Lee25e26452015-06-02 09:56:29 -07003173 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003174 if (mService != null) {
3175 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003176 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003177 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003178 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003179 }
3180 }
3181 }
3182
3183 /**
3184 * @hide
3185 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003186 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003187 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003188 if (mService != null) {
3189 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003190 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003191 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003192 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003193 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003194 }
3195 }
3196 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003197
Dianne Hackbornd6847842010-01-12 18:14:19 -08003198 /**
3199 * @hide
3200 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003201 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003202 if (mService != null) {
3203 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003204 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003205 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003206 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003207 }
3208 }
3209 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003210
Dianne Hackbornd6847842010-01-12 18:14:19 -08003211 /**
3212 * @hide
3213 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003214 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003215 if (mService != null) {
3216 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003217 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003218 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003219 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003220 }
3221 }
3222 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003223
3224 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003225 * @hide
3226 */
3227 public void reportFailedFingerprintAttempt(int userHandle) {
3228 if (mService != null) {
3229 try {
3230 mService.reportFailedFingerprintAttempt(userHandle);
3231 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003232 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003233 }
3234 }
3235 }
3236
3237 /**
3238 * @hide
3239 */
3240 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3241 if (mService != null) {
3242 try {
3243 mService.reportSuccessfulFingerprintAttempt(userHandle);
3244 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003245 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003246 }
3247 }
3248 }
3249
3250 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003251 * Should be called when keyguard has been dismissed.
3252 * @hide
3253 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003254 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003255 if (mService != null) {
3256 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003257 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003258 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003259 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003260 }
3261 }
3262 }
3263
3264 /**
3265 * Should be called when keyguard view has been shown to the user.
3266 * @hide
3267 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003268 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003269 if (mService != null) {
3270 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003271 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003272 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003273 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003274 }
3275 }
3276 }
3277
3278 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003279 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003280 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003281 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3282 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003283 * @return whether the package was successfully registered as the device owner.
3284 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003285 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003286 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003287 public boolean setDeviceOwner(ComponentName who) {
3288 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003289 }
3290
3291 /**
3292 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003293 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003294 public boolean setDeviceOwner(ComponentName who, int userId) {
3295 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003296 }
3297
3298 /**
3299 * @hide
3300 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003301 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3302 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003303 }
3304
3305 /**
3306 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003307 * Sets the given package as the device owner. The package must already be installed. There
3308 * must not already be a device owner.
3309 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3310 * this method.
3311 * Calling this after the setup phase of the primary user has completed is allowed only if
3312 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003313 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003314 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003315 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003316 * @return whether the package was successfully registered as the device owner.
3317 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003318 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003319 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003320 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003321 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003322 if (mService != null) {
3323 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003324 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003325 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003326 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003327 }
3328 }
3329 return false;
3330 }
3331
3332 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003333 * Used to determine if a particular package has been registered as a Device Owner app.
3334 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003335 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003336 * package is currently registered as the device owner app, pass in the package name from
3337 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003338 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003339 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3340 * the setup process.
3341 * @param packageName the package name of the app, to compare with the registered device owner
3342 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003343 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003344 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003345 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003346 return isDeviceOwnerAppOnCallingUser(packageName);
3347 }
3348
3349 /**
3350 * @return true if a package is registered as device owner, only when it's running on the
3351 * calling user.
3352 *
3353 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3354 * @hide
3355 */
3356 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3357 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3358 }
3359
3360 /**
3361 * @return true if a package is registered as device owner, even if it's running on a different
3362 * user.
3363 *
3364 * <p>Requires the MANAGE_USERS permission.
3365 *
3366 * @hide
3367 */
3368 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3369 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3370 }
3371
3372 /**
3373 * @return device owner component name, only when it's running on the calling user.
3374 *
3375 * @hide
3376 */
3377 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3378 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3379 }
3380
3381 /**
3382 * @return device owner component name, even if it's running on a different user.
3383 *
3384 * <p>Requires the MANAGE_USERS permission.
3385 *
3386 * @hide
3387 */
3388 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3389 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3390 }
3391
3392 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003393 if (packageName == null) {
3394 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003395 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003396 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003397 if (deviceOwner == null) {
3398 return false;
3399 }
3400 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003401 }
3402
Makoto Onukic8a5a552015-11-19 14:29:12 -08003403 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3404 if (mService != null) {
3405 try {
3406 return mService.getDeviceOwnerComponent(callingUserOnly);
3407 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003408 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003409 }
3410 }
3411 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003412 }
3413
Jason Monkb0dced82014-06-06 14:36:20 -04003414 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003415 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3416 * no device owner.
3417 *
3418 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003419 *
3420 * @hide
3421 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003422 public int getDeviceOwnerUserId() {
3423 if (mService != null) {
3424 try {
3425 return mService.getDeviceOwnerUserId();
3426 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003427 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003428 }
3429 }
3430 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003431 }
3432
3433 /**
Jason Monkb0dced82014-06-06 14:36:20 -04003434 * Clears the current device owner. The caller must be the device owner.
3435 *
3436 * This function should be used cautiously as once it is called it cannot
3437 * be undone. The device owner can only be set as a part of device setup
3438 * before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003439 *
3440 * @param packageName The package name of the device owner.
Jason Monkb0dced82014-06-06 14:36:20 -04003441 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003442 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003443 if (mService != null) {
3444 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003445 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003446 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003447 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003448 }
3449 }
3450 }
3451
Makoto Onukia52562c2015-10-01 16:12:31 -07003452 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003453 * Returns the device owner package name, only if it's running on the calling user.
3454 *
3455 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003456 *
3457 * @hide
3458 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003459 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003460 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003461 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3462 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003463 }
3464
3465 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003466 * @return true if the device is managed by any device owner.
3467 *
3468 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003469 *
3470 * @hide
3471 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003472 public boolean isDeviceManaged() {
3473 return getDeviceOwnerComponentOnAnyUser() != null;
3474 }
3475
3476 /**
3477 * Returns the device owner name. Note this method *will* return the device owner
3478 * name when it's running on a different user.
3479 *
3480 * <p>Requires the MANAGE_USERS permission.
3481 *
3482 * @hide
3483 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003484 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003485 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003486 if (mService != null) {
3487 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003488 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003489 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003490 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003491 }
3492 }
3493 return null;
3494 }
Adam Connors776c5552014-01-09 10:42:56 +00003495
3496 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003497 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003498 * @deprecated Do not use
3499 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003500 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003501 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003502 @SystemApi
3503 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003504 return null;
3505 }
3506
3507 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003508 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003509 * @deprecated Do not use
3510 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003511 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003512 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003513 @SystemApi
3514 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003515 return null;
3516 }
3517
Julia Reynolds20118f12015-02-11 12:34:08 -05003518 /**
Adam Connors776c5552014-01-09 10:42:56 +00003519 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003520 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303521 * Sets the given component as an active admin and registers the package as the profile
3522 * owner for this user. The package must already be installed and there shouldn't be
3523 * an existing profile owner registered for this user. Also, this method must be called
3524 * before the user setup has been completed.
3525 * <p>
3526 * This method can only be called by system apps that hold MANAGE_USERS permission and
3527 * MANAGE_DEVICE_ADMINS permission.
3528 * @param admin The component to register as an active admin and profile owner.
3529 * @param ownerName The user-visible name of the entity that is managing this user.
3530 * @return whether the admin was successfully registered as the profile owner.
3531 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3532 * the user has already been set up.
3533 */
Justin Morey80440cc2014-07-24 09:16:35 -05003534 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003535 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303536 throws IllegalArgumentException {
3537 if (mService != null) {
3538 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003539 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303540 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003541 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303542 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003543 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303544 }
3545 }
3546 return false;
3547 }
3548
3549 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003550 * Clears the active profile owner and removes all user restrictions. The caller must
3551 * be from the same package as the active profile owner for this user, otherwise a
3552 * SecurityException will be thrown.
3553 *
Makoto Onuki5bf68022016-01-27 13:49:19 -08003554 * <p>This doesn't work for managed profile owners.
3555 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003556 * @param admin The component to remove as the profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003557 */
Robin Lee25e26452015-06-02 09:56:29 -07003558 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003559 if (mService != null) {
3560 try {
3561 mService.clearProfileOwner(admin);
3562 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003563 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003564 }
3565 }
3566 }
3567
3568 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003569 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003570 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003571 */
3572 public boolean hasUserSetupCompleted() {
3573 if (mService != null) {
3574 try {
3575 return mService.hasUserSetupCompleted();
3576 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003577 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003578 }
3579 }
3580 return true;
3581 }
3582
3583 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003584 * @hide
3585 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003586 * already be installed. There must not already be a profile owner for this user.
3587 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3588 * this method.
3589 * Calling this after the setup phase of the specified user has completed is allowed only if:
3590 * - the caller is SYSTEM_UID.
3591 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003592 * @param admin the component name to be registered as profile owner.
3593 * @param ownerName the human readable name of the organisation associated with this DPM.
3594 * @param userHandle the userId to set the profile owner for.
3595 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003596 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3597 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003598 */
Robin Lee25e26452015-06-02 09:56:29 -07003599 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003600 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003601 if (mService != null) {
3602 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003603 if (ownerName == null) {
3604 ownerName = "";
3605 }
3606 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003607 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003608 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003609 }
3610 }
3611 return false;
3612 }
3613
3614 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003615 * Sets the device owner information to be shown on the lock screen.
3616 *
3617 * <p>If the device owner information is {@code null} or empty then the device owner info is
3618 * cleared and the user owner info is shown on the lock screen if it is set.
Andrei Stingaceanucc5061f2016-01-07 17:55:57 +00003619 * <p>If the device owner information contains only whitespaces then the message on the lock
3620 * screen will be blank and the user will not be allowed to change it.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003621 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003622 * <p>If the device owner information needs to be localized, it is the responsibility of the
3623 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3624 * and set a new version of this string accordingly.
3625 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003626 * @param admin The name of the admin component to check.
3627 * @param info Device owner information which will be displayed instead of the user
3628 * owner info.
3629 * @return Whether the device owner information has been set.
3630 */
3631 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3632 if (mService != null) {
3633 try {
3634 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3635 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003636 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003637 }
3638 }
3639 return false;
3640 }
3641
3642 /**
3643 * @return The device owner information. If it is not set returns {@code null}.
3644 */
3645 public String getDeviceOwnerLockScreenInfo() {
3646 if (mService != null) {
3647 try {
3648 return mService.getDeviceOwnerLockScreenInfo();
3649 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003650 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003651 }
3652 }
3653 return null;
3654 }
3655
3656 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003657 * Called by device or profile owners to suspend packages for this user.
3658 *
3659 * <p>A suspended package will not be able to start activities. Its notifications will
3660 * be hidden, it will not show up in recents, will not be able to show toasts or dialogs
3661 * or ring the device.
3662 *
3663 * <p>The package must already be installed.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003664 *
3665 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003666 * @param packageNames The package names to suspend or unsuspend.
3667 * @param suspended If set to {@code true} than the packages will be suspended, if set to
3668 * {@code false} the packages will be unsuspended.
3669 * @return an array of package names for which the suspended status is not set as requested in
3670 * this method.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003671 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003672 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003673 boolean suspended) {
3674 if (mService != null) {
3675 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003676 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003677 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003678 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003679 }
3680 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003681 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003682 }
3683
3684 /**
3685 * Called by device or profile owners to determine if a package is suspended.
3686 *
3687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3688 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003689 * @return {@code true} if the package is suspended or {@code false} if the package is not
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003690 * suspended, could not be found or an error occurred.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003691 */
3692 public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
3693 if (mService != null) {
3694 try {
3695 return mService.getPackageSuspended(admin, packageName);
3696 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003697 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003698 }
3699 }
3700 return false;
3701 }
3702
3703 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003704 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3705 * be used. Only the profile owner can call this.
3706 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003707 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003708 *
3709 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3710 */
Robin Lee25e26452015-06-02 09:56:29 -07003711 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003712 if (mService != null) {
3713 try {
3714 mService.setProfileEnabled(admin);
3715 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003716 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003717 }
3718 }
3719 }
3720
3721 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003722 * Sets the name of the profile. In the device owner case it sets the name of the user
3723 * 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 +01003724 * never called by the profile or device owner, the name will be set to default values.
3725 *
3726 * @see #isProfileOwnerApp
3727 * @see #isDeviceOwnerApp
3728 *
Robin Lee25e26452015-06-02 09:56:29 -07003729 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003730 * @param profileName The name of the profile.
3731 */
Robin Lee25e26452015-06-02 09:56:29 -07003732 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003733 if (mService != null) {
3734 try {
Robin Lee25e26452015-06-02 09:56:29 -07003735 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003736 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003737 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003738 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003739 }
3740 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003741
3742 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003743 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003744 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003745 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003746 *
3747 * @param packageName The package name of the app to compare with the registered profile owner.
3748 * @return Whether or not the package is registered as the profile owner.
3749 */
3750 public boolean isProfileOwnerApp(String packageName) {
3751 if (mService != null) {
3752 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003753 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003754 return profileOwner != null
3755 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003756 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003757 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003758 }
3759 }
3760 return false;
3761 }
3762
3763 /**
3764 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003765 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003766 * owner has been set for that user.
3767 * @throws IllegalArgumentException if the userId is invalid.
3768 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003769 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003770 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003771 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3772 }
3773
3774 /**
3775 * @see #getProfileOwner()
3776 * @hide
3777 */
3778 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003779 if (mService != null) {
3780 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003781 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003782 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003783 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003784 }
3785 }
3786 return null;
3787 }
3788
3789 /**
3790 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003791 * @return the human readable name of the organisation associated with this DPM or {@code null}
3792 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003793 * @throws IllegalArgumentException if the userId is invalid.
3794 */
3795 public String getProfileOwnerName() throws IllegalArgumentException {
3796 if (mService != null) {
3797 try {
3798 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3799 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003800 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003801 }
3802 }
3803 return null;
3804 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003805
3806 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003807 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003808 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003809 * @return the human readable name of the organisation associated with this profile owner or
3810 * null if one is not set.
3811 * @throws IllegalArgumentException if the userId is invalid.
3812 */
3813 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003814 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003815 if (mService != null) {
3816 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003817 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003818 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003819 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07003820 }
3821 }
3822 return null;
3823 }
3824
3825 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003826 * Called by a profile owner or device owner to add a default intent handler activity for
3827 * intents that match a certain intent filter. This activity will remain the default intent
3828 * handler even if the set of potential event handlers for the intent filter changes and if
3829 * the intent preferences are reset.
3830 *
3831 * <p>The default disambiguation mechanism takes over if the activity is not installed
3832 * (anymore). When the activity is (re)installed, it is automatically reset as default
3833 * intent handler for the filter.
3834 *
3835 * <p>The calling device admin must be a profile owner or device owner. If it is not, a
3836 * security exception will be thrown.
3837 *
3838 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3839 * @param filter The IntentFilter for which a default handler is added.
3840 * @param activity The Activity that is added as default intent handler.
3841 */
Robin Lee25e26452015-06-02 09:56:29 -07003842 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3843 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003844 if (mService != null) {
3845 try {
3846 mService.addPersistentPreferredActivity(admin, filter, activity);
3847 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003848 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003849 }
3850 }
3851 }
3852
3853 /**
3854 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003855 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003856 *
3857 * <p>The calling device admin must be a profile owner. If it is not, a security
3858 * exception will be thrown.
3859 *
3860 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3861 * @param packageName The name of the package for which preferences are removed.
3862 */
Robin Lee25e26452015-06-02 09:56:29 -07003863 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003864 String packageName) {
3865 if (mService != null) {
3866 try {
3867 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3868 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003869 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003870 }
3871 }
3872 }
Robin Lee66e5d962014-04-09 16:44:21 +01003873
3874 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003875 * Called by a profile owner or device owner to grant permission to a package to manage
3876 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3877 * {@link #getApplicationRestrictions}.
3878 * <p>
3879 * This permission is persistent until it is later cleared by calling this method with a
3880 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00003881 * <p>
3882 * The supplied application restriction managing package must be installed when calling this
3883 * API, otherwise an {@link IllegalArgumentException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00003884 *
3885 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3886 * @param packageName The package name which will be given access to application restrictions
3887 * APIs. If {@code null} is given the current package will be cleared.
3888 */
3889 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
3890 @Nullable String packageName) {
3891 if (mService != null) {
3892 try {
3893 mService.setApplicationRestrictionsManagingPackage(admin, packageName);
3894 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003895 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003896 }
3897 }
3898 }
3899
3900 /**
3901 * Called by a profile owner or device owner to retrieve the application restrictions managing
3902 * package for the current user, or {@code null} if none is set.
3903 *
3904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3905 * @return The package name allowed to manage application restrictions on the current user, or
3906 * {@code null} if none is set.
3907 */
3908 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
3909 if (mService != null) {
3910 try {
3911 return mService.getApplicationRestrictionsManagingPackage(admin);
3912 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003913 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003914 }
3915 }
3916 return null;
3917 }
3918
3919 /**
3920 * Returns {@code true} if the calling package has been granted permission via
3921 * {@link #setApplicationRestrictionsManagingPackage} to manage application
3922 * restrictions for the calling user.
3923 */
3924 public boolean isCallerApplicationRestrictionsManagingPackage() {
3925 if (mService != null) {
3926 try {
3927 return mService.isCallerApplicationRestrictionsManagingPackage();
3928 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003929 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00003930 }
3931 }
3932 return false;
3933 }
3934
3935 /**
3936 * Sets the application restrictions for a given target application running in the calling user.
3937 *
3938 * <p>The caller must be a profile or device owner on that user, or the package allowed to
3939 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
3940 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01003941 *
Esteban Talavera6b8e0642015-08-10 17:26:04 +01003942 * <p>The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
3943 * <ul>
3944 * <li>{@code boolean}
3945 * <li>{@code int}
3946 * <li>{@code String} or {@code String[]}
3947 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
3948 * </ul>
Robin Lee66e5d962014-04-09 16:44:21 +01003949 *
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003950 * <p>If the restrictions are not available yet, but may be applied in the near future,
Esteban Talaverabf60f722015-12-10 16:26:44 +00003951 * the caller can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003952 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
3953 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003954 * <p>The application restrictions are only made visible to the target application via
3955 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or
3956 * device owner, and the application restrictions managing package via
3957 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01003958 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3960 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01003961 * @param packageName The name of the package to update restricted settings for.
3962 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
3963 * set of active restrictions.
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003964 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00003965 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00003966 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01003967 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00003968 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01003969 Bundle settings) {
3970 if (mService != null) {
3971 try {
3972 mService.setApplicationRestrictions(admin, packageName, settings);
3973 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003974 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01003975 }
3976 }
3977 }
3978
3979 /**
Jim Millere303bf42014-08-26 17:12:29 -07003980 * Sets a list of configuration features to enable for a TrustAgent component. This is meant
3981 * to be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all
3982 * trust agents but those enabled by this function call. If flag
3983 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Jim Miller604e7552014-07-18 19:00:02 -07003984 *
3985 * <p>The calling device admin must have requested
3986 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
Jim Millere303bf42014-08-26 17:12:29 -07003987 * this method; if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07003988 *
3989 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07003990 * @param target Component name of the agent to be enabled.
Jim Millerb5db57a2015-01-14 18:17:19 -08003991 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent
Jim Millere303bf42014-08-26 17:12:29 -07003992 * will be strictly disabled according to the state of the
3993 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
3994 * <p>If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all admins,
3995 * then it's up to the TrustAgent itself to aggregate the values from all device admins.
3996 * <p>Consult documentation for the specific TrustAgent to determine legal options parameters.
Jim Miller604e7552014-07-18 19:00:02 -07003997 */
Robin Lee25e26452015-06-02 09:56:29 -07003998 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
3999 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004000 if (mService != null) {
4001 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004002 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004003 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004004 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004005 }
4006 }
4007 }
4008
4009 /**
Jim Millere303bf42014-08-26 17:12:29 -07004010 * Gets configuration for the given trust agent based on aggregating all calls to
4011 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4012 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004013 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004014 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4015 * this function returns a list of configurations for all admins that declare
4016 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4017 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4018 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4019 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004020 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004021 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004022 */
Robin Lee25e26452015-06-02 09:56:29 -07004023 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4024 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004025 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004026 }
4027
4028 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004029 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4030 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004031 if (mService != null) {
4032 try {
Jim Millere303bf42014-08-26 17:12:29 -07004033 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004035 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004036 }
4037 }
Jim Millere303bf42014-08-26 17:12:29 -07004038 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004039 }
4040
4041 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004042 * Called by a profile owner of a managed profile to set whether caller-Id information from
4043 * the managed profile will be shown in the parent profile, for incoming calls.
Adam Connors210fe212014-07-17 15:41:43 +01004044 *
4045 * <p>The calling device admin must be a profile owner. If it is not, a
4046 * security exception will be thrown.
4047 *
Robin Lee25e26452015-06-02 09:56:29 -07004048 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004049 * @param disabled If true caller-Id information in the managed profile is not displayed.
4050 */
Robin Lee25e26452015-06-02 09:56:29 -07004051 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004052 if (mService != null) {
4053 try {
Robin Lee25e26452015-06-02 09:56:29 -07004054 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004055 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004056 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004057 }
4058 }
4059 }
4060
4061 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004062 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4063 * information has been disabled.
Adam Connors210fe212014-07-17 15:41:43 +01004064 *
4065 * <p>The calling device admin must be a profile owner. If it is not, a
4066 * security exception will be thrown.
4067 *
Robin Lee25e26452015-06-02 09:56:29 -07004068 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004069 */
Robin Lee25e26452015-06-02 09:56:29 -07004070 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004071 if (mService != null) {
4072 try {
Robin Lee25e26452015-06-02 09:56:29 -07004073 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004075 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004076 }
4077 }
4078 return false;
4079 }
4080
4081 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004082 * Determine whether or not caller-Id information has been disabled.
4083 *
4084 * @param userHandle The user for whom to check the caller-id permission
4085 * @hide
4086 */
4087 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4088 if (mService != null) {
4089 try {
4090 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4091 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004092 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004093 }
4094 }
4095 return false;
4096 }
4097
4098 /**
Victor Chang1060c6182016-01-04 20:16:23 +00004099 * Called by a profile owner of a managed profile to set whether contacts search from
4100 * the managed profile will be shown in the parent profile, for incoming calls.
4101 *
4102 * <p>The calling device admin must be a profile owner. If it is not, a
4103 * security exception will be thrown.
4104 *
4105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4106 * @param disabled If true contacts search in the managed profile is not displayed.
4107 */
4108 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4109 boolean disabled) {
4110 if (mService != null) {
4111 try {
4112 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004114 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004115 }
4116 }
4117 }
4118
4119 /**
4120 * Called by a profile owner of a managed profile to determine whether or not contacts search
4121 * has been disabled.
4122 *
4123 * <p>The calling device admin must be a profile owner. If it is not, a
4124 * security exception will be thrown.
4125 *
4126 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4127 */
4128 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4129 if (mService != null) {
4130 try {
4131 return mService.getCrossProfileContactsSearchDisabled(admin);
4132 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004133 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004134 }
4135 }
4136 return false;
4137 }
4138
4139
4140 /**
4141 * Determine whether or not contacts search has been disabled.
4142 *
4143 * @param userHandle The user for whom to check the contacts search permission
4144 * @hide
4145 */
4146 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4147 if (mService != null) {
4148 try {
4149 return mService
4150 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4151 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004152 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004153 }
4154 }
4155 return false;
4156 }
4157
4158 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004159 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004160 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004161 * @hide
4162 */
4163 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004164 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004165 if (mService != null) {
4166 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004167 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4168 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004170 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004171 }
4172 }
4173 }
4174
4175 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004176 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004177 * @hide
4178 */
4179 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4180 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004181 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004182 originalIntent);
4183 }
4184
4185 /**
Ricky Wai778ba132015-03-31 14:21:22 +01004186 * Called by a profile owner of a managed profile to set whether bluetooth
4187 * devices can access enterprise contacts.
4188 * <p>
4189 * The calling device admin must be a profile owner. If it is not, a
4190 * security exception will be thrown.
4191 * <p>
4192 * This API works on managed profile only.
4193 *
Robin Lee25e26452015-06-02 09:56:29 -07004194 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004195 * with.
4196 * @param disabled If true, bluetooth devices cannot access enterprise
4197 * contacts.
4198 */
Robin Lee25e26452015-06-02 09:56:29 -07004199 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004200 if (mService != null) {
4201 try {
Robin Lee25e26452015-06-02 09:56:29 -07004202 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004203 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004204 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004205 }
4206 }
4207 }
4208
4209 /**
4210 * Called by a profile owner of a managed profile to determine whether or
4211 * not Bluetooth devices cannot access enterprise contacts.
4212 * <p>
4213 * The calling device admin must be a profile owner. If it is not, a
4214 * security exception will be thrown.
4215 * <p>
4216 * This API works on managed profile only.
4217 *
Robin Lee25e26452015-06-02 09:56:29 -07004218 * @param admin Which {@link DeviceAdminReceiver} this request is associated
Ricky Wai778ba132015-03-31 14:21:22 +01004219 * with.
4220 */
Robin Lee25e26452015-06-02 09:56:29 -07004221 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004222 if (mService != null) {
4223 try {
Robin Lee25e26452015-06-02 09:56:29 -07004224 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004225 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004226 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004227 }
4228 }
4229 return true;
4230 }
4231
4232 /**
4233 * Determine whether or not Bluetooth devices cannot access contacts.
4234 * <p>
4235 * This API works on managed profile UserHandle only.
4236 *
4237 * @param userHandle The user for whom to check the caller-id permission
4238 * @hide
4239 */
4240 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4241 if (mService != null) {
4242 try {
4243 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4244 .getIdentifier());
4245 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004246 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004247 }
4248 }
4249 return true;
4250 }
4251
4252 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004253 * Called by the profile owner of a managed profile so that some intents sent in the managed
4254 * profile can also be resolved in the parent, or vice versa.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004255 * Only activity intents are supported.
4256 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004257 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004258 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
4259 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004260 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
4261 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004262 */
Robin Lee25e26452015-06-02 09:56:29 -07004263 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004264 if (mService != null) {
4265 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004266 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004267 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004268 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004269 }
4270 }
4271 }
4272
4273 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004274 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4275 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004276 * Only removes those that have been set by the profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4278 */
Robin Lee25e26452015-06-02 09:56:29 -07004279 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004280 if (mService != null) {
4281 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004282 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004283 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004284 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004285 }
4286 }
4287 }
4288
4289 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004290 * Called by a profile or device owner to set the permitted accessibility services. When
4291 * set by a device owner or profile owner the restriction applies to all profiles of the
4292 * user the device owner or profile owner is an admin for.
Jim Millerb1474f42014-08-26 18:42:58 -07004293 *
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004294 * By default the user can use any accessiblity service. When zero or more packages have
4295 * been added, accessiblity services that are not in the list and not part of the system
Jim Millerb1474f42014-08-26 18:42:58 -07004296 * can not be enabled by the user.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004297 *
4298 * <p> Calling with a null value for the list disables the restriction so that all services
4299 * can be used, calling with an empty list only allows the builtin system's services.
4300 *
4301 * <p> System accesibility services are always available to the user the list can't modify
4302 * this.
4303 *
4304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4305 * @param packageNames List of accessibility service package names.
4306 *
4307 * @return true if setting the restriction succeeded. It fail if there is
4308 * one or more non-system accessibility services enabled, that are not in the list.
4309 */
Robin Lee25e26452015-06-02 09:56:29 -07004310 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004311 List<String> packageNames) {
4312 if (mService != null) {
4313 try {
4314 return mService.setPermittedAccessibilityServices(admin, packageNames);
4315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004316 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004317 }
4318 }
4319 return false;
4320 }
4321
4322 /**
4323 * Returns the list of permitted accessibility services set by this device or profile owner.
4324 *
4325 * <p>An empty list means no accessibility services except system services are allowed.
4326 * Null means all accessibility services are allowed.
4327 *
4328 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4329 * @return List of accessiblity service package names.
4330 */
Robin Lee25e26452015-06-02 09:56:29 -07004331 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004332 if (mService != null) {
4333 try {
4334 return mService.getPermittedAccessibilityServices(admin);
4335 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004336 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004337 }
4338 }
4339 return null;
4340 }
4341
4342 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004343 * Called by the system to check if a specific accessibility service is disabled by admin.
4344 *
4345 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4346 * @param packageName Accessibility service package name that needs to be checked.
4347 * @param userHandle user id the admin is running as.
4348 * @return true if the accessibility service is permitted, otherwise false.
4349 *
4350 * @hide
4351 */
4352 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4353 @NonNull String packageName, int userHandle) {
4354 if (mService != null) {
4355 try {
4356 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4357 userHandle);
4358 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004359 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004360 }
4361 }
4362 return false;
4363 }
4364
4365 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004366 * Returns the list of accessibility services permitted by the device or profiles
4367 * owners of this user.
4368 *
4369 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4370 * it will contain the intersection of the permitted lists for any device or profile
4371 * owners that apply to this user. It will also include any system accessibility services.
4372 *
4373 * @param userId which user to check for.
4374 * @return List of accessiblity service package names.
4375 * @hide
4376 */
4377 @SystemApi
4378 public List<String> getPermittedAccessibilityServices(int userId) {
4379 if (mService != null) {
4380 try {
4381 return mService.getPermittedAccessibilityServicesForUser(userId);
4382 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004383 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004384 }
4385 }
4386 return null;
4387 }
4388
4389 /**
4390 * Called by a profile or device owner to set the permitted input methods services. When
4391 * set by a device owner or profile owner the restriction applies to all profiles of the
4392 * user the device owner or profile owner is an admin for.
4393 *
4394 * By default the user can use any input method. When zero or more packages have
4395 * been added, input method that are not in the list and not part of the system
4396 * can not be enabled by the user.
4397 *
4398 * This method will fail if it is called for a admin that is not for the foreground user
4399 * or a profile of the foreground user.
4400 *
4401 * <p> Calling with a null value for the list disables the restriction so that all input methods
4402 * can be used, calling with an empty list disables all but the system's own input methods.
4403 *
4404 * <p> System input methods are always available to the user this method can't modify this.
4405 *
4406 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4407 * @param packageNames List of input method package names.
Kenny Guy74a70242015-02-05 19:48:38 +00004408 * @return true if setting the restriction succeeded. It will fail if there are
4409 * one or more non-system input methods currently enabled that are not in
4410 * the packageNames list.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004411 */
Robin Lee25e26452015-06-02 09:56:29 -07004412 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004413 if (mService != null) {
4414 try {
4415 return mService.setPermittedInputMethods(admin, packageNames);
4416 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004417 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004418 }
4419 }
4420 return false;
4421 }
4422
4423
4424 /**
4425 * Returns the list of permitted input methods set by this device or profile owner.
4426 *
4427 * <p>An empty list means no input methods except system input methods are allowed.
4428 * Null means all input methods are allowed.
4429 *
4430 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4431 * @return List of input method package names.
4432 */
Robin Lee25e26452015-06-02 09:56:29 -07004433 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004434 if (mService != null) {
4435 try {
4436 return mService.getPermittedInputMethods(admin);
4437 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004438 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004439 }
4440 }
4441 return null;
4442 }
4443
4444 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004445 * Called by the system to check if a specific input method is disabled by admin.
4446 *
4447 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4448 * @param packageName Input method package name that needs to be checked.
4449 * @param userHandle user id the admin is running as.
4450 * @return true if the input method is permitted, otherwise false.
4451 *
4452 * @hide
4453 */
4454 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4455 @NonNull String packageName, int userHandle) {
4456 if (mService != null) {
4457 try {
4458 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4459 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004460 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004461 }
4462 }
4463 return false;
4464 }
4465
4466 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004467 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004468 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004469 *
4470 * <p>Null means all input methods are allowed, if a non-null list is returned
4471 * it will contain the intersection of the permitted lists for any device or profile
4472 * owners that apply to this user. It will also include any system input methods.
4473 *
4474 * @return List of input method package names.
4475 * @hide
4476 */
4477 @SystemApi
4478 public List<String> getPermittedInputMethodsForCurrentUser() {
4479 if (mService != null) {
4480 try {
4481 return mService.getPermittedInputMethodsForCurrentUser();
4482 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004483 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004484 }
4485 }
4486 return null;
4487 }
4488
4489 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004490 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4491 * currently installed it.
4492 *
4493 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4494 *
4495 * @return List of package names to keep cached.
4496 * @hide
4497 */
4498 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4499 if (mService != null) {
4500 try {
4501 return mService.getKeepUninstalledPackages(admin);
4502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004503 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004504 }
4505 }
4506 return null;
4507 }
4508
4509 /**
4510 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4511 * currently installed it.
4512 *
4513 * <p>Please note that setting this policy does not imply that specified apps will be
4514 * automatically pre-cached.</p>
4515 *
4516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4517 * @param packageNames List of package names to keep cached.
4518 * @hide
4519 */
4520 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4521 @NonNull List<String> packageNames) {
4522 if (mService != null) {
4523 try {
4524 mService.setKeepUninstalledPackages(admin, packageNames);
4525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004526 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004527 }
4528 }
4529 }
4530
4531 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004532 * Called by a device owner to create a user with the specified name. The UserHandle returned
4533 * by this method should not be persisted as user handles are recycled as users are removed and
4534 * created. If you need to persist an identifier for this user, use
4535 * {@link UserManager#getSerialNumberForUser}.
4536 *
4537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4538 * @param name the user's name
4539 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004540 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4541 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004542 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004543 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004544 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004545 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004546 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004547 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004548 return null;
4549 }
4550
4551 /**
Jason Monk03978a42014-06-10 15:05:30 -04004552 * Called by a device owner to create a user with the specified name. The UserHandle returned
4553 * by this method should not be persisted as user handles are recycled as users are removed and
4554 * created. If you need to persist an identifier for this user, use
4555 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4556 * immediately.
4557 *
4558 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4559 * as registered as an active admin on the new user. The profile owner package will be
4560 * installed on the new user if it already is installed on the device.
4561 *
4562 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4563 * profileOwnerComponent when onEnable is called.
4564 *
4565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4566 * @param name the user's name
4567 * @param ownerName the human readable name of the organisation associated with this DPM.
4568 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4569 * the user.
4570 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4571 * on the new user.
4572 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004573 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4574 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004575 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004576 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004577 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004578 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004579 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004580 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4581 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004582 return null;
4583 }
4584
4585 /**
phweissa92e1212016-01-25 17:14:10 +01004586 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004587 */
4588 public static final int SKIP_SETUP_WIZARD = 0x0001;
4589
4590 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004591 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4592 * ephemeral.
4593 * @hide
4594 */
4595 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4596
4597 /**
phweissa92e1212016-01-25 17:14:10 +01004598 * Called by a device owner to create a user with the specified name and a given component of
4599 * the calling package as profile owner. The UserHandle returned by this method should not be
4600 * persisted as user handles are recycled as users are removed and created. If you need to
4601 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4602 * user will not be started in the background.
phweiss343fb332016-01-25 14:48:59 +01004603 *
phweissa92e1212016-01-25 17:14:10 +01004604 * <p>admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also
4605 * a DeviceAdminReceiver in the same package as admin, and will become the profile owner and
4606 * will be registered as an active admin on the new user. The profile owner package will be
4607 * installed on the new user.
phweiss343fb332016-01-25 14:48:59 +01004608 *
4609 * <p>If the adminExtras are not null, they will be stored on the device until the user is
4610 * started for the first time. Then the extras will be passed to the admin when
4611 * onEnable is called.
4612 *
4613 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4614 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004615 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
4616 * same package as admin, otherwise no user is created and an IllegalArgumentException is
4617 * thrown.
phweiss343fb332016-01-25 14:48:59 +01004618 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
4619 * user.
phweissa92e1212016-01-25 17:14:10 +01004620 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004621 * @see UserHandle
4622 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4623 * user could not be created.
phweiss343fb332016-01-25 14:48:59 +01004624 */
4625 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004626 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4627 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004628 try {
phweissa92e1212016-01-25 17:14:10 +01004629 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004630 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004631 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01004632 }
phweiss343fb332016-01-25 14:48:59 +01004633 }
4634
4635 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004636 * Called by a device owner to remove a user and all associated data. The primary user can
4637 * not be removed.
4638 *
4639 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4640 * @param userHandle the user to remove.
4641 * @return {@code true} if the user was removed, {@code false} otherwise.
4642 */
Robin Lee25e26452015-06-02 09:56:29 -07004643 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004644 try {
4645 return mService.removeUser(admin, userHandle);
4646 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004647 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04004648 }
4649 }
4650
4651 /**
Jason Monk582d9112014-07-09 19:57:08 -04004652 * Called by a device owner to switch the specified user to the foreground.
4653 *
4654 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4655 * @param userHandle the user to switch to; null will switch to primary.
4656 * @return {@code true} if the switch was successful, {@code false} otherwise.
4657 *
4658 * @see Intent#ACTION_USER_FOREGROUND
4659 */
Robin Lee25e26452015-06-02 09:56:29 -07004660 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004661 try {
4662 return mService.switchUser(admin, userHandle);
4663 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004664 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04004665 }
4666 }
4667
4668 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004669 * Retrieves the application restrictions for a given target application running in the calling
4670 * user.
Robin Lee66e5d962014-04-09 16:44:21 +01004671 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004672 * <p>The caller must be a profile or device owner on that user, or the package allowed to
4673 * manage application restrictions via {@link #setApplicationRestrictionsManagingPackage};
4674 * otherwise a security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004675 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004676 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
4677 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004678 * @param packageName The name of the package to fetch restricted settings of.
4679 * @return {@link Bundle} of settings corresponding to what was set last time
4680 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty {@link Bundle}
4681 * if no restrictions have been set.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004682 *
4683 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004684 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004685 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004686 if (mService != null) {
4687 try {
4688 return mService.getApplicationRestrictions(admin, packageName);
4689 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004690 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004691 }
4692 }
4693 return null;
4694 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004695
4696 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004697 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004698 * <p>
4699 * The calling device admin must be a profile or device owner; if it is not,
4700 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004701 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004702 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4703 * with.
4704 * @param key The key of the restriction. See the constants in
4705 * {@link android.os.UserManager} for the list of keys.
4706 */
Robin Lee25e26452015-06-02 09:56:29 -07004707 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004708 if (mService != null) {
4709 try {
4710 mService.setUserRestriction(admin, key, true);
4711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004712 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004713 }
4714 }
4715 }
4716
4717 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004718 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004719 * <p>
4720 * The calling device admin must be a profile or device owner; if it is not,
4721 * a security exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004722 *
Amith Yamasanibe465322014-04-24 13:45:17 -07004723 * @param admin Which {@link DeviceAdminReceiver} this request is associated
4724 * with.
4725 * @param key The key of the restriction. See the constants in
4726 * {@link android.os.UserManager} for the list of keys.
4727 */
Robin Lee25e26452015-06-02 09:56:29 -07004728 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004729 if (mService != null) {
4730 try {
4731 mService.setUserRestriction(admin, key, false);
4732 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004733 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004734 }
4735 }
4736 }
Adam Connors010cfd42014-04-16 12:48:13 +01004737
4738 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004739 * Called by a profile or device owner to get user restrictions set with
4740 * {@link #addUserRestriction(ComponentName, String)}.
4741 * <p>
4742 * The target user may have more restrictions set by the system or other device owner / profile
4743 * owner. To get all the user restrictions currently set, use
4744 * {@link UserManager#getUserRestrictions()}.
4745 *
4746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004747 * @throws SecurityException if the {@code admin} is not an active admin.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004748 */
4749 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004750 return getUserRestrictions(admin, myUserId());
4751 }
4752
4753 /** @hide per-user version */
4754 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004755 Bundle ret = null;
4756 if (mService != null) {
4757 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004758 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004759 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004760 throw e.rethrowFromSystemServer();
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004761 }
4762 }
4763 return ret == null ? new Bundle() : ret;
4764 }
4765
4766 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004767 * Called by profile or device owners to hide or unhide packages. When a package is hidden it
Julia Reynolds966881e2014-05-14 12:23:08 -04004768 * is unavailable for use, but the data and actual package file remain.
4769 *
4770 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004771 * @param packageName The name of the package to hide or unhide.
4772 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
4773 * unhidden.
4774 * @return boolean Whether the hidden setting of the package was successfully updated.
Julia Reynolds966881e2014-05-14 12:23:08 -04004775 */
Robin Lee25e26452015-06-02 09:56:29 -07004776 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004777 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004778 if (mService != null) {
4779 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004780 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004781 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004782 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004783 }
4784 }
4785 return false;
4786 }
4787
4788 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004789 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004790 *
4791 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004792 * @param packageName The name of the package to retrieve the hidden status of.
4793 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Julia Reynolds966881e2014-05-14 12:23:08 -04004794 */
Robin Lee25e26452015-06-02 09:56:29 -07004795 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004796 if (mService != null) {
4797 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004798 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004799 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004800 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004801 }
4802 }
4803 return false;
4804 }
4805
4806 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004807 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004808 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004809 *
4810 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004811 * @param packageName The package to be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004812 */
Robin Lee25e26452015-06-02 09:56:29 -07004813 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004814 if (mService != null) {
4815 try {
4816 mService.enableSystemApp(admin, packageName);
4817 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004818 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004819 }
4820 }
4821 }
4822
4823 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004824 * Called by profile or device owners to re-enable system apps by intent that were disabled
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004825 * by default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004826 *
4827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4828 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Makoto Onuki32b30572015-12-11 14:29:51 -08004829 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004830 * @return int The number of activities that matched the intent and were installed.
4831 */
Robin Lee25e26452015-06-02 09:56:29 -07004832 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004833 if (mService != null) {
4834 try {
4835 return mService.enableSystemAppWithIntent(admin, intent);
4836 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004837 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004838 }
4839 }
4840 return 0;
4841 }
4842
4843 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004844 * Called by a device owner or profile owner to disable account management for a specific type
4845 * of account.
Sander Alewijnse650c3342014-05-08 18:00:50 +01004846 *
Sander Alewijnse112e0532014-10-29 13:28:49 +00004847 * <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 +01004848 * security exception will be thrown.
4849 *
4850 * <p>When account management is disabled for an account type, adding or removing an account
4851 * of that type will not be possible.
4852 *
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004853 * <p>From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
4854 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4855 * management for a specific type is disabled.
4856 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004857 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4858 * @param accountType For which account management is disabled or enabled.
4859 * @param disabled The boolean indicating that account management will be disabled (true) or
4860 * enabled (false).
4861 */
Robin Lee25e26452015-06-02 09:56:29 -07004862 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01004863 boolean disabled) {
4864 if (mService != null) {
4865 try {
4866 mService.setAccountManagementDisabled(admin, accountType, disabled);
4867 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004868 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01004869 }
4870 }
4871 }
4872
4873 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004874 * Gets the array of accounts for which account management is disabled by the profile owner.
4875 *
4876 * <p> Account management can be disabled/enabled by calling
4877 * {@link #setAccountManagementDisabled}.
4878 *
4879 * @return a list of account types for which account management has been disabled.
4880 *
4881 * @see #setAccountManagementDisabled
4882 */
4883 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004884 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004885 }
4886
4887 /**
4888 * @see #getAccountTypesWithManagementDisabled()
4889 * @hide
4890 */
4891 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004892 if (mService != null) {
4893 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01004894 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004895 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004896 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01004897 }
4898 }
4899
4900 return null;
4901 }
justinzhang511e0d82014-03-24 16:09:24 -04004902
4903 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004904 * Sets which packages may enter lock task mode.
4905 *
4906 * <p>Any packages that shares uid with an allowed package will also be allowed
4907 * to activate lock task.
justinzhang511e0d82014-03-24 16:09:24 -04004908 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004909 * From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
Benjamin Franz469dd582015-06-09 14:24:36 +01004910 * package list results in locked tasks belonging to those packages to be finished.
4911 *
Jason Monkc5185f22014-06-24 11:12:42 -04004912 * This function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04004913 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04004914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jason Monkd7b86212014-06-16 13:15:38 -04004915 *
4916 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00004917 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
4918 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04004919 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04004920 */
Robin Lee25e26452015-06-02 09:56:29 -07004921 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04004922 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04004923 if (mService != null) {
4924 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004925 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04004926 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004927 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04004928 }
4929 }
4930 }
4931
4932 /**
Jason Monkd7b86212014-06-16 13:15:38 -04004933 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04004934 *
4935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04004936 * @hide
4937 */
Robin Lee25e26452015-06-02 09:56:29 -07004938 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04004939 if (mService != null) {
4940 try {
Jason Monk48aacba2014-08-13 16:29:08 -04004941 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04004942 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004943 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04004944 }
4945 }
4946 return null;
4947 }
4948
4949 /**
4950 * This function lets the caller know whether the given component is allowed to start the
4951 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04004952 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04004953 */
Jason Monkd7b86212014-06-16 13:15:38 -04004954 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04004955 if (mService != null) {
4956 try {
Jason Monkd7b86212014-06-16 13:15:38 -04004957 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04004958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004959 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04004960 }
4961 }
4962 return false;
4963 }
Julia Reynoldsda551652014-05-14 17:15:16 -04004964
4965 /**
4966 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
4967 * 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 -04004968 * <p>The settings that can be updated with this method are:
4969 * <ul>
4970 * <li>{@link Settings.Global#ADB_ENABLED}</li>
4971 * <li>{@link Settings.Global#AUTO_TIME}</li>
4972 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004973 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004974 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004975 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Benjamin Franz68cc4202015-03-11 15:43:06 +00004976 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN}
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004977 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004978 * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
Zoltan Szatmary-Ban4045d242015-05-27 12:42:39 +01004979 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004980 * This setting is only available from {@link android.os.Build.VERSION_CODES#M} onwards.
Zoltan Szatmary-Ban3c430952015-07-03 14:04:09 +01004981 * </li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04004982 * </ul>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004983 * <p>Changing the following settings has no effect as of
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004984 * {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01004985 * <ul>
4986 * <li>{@link Settings.Global#BLUETOOTH_ON}.
4987 * Use {@link android.bluetooth.BluetoothAdapter#enable()} and
4988 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
4989 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
4990 * <li>{@link Settings.Global#MODE_RINGER}.
4991 * Use {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
4992 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
4993 * <li>{@link Settings.Global#WIFI_ON}.
4994 * Use {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
4995 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04004996 *
4997 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4998 * @param setting The name of the setting to update.
4999 * @param value The value to update the setting to.
5000 */
Robin Lee25e26452015-06-02 09:56:29 -07005001 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005002 if (mService != null) {
5003 try {
5004 mService.setGlobalSetting(admin, setting, value);
5005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005006 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005007 }
5008 }
5009 }
5010
5011 /**
5012 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5013 * that the value of the setting is in the correct form for the setting type should be performed
5014 * by the caller.
Julia Reynolds82735bc2014-09-04 16:43:30 -04005015 * <p>The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005016 * <ul>
5017 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005018 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005019 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5020 * </ul>
Julia Reynolds82735bc2014-09-04 16:43:30 -04005021 * <p>A device owner can additionally update the following settings:
5022 * <ul>
5023 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5024 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005025 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5026 * @param setting The name of the setting to update.
5027 * @param value The value to update the setting to.
5028 */
Robin Lee25e26452015-06-02 09:56:29 -07005029 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005030 if (mService != null) {
5031 try {
5032 mService.setSecureSetting(admin, setting, value);
5033 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005034 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005035 }
5036 }
5037 }
5038
Amith Yamasanif20d6402014-05-24 15:34:37 -07005039 /**
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005040 * Designates a specific service component as the provider for
Amith Yamasanif20d6402014-05-24 15:34:37 -07005041 * making permission requests of a local or remote administrator of the user.
5042 * <p/>
5043 * Only a profile owner can designate the restrictions provider.
5044 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005045 * @param provider The component name of the service that implements
Amith Yamasanid1d7c022014-08-19 17:03:41 -07005046 * {@link RestrictionsReceiver}. If this param is null,
Amith Yamasanif20d6402014-05-24 15:34:37 -07005047 * it removes the restrictions provider previously assigned.
5048 */
Robin Lee25e26452015-06-02 09:56:29 -07005049 public void setRestrictionsProvider(@NonNull ComponentName admin,
5050 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005051 if (mService != null) {
5052 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005053 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005054 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005055 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005056 }
5057 }
5058 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005059
5060 /**
5061 * Called by profile or device owners to set the master volume mute on or off.
5062 *
5063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5064 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
5065 */
Robin Lee25e26452015-06-02 09:56:29 -07005066 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005067 if (mService != null) {
5068 try {
5069 mService.setMasterVolumeMuted(admin, on);
5070 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005071 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005072 }
5073 }
5074 }
5075
5076 /**
5077 * Called by profile or device owners to check whether the master volume mute is on or off.
5078 *
5079 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5080 * @return {@code true} if master volume is muted, {@code false} if it's not.
5081 */
Robin Lee25e26452015-06-02 09:56:29 -07005082 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005083 if (mService != null) {
5084 try {
5085 return mService.isMasterVolumeMuted(admin);
5086 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005087 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005088 }
5089 }
5090 return false;
5091 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005092
5093 /**
5094 * Called by profile or device owners to change whether a user can uninstall
5095 * a package.
5096 *
5097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5098 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005099 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005100 */
Robin Lee25e26452015-06-02 09:56:29 -07005101 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005102 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005103 if (mService != null) {
5104 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005105 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005106 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005107 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005108 }
5109 }
5110 }
5111
5112 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005113 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005114 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005115 * <p>
5116 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Robin Lee25e26452015-06-02 09:56:29 -07005117 * behavior of this API is changed such that passing {@code null} as the {@code admin}
Rubin Xue1e6faa2015-03-10 10:51:59 +00005118 * parameter will return if any admin has blocked the uninstallation. Before L MR1, passing
Robin Lee25e26452015-06-02 09:56:29 -07005119 * {@code null} will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005120 *
Robin Lee25e26452015-06-02 09:56:29 -07005121 * @param admin The name of the admin component whose blocking policy will be checked, or
5122 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005123 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005124 * @return true if uninstallation is blocked.
Kenny Guyc13053b2014-05-29 14:17:17 +01005125 */
Robin Lee25e26452015-06-02 09:56:29 -07005126 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005127 if (mService != null) {
5128 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005129 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005130 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005131 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005132 }
5133 }
5134 return false;
5135 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005136
5137 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005138 * Called by the profile owner of a managed profile to enable widget providers from a
5139 * given package to be available in the parent profile. As a result the user will be able to
Svetoslav976e8bd2014-07-16 15:12:03 -07005140 * add widgets from the white-listed package running under the profile to a widget
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005141 * host which runs under the parent profile, for example the home screen. Note that
Svetoslav976e8bd2014-07-16 15:12:03 -07005142 * a package may have zero or more provider components, where each component
5143 * provides a different widget type.
5144 * <p>
5145 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005146 *
5147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5148 * @param packageName The package from which widget providers are white-listed.
5149 * @return Whether the package was added.
5150 *
5151 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5152 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5153 */
Robin Lee25e26452015-06-02 09:56:29 -07005154 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005155 if (mService != null) {
5156 try {
5157 return mService.addCrossProfileWidgetProvider(admin, packageName);
5158 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005159 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005160 }
5161 }
5162 return false;
5163 }
5164
5165 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005166 * Called by the profile owner of a managed profile to disable widget providers from a given
5167 * package to be available in the parent profile. For this method to take effect the
Svetoslav976e8bd2014-07-16 15:12:03 -07005168 * package should have been added via {@link #addCrossProfileWidgetProvider(
5169 * android.content.ComponentName, String)}.
5170 * <p>
5171 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005172 *
5173 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5174 * @param packageName The package from which widget providers are no longer
5175 * white-listed.
5176 * @return Whether the package was removed.
5177 *
5178 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5179 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5180 */
Esteban Talavera62399912016-01-11 15:37:55 +00005181 public boolean removeCrossProfileWidgetProvider(
5182 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005183 if (mService != null) {
5184 try {
5185 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5186 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005187 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005188 }
5189 }
5190 return false;
5191 }
5192
5193 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005194 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005195 * available in the parent profile.
5196 *
5197 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5198 * @return The white-listed package list.
5199 *
5200 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5201 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5202 */
Robin Lee25e26452015-06-02 09:56:29 -07005203 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005204 if (mService != null) {
5205 try {
5206 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5207 if (providers != null) {
5208 return providers;
5209 }
5210 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005211 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005212 }
5213 }
5214 return Collections.emptyList();
5215 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005216
5217 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005218 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005219 *
5220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5221 * @param icon the bitmap to set as the photo.
5222 */
Robin Lee25e26452015-06-02 09:56:29 -07005223 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005224 try {
5225 mService.setUserIcon(admin, icon);
5226 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005227 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005228 }
5229 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005230
5231 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005232 * Called by device owners to set a local system update policy. When a new policy is set,
5233 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005234 *
Robin Lee25e26452015-06-02 09:56:29 -07005235 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
5236 * components in the device owner package can set system update policies and the
5237 * most recent policy takes
Rubin Xu5faad8e2015-04-20 17:43:48 +01005238 * effect.
Robin Lee25e26452015-06-02 09:56:29 -07005239 * @param policy the new policy, or {@code null} to clear the current policy.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005240 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005241 */
Robin Lee25e26452015-06-02 09:56:29 -07005242 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005243 if (mService != null) {
5244 try {
Robin Lee25e26452015-06-02 09:56:29 -07005245 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005246 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005247 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005248 }
5249 }
5250 }
5251
5252 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005253 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005254 *
Robin Lee25e26452015-06-02 09:56:29 -07005255 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005256 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005257 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005258 if (mService != null) {
5259 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005260 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005261 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005262 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005263 }
5264 }
5265 return null;
5266 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005267
5268 /**
5269 * Called by a device owner to disable the keyguard altogether.
5270 *
5271 * <p>Setting the keyguard to disabled has the same effect as choosing "None" as the screen
5272 * lock type. However, this call has no effect if a password, pin or pattern is currently set.
5273 * If a password, pin or pattern is set after the keyguard was disabled, the keyguard stops
5274 * being disabled.
5275 *
5276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005277 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005278 *
5279 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Benjamin Franzbece8062015-05-06 12:14:31 +01005280 * place. {@code true} otherwise.
Benjamin Franze36087e2015-04-07 16:40:34 +01005281 */
Robin Lee25e26452015-06-02 09:56:29 -07005282 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005283 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005284 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005285 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005286 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005287 }
5288 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005289
5290 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005291 * Called by device owner to disable the status bar. Disabling the status bar blocks
5292 * notifications, quick settings and other screen overlays that allow escaping from
Benjamin Franzea2ec972015-03-16 17:18:09 +00005293 * a single use device.
5294 *
5295 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005296 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
5297 *
5298 * @return {@code false} if attempting to disable the status bar failed.
5299 * {@code true} otherwise.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005300 */
Robin Lee25e26452015-06-02 09:56:29 -07005301 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005302 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005303 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005304 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005305 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005306 }
5307 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005308
5309 /**
5310 * Callable by the system update service to notify device owners about pending updates.
5311 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5312 * permission.
5313 *
5314 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5315 * when the current pending update was first available. -1 if no update is available.
5316 * @hide
5317 */
5318 @SystemApi
5319 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5320 if (mService != null) {
5321 try {
5322 mService.notifyPendingSystemUpdate(updateReceivedTime);
5323 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005324 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005325 }
5326 }
5327 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005328
5329 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005330 * Called by profile or device owners to set the default response for future runtime permission
5331 * requests by applications. The policy can allow for normal operation which prompts the
5332 * user to grant a permission, or can allow automatic granting or denying of runtime
5333 * permission requests by an application. This also applies to new permissions declared by app
Benjamin Franz45dd6662015-07-08 14:24:14 +01005334 * updates. When a permission is denied or granted this way, the effect is equivalent to setting
5335 * the permission grant state via {@link #setPermissionGrantState}.
5336 *
5337 * <p/>As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005338 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005339 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005340 * @param admin Which profile or device owner this request is associated with.
5341 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
5342 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005343 *
5344 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005345 */
Robin Lee25e26452015-06-02 09:56:29 -07005346 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005347 try {
5348 mService.setPermissionPolicy(admin, policy);
5349 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005350 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005351 }
5352 }
5353
5354 /**
5355 * Returns the current runtime permission policy set by the device or profile owner. The
5356 * default is {@link #PERMISSION_POLICY_PROMPT}.
5357 * @param admin Which profile or device owner this request is associated with.
5358 * @return the current policy for future permission requests.
5359 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005360 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005361 try {
5362 return mService.getPermissionPolicy(admin);
5363 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005364 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005365 }
5366 }
5367
5368 /**
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005369 * Sets the grant state of a runtime permission for a specific application. The state
5370 * can be {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it
5371 * through the UI, {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission
5372 * is denied and the user cannot manage it through the UI, and {@link
5373 * #PERMISSION_GRANT_STATE_GRANTED granted} in which the permission is granted and the
5374 * user cannot manage it through the UI. This might affect all permissions in a
5375 * group that the runtime permission belongs to. This method can only be called
5376 * by a profile or device owner.
5377 *
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005378 * <p/>Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not
5379 * revoke the permission. It retains the previous grant, if any.
5380 *
5381 * <p/>Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005382 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005383 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005384 * @param admin Which profile or device owner this request is associated with.
5385 * @param packageName The application to grant or revoke a permission to.
5386 * @param permission The permission to grant or revoke.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005387 * @param grantState The permission grant state which is one of {@link
5388 * #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5389 * {@link #PERMISSION_GRANT_STATE_GRANTED},
5390 * @return whether the permission was successfully granted or revoked.
5391 *
5392 * @see #PERMISSION_GRANT_STATE_DENIED
5393 * @see #PERMISSION_GRANT_STATE_DEFAULT
5394 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005395 */
Robin Lee25e26452015-06-02 09:56:29 -07005396 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005397 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005398 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005399 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005400 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005401 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005402 }
5403 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005404
5405 /**
5406 * Returns the current grant state of a runtime permission for a specific application.
5407 *
5408 * @param admin Which profile or device owner this request is associated with.
5409 * @param packageName The application to check the grant state for.
5410 * @param permission The permission to check for.
5411 * @return the current grant state specified by device policy. If the profile or device owner
5412 * has not set a grant state, the return value is {@link #PERMISSION_GRANT_STATE_DEFAULT}.
5413 * This does not indicate whether or not the permission is currently granted for the package.
5414 *
5415 * <p/>If a grant state was set by the profile or device owner, then the return value will
5416 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or {@link #PERMISSION_GRANT_STATE_GRANTED},
5417 * which indicates if the permission is currently denied or granted.
5418 *
5419 * @see #setPermissionGrantState(ComponentName, String, String, int)
5420 * @see PackageManager#checkPermission(String, String)
5421 */
Robin Lee25e26452015-06-02 09:56:29 -07005422 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005423 String permission) {
5424 try {
5425 return mService.getPermissionGrantState(admin, packageName, permission);
5426 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005427 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005428 }
5429 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005430
5431 /**
5432 * Returns if provisioning a managed profile or device is possible or not.
5433 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5434 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
5435 * Note that even if this method returns true, there is a slight possibility that the
5436 * provisioning will not be allowed when it is actually initiated because some event has
5437 * happened in between.
5438 * @return if provisioning a managed profile or device is possible or not.
5439 * @throws IllegalArgumentException if the supplied action is not valid.
5440 */
5441 public boolean isProvisioningAllowed(String action) {
5442 try {
5443 return mService.isProvisioningAllowed(action);
5444 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005445 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005446 }
5447 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005448
5449 /**
5450 * @hide
5451 * Return if this user is a managed profile of another user. An admin can become the profile
5452 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5453 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5454 * @param admin Which profile owner this request is associated with.
5455 * @return if this user is a managed profile of another user.
5456 */
5457 public boolean isManagedProfile(@NonNull ComponentName admin) {
5458 try {
5459 return mService.isManagedProfile(admin);
5460 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005461 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005462 }
5463 }
5464
5465 /**
5466 * @hide
5467 * Return if this user is a system-only user. An admin can manage a device from a system only
5468 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5469 * @param admin Which device owner this request is associated with.
5470 * @return if this user is a system-only user.
5471 */
5472 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5473 try {
5474 return mService.isSystemOnlyUser(admin);
5475 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005476 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005477 }
5478 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005479
5480 /**
5481 * Called by device owner to get the MAC address of the Wi-Fi device.
5482 *
5483 * @return the MAC address of the Wi-Fi device, or null when the information is not
5484 * available. (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5485 *
5486 * <p>The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5487 */
5488 public String getWifiMacAddress() {
5489 try {
5490 return mService.getWifiMacAddress();
5491 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005492 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005493 }
5494 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005495
5496 /**
5497 * Called by device owner to reboot the device.
5498 */
5499 public void reboot(@NonNull ComponentName admin) {
5500 try {
5501 mService.reboot(admin);
5502 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005503 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005504 }
5505 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005506
5507 /**
5508 * Called by a device admin to set the short support message. This will
5509 * be displayed to the user in settings screens where funtionality has
5510 * been disabled by the admin.
5511 *
5512 * The message should be limited to a short statement such as
5513 * "This setting is disabled by your administrator. Contact someone@example.com
5514 * for support."
5515 * If the message is longer than 200 characters it may be truncated.
5516 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005517 * <p>If the short support message needs to be localized, it is the responsibility of the
5518 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5519 * and set a new version of this string accordingly.
5520 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005521 * @see #setLongSupportMessage
5522 *
5523 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5524 * @param message Short message to be displayed to the user in settings or null to
5525 * clear the existing message.
5526 */
5527 public void setShortSupportMessage(@NonNull ComponentName admin,
5528 @Nullable String message) {
5529 if (mService != null) {
5530 try {
5531 mService.setShortSupportMessage(admin, message);
5532 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005533 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005534 }
5535 }
5536 }
5537
5538 /**
5539 * Called by a device admin to get the short support message.
5540 *
5541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5542 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5543 * or null if no message has been set.
5544 */
5545 public String getShortSupportMessage(@NonNull ComponentName admin) {
5546 if (mService != null) {
5547 try {
5548 return mService.getShortSupportMessage(admin);
5549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005550 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005551 }
5552 }
5553 return null;
5554 }
5555
5556 /**
5557 * Called by a device admin to set the long support message. This will
5558 * be displayed to the user in the device administators settings screen.
5559 *
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005560 * <p>If the long support message needs to be localized, it is the responsibility of the
5561 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5562 * and set a new version of this string accordingly.
5563 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005564 * @see #setShortSupportMessage
5565 *
5566 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5567 * @param message Long message to be displayed to the user in settings or null to
5568 * clear the existing message.
5569 */
5570 public void setLongSupportMessage(@NonNull ComponentName admin,
5571 @Nullable String message) {
5572 if (mService != null) {
5573 try {
5574 mService.setLongSupportMessage(admin, message);
5575 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005576 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005577 }
5578 }
5579 }
5580
5581 /**
5582 * Called by a device admin to get the long support message.
5583 *
5584 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5585 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5586 * or null if no message has been set.
5587 */
5588 public String getLongSupportMessage(@NonNull ComponentName admin) {
5589 if (mService != null) {
5590 try {
5591 return mService.getLongSupportMessage(admin);
5592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005593 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005594 }
5595 }
5596 return null;
5597 }
5598
5599 /**
5600 * Called by the system to get the short support message.
5601 *
5602 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5603 * @param userHandle user id the admin is running as.
5604 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5605 *
5606 * @hide
5607 */
5608 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5609 if (mService != null) {
5610 try {
5611 return mService.getShortSupportMessageForUser(admin, userHandle);
5612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005613 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005614 }
5615 }
5616 return null;
5617 }
5618
5619
5620 /**
5621 * Called by the system to get the long support message.
5622 *
5623 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5624 * @param userHandle user id the admin is running as.
5625 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5626 *
5627 * @hide
5628 */
5629 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5630 if (mService != null) {
5631 try {
5632 return mService.getLongSupportMessageForUser(admin, userHandle);
5633 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005634 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005635 }
5636 }
5637 return null;
5638 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005639
5640 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005641 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5642 * whose calls act on the parent profile.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005643 *
5644 * <p> Note only some methods will work on the parent Manager.
5645 *
5646 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
5647 */
5648 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5649 try {
5650 if (!mService.isManagedProfile(admin)) {
5651 throw new SecurityException("The current user does not have a parent profile.");
5652 }
5653 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005654 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005655 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005656 }
5657 }
5658
5659 /**
5660 * Called by device owner to control the device logging feature. Logging can only be
5661 * enabled on single user devices where the sole user is managed by the device owner.
5662 *
5663 * <p> Device logs contain various information intended for security auditing purposes.
5664 * See {@link SecurityEvent} for details.
5665 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005666 * <p>There must be only one user on the device, managed by the device owner.
5667 * Otherwise a {@link SecurityException} will be thrown.
5668 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005669 * @param admin Which device owner this request is associated with.
5670 * @param enabled whether device logging should be enabled or not.
5671 * @see #retrieveDeviceLogs
5672 */
5673 public void setDeviceLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5674 try {
5675 mService.setDeviceLoggingEnabled(admin, enabled);
5676 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005677 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005678 }
5679 }
5680
5681 /**
5682 * Return whether device logging is enabled or not by the device owner.
5683 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005684 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
5685 * thrown.
5686 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005687 * @param admin Which device owner this request is associated with.
5688 * @return {@code true} if device logging is enabled by device owner, {@code false} otherwise.
5689 */
5690 public boolean getDeviceLoggingEnabled(@NonNull ComponentName admin) {
5691 try {
5692 return mService.getDeviceLoggingEnabled(admin);
5693 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005694 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005695 }
5696 }
5697
5698 /**
5699 * Called by device owner to retrieve all new device logging entries since the last call to
5700 * this API after device boots.
5701 *
5702 * <p> Access to the logs is rate limited and it will only return new logs after the device
5703 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5704 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005705 * <p>There must be only one user on the device, managed by the device owner.
5706 * Otherwise a {@link SecurityException} will be thrown.
5707 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005708 * @param admin Which device owner this request is associated with.
5709 * @return the new batch of device logs which is a list of {@link SecurityEvent},
5710 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
5711 */
5712 public List<SecurityEvent> retrieveDeviceLogs(@NonNull ComponentName admin) {
5713 try {
5714 ParceledListSlice<SecurityEvent> list = mService.retrieveDeviceLogs(admin);
5715 if (list != null) {
5716 return list.getList();
5717 } else {
5718 // Rate limit exceeded.
5719 return null;
5720 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005721 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005722 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005723 }
5724 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005725
5726 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005727 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5728 * profile.
5729 *
5730 * @hide
5731 */
5732 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5733 mContext.checkSelfPermission(
5734 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5735 if (!uInfo.isManagedProfile()) {
5736 throw new SecurityException("The user " + uInfo.id
5737 + " does not have a parent profile.");
5738 }
5739 return new DevicePolicyManager(mContext, true);
5740 }
5741
5742 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005743 * Called by device owners to retrieve device logs from before the device's last reboot.
5744 *
5745 * <p>
5746 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
5747 * corruption-free during power cycles, due to hardware variations and limitations. As a
5748 * result, this API is provided as best-effort and the returned logs may contain corrupted data.
5749 * </strong>
5750 *
Michal Karpinskib58e4962016-03-01 14:55:10 +00005751 * <p>There must be only one user on the device, managed by the device owner.
5752 * Otherwise a {@link SecurityException} will be thrown.
5753 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005754 * @param admin Which device owner this request is associated with.
5755 * @return Device logs from before the latest reboot of the system.
5756 */
5757 public List<SecurityEvent> retrievePreviousDeviceLogs(@NonNull ComponentName admin) {
5758 try {
5759 ParceledListSlice<SecurityEvent> list = mService.retrievePreviousDeviceLogs(admin);
5760 return list.getList();
5761 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005762 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005763 }
5764 }
5765
5766 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005767 * Called by a profile owner of a managed profile to set the color used for customization.
5768 * This color is used as background color of the confirm credentials screen for that user.
5769 * The default color is {@link android.graphics.Color#GRAY}.
5770 *
5771 * <p>The confirm credentials screen can be created using
5772 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5773 *
5774 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5775 * @param color The 32bit representation of the color to be used.
5776 */
5777 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5778 try {
5779 mService.setOrganizationColor(admin, color);
5780 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005781 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005782 }
5783 }
5784
5785 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005786 * @hide
5787 *
5788 * Sets the color used for customization.
5789 *
5790 * @param color The 32bit representation of the color to be used.
5791 * @param userId which user to set the color to.
5792 * @RequiresPermission(allOf = {
5793 * Manifest.permission.MANAGE_USERS,
5794 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5795 */
5796 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5797 try {
5798 mService.setOrganizationColorForUser(color, userId);
5799 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005800 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005801 }
5802 }
5803
5804 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005805 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5806 * This color is used as background color of the confirm credentials screen for that user.
5807 *
5808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5809 * @return The 32bit representation of the color to be used.
5810 */
5811 public int getOrganizationColor(@NonNull ComponentName admin) {
5812 try {
5813 return mService.getOrganizationColor(admin);
5814 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005815 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005816 }
5817 }
5818
5819 /**
5820 * @hide
5821 * Retrieve the customization color for a given user.
5822 *
5823 * @param userHandle The user id of the user we're interested in.
5824 * @return The 32bit representation of the color to be used.
5825 */
5826 public int getOrganizationColorForUser(int userHandle) {
5827 try {
5828 return mService.getOrganizationColorForUser(userHandle);
5829 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005830 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005831 }
5832 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005833
5834 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005835 * Called by a profile owner of a managed profile to set the name of the organization under
5836 * management.
5837 *
5838 * <p>If the organization name needs to be localized, it is the responsibility of the
5839 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5840 * and set a new version of this string accordingly.
5841 *
5842 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5843 * @param title The organization name or {@code null} to clear a previously set name.
5844 */
5845 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
5846 try {
5847 mService.setOrganizationName(admin, title);
5848 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005849 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005850 }
5851 }
5852
5853 /**
5854 * Called by a profile owner of a managed profile to retrieve the name of the organization
5855 * under management.
5856 *
5857 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5858 * @return The organization name or {@code null} if none is set.
5859 */
5860 public String getOrganizationName(@NonNull ComponentName admin) {
5861 try {
5862 return mService.getOrganizationName(admin);
5863 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005864 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005865 }
5866 }
5867
5868 /**
5869 * Retrieve the default title message used in the confirm credentials screen for a given user.
5870 *
5871 * @param userHandle The user id of the user we're interested in.
5872 * @return The organization name or {@code null} if none is set.
5873 *
5874 * @hide
5875 */
5876 public String getOrganizationNameForUser(int userHandle) {
5877 try {
5878 return mService.getOrganizationNameForUser(userHandle);
5879 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005880 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005881 }
5882 }
5883
5884 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00005885 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
5886 * return {@link #STATE_USER_UNMANAGED}
5887 * @hide
5888 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00005889 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00005890 @UserProvisioningState
5891 public int getUserProvisioningState() {
5892 if (mService != null) {
5893 try {
5894 return mService.getUserProvisioningState();
5895 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005896 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00005897 }
5898 }
5899 return STATE_USER_UNMANAGED;
5900 }
5901
5902 /**
5903 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
5904 *
5905 * @param state to store
5906 * @param userHandle for user
5907 * @hide
5908 */
5909 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
5910 if (mService != null) {
5911 try {
5912 mService.setUserProvisioningState(state, userHandle);
5913 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005914 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00005915 }
5916 }
5917 }
5918
5919 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005920 * @hide
5921 * Indicates the entity that controls the device or profile owner. A user/profile is considered
5922 * affiliated if it is managed by the same entity as the device.
5923 *
5924 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
5925 * user/profile is considered affiliated if the following conditions are both met:
5926 * <ul>
5927 * <li>The device owner and the user's/profile's profile owner have called this method,
5928 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
5929 * and a profile owner intersect, they must have come from the same source, which means that
5930 * the device owner and profile owner are controlled by the same entity.</li>
5931 * <li>The device owner's and profile owner's package names are the same.</li>
5932 * </ul>
5933 *
5934 * @param admin Which profile or device owner this request is associated with.
5935 * @param ids A set of opaque affiliation ids.
5936 */
5937 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
5938 try {
5939 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
5940 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005941 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005942 }
5943 }
5944
5945 /**
5946 * @hide
5947 * Returns whether this user/profile is affiliated with the device. See
5948 * {@link #setAffiliationIds} for the definition of affiliation.
5949 *
5950 * @return whether this user/profile is affiliated with the device.
5951 */
5952 public boolean isAffiliatedUser() {
5953 try {
5954 return mService != null && mService.isAffiliatedUser();
5955 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005956 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005957 }
5958 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005959
5960 /**
5961 * @hide
5962 * Returns whether the uninstall for {@code packageName} for the current user is in queue
5963 * to be started
5964 * @param packageName the package to check for
5965 * @return whether the uninstall intent for {@code packageName} is pending
5966 */
5967 public boolean isUninstallInQueue(String packageName) {
5968 try {
5969 return mService.isUninstallInQueue(packageName);
5970 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005971 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005972 }
5973 }
5974
5975 /**
5976 * @hide
5977 * @param packageName the package containing active DAs to be uninstalled
5978 */
5979 public void uninstallPackageWithActiveAdmins(String packageName) {
5980 try {
5981 mService.uninstallPackageWithActiveAdmins(packageName);
5982 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005983 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08005984 }
5985 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08005986}