blob: 62659d9323c3487687ea0ccaaf672283f0c94c1f [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;
Michal Karpinski6235a942016-03-15 12:07:23 +000028import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080029import android.content.ComponentName;
30import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010031import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000032import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080033import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000034import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000035import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000036import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050037import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040038import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000039import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010040import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070041import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000042import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080043import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080044import android.os.RemoteException;
45import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070046import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040047import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000048import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000049import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010050import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070051import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000052import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080053import android.util.Log;
54
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070055import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040056import com.android.org.conscrypt.TrustedCertificateStore;
57
58import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080059import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000060import java.lang.annotation.Retention;
61import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070062import java.net.InetSocketAddress;
63import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010064import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000065import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010066import java.security.PrivateKey;
67import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040068import java.security.cert.CertificateException;
69import java.security.cert.CertificateFactory;
70import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010071import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000072import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070073import java.util.ArrayList;
Svetoslav976e8bd2014-07-16 15:12:03 -070074import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080075import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010076import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080077
78/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000079 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070080 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
81 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
82 * device owner. A given method is accessible to all device administrators unless the documentation
83 * for that method specifies that it is restricted to either device or profile owners. Any
84 * application calling an api may only pass as an argument a device administrator component it
85 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080086 * <div class="special reference">
87 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070088 * <p>
89 * For more information about managing policies for device administration, read the <a href=
90 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
91 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080092 */
93public class DevicePolicyManager {
94 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080095
96 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -080097 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +000098 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -070099
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000100 private DevicePolicyManager(Context context, boolean parentInstance) {
Esteban Talavera62399912016-01-11 15:37:55 +0000101 this(context,
102 IDevicePolicyManager.Stub.asInterface(
103 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)),
104 parentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800105 }
106
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800107 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108 @VisibleForTesting
Esteban Talavera62399912016-01-11 15:37:55 +0000109 protected DevicePolicyManager(
110 Context context, IDevicePolicyManager service, boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 mContext = context;
112 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000113 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 }
115
116 /** @hide */
117 public static DevicePolicyManager create(Context context) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +0000118 DevicePolicyManager me = new DevicePolicyManager(context, false);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800119 return me.mService != null ? me : null;
120 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700121
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700122 /** @hide test will override it. */
123 @VisibleForTesting
124 protected int myUserId() {
125 return UserHandle.myUserId();
126 }
127
Dianne Hackbornd6847842010-01-12 18:14:19 -0800128 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000129 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000130 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100131 * <p>A managed profile allows data separation for example for the usage of a
132 * device as a personal and corporate device. The user which provisioning is started from and
133 * the managed profile share a launcher.
134 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800135 * <p>This intent will typically be sent by a mobile device management application (MDM).
136 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
137 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100138 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000139 * <p>It is possible to check if provisioning is allowed or not by querying the method
140 * {@link #isProvisioningAllowed(String)}.
141 *
142 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000143 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700144 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000145 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
146 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000147 *
Benjamin Franzea956242016-03-21 15:45:56 +0000148 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000149 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000150 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
151 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
152 * {@link android.os.Build.VERSION_CODES#N}</li>
153 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
154 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
155 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000156 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000157 *
Benjamin Franzea956242016-03-21 15:45:56 +0000158 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000159 * in the provisioning intent. The
160 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
161 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
162 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100163 *
Benjamin Franzea956242016-03-21 15:45:56 +0000164 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100165 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100166 *
167 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
168 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
169 * the provisioning flow was successful, although this doesn't guarantee the full flow will
170 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
171 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000172 */
173 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
174 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100175 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000176
177 /**
Mahaver 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 *
Benjamin Franzea956242016-03-21 15:45:56 +0000186 * <p>The intent contains the following extras:
187 * <ul>
188 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
189 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
190 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
191 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
192 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
193 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000194 *
Benjamin Franzea956242016-03-21 15:45:56 +0000195 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000196 *
197 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
198 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
199 * the provisioning flow was successful, although this doesn't guarantee the full flow will
200 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
201 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000202 *
203 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000204 */
205 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
206 public static final String ACTION_PROVISION_MANAGED_USER
207 = "android.app.action.PROVISION_MANAGED_USER";
208
209 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100210 * Activity action: Starts the provisioning flow which sets up a managed device.
211 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
212 *
213 * <p> During device owner provisioning a device admin app is set as the owner of the device.
214 * A device owner has full control over the device. The device owner can not be modified by the
215 * user.
216 *
217 * <p> A typical use case would be a device that is owned by a company, but used by either an
218 * employee or client.
219 *
220 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000221 * It is possible to check if provisioning is allowed or not by querying the method
222 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100223 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000224 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100225 * <ul>
226 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
227 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
228 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100229 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000230 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000231 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100232 * </ul>
233 *
Benjamin Franzea956242016-03-21 15:45:56 +0000234 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100235 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
236 * device owner.
237 *
Benjamin Franzea956242016-03-21 15:45:56 +0000238 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 *
Alan Treadway4582f812015-07-28 11:49:35 +0100240 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
241 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
242 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
243 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100244 */
245 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
246 public static final String ACTION_PROVISION_MANAGED_DEVICE
247 = "android.app.action.PROVISION_MANAGED_DEVICE";
248
249 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000250 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000251 *
252 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
253 * the device. A device owner has full control over the device. The device owner can not be
254 * modified by the user and the only way of resetting the device is via factory reset.
255 *
256 * <p>A typical use case would be a device that is owned by a company, but used by either an
257 * employee or client.
258 *
259 * <p>The provisioning message should be sent to an unprovisioned device.
260 *
261 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
262 * by a privileged app with the permission
263 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
264 *
265 * <p>The provisioning intent contains the following properties:
266 * <ul>
267 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
268 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
283 *
284 * @hide
285 */
286 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
287 @SystemApi
288 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
289 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
290
291 /**
292 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000293 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
294 *
295 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
296 * management state that is distinct from that reached by
297 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
298 * user, and only has control over device-wide policies, not individual users and their data.
299 * The primary benefit is that multiple non-system users are supported when provisioning using
300 * this form of device management.
301 *
Benjamin Franzea956242016-03-21 15:45:56 +0000302 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000303 * A device owner has full control over the device. The device owner can not be modified by the
304 * user.
305 *
Benjamin Franzea956242016-03-21 15:45:56 +0000306 * <p>A typical use case would be a device that is owned by a company, but used by either an
Alan Treadway46dd4492015-11-09 13:57:19 +0000307 * employee or client.
308 *
Benjamin Franzea956242016-03-21 15:45:56 +0000309 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000310 * It is possible to check if provisioning is allowed or not by querying the method
311 * {@link #isProvisioningAllowed(String)}.
312 *
313 * <p>The intent contains the following extras:
314 * <ul>
315 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
316 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
317 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
318 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000319 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
320 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000321 * </ul>
322 *
Benjamin Franzea956242016-03-21 15:45:56 +0000323 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000324 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
325 * device owner.
326 *
Benjamin Franzea956242016-03-21 15:45:56 +0000327 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000328 *
329 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
330 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
331 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
332 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
333 *
334 * @hide
335 */
336 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
337 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
338 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
339
340 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000341 * Activity action: Finalizes management provisioning, should be used after user-setup
342 * has been completed and {@link #getUserProvisioningState()} returns one of:
343 * <ul>
344 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
345 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
346 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
347 * </ul>
348 *
349 * @hide
350 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000351 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000352 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
353 public static final String ACTION_PROVISION_FINALIZATION
354 = "android.app.action.PROVISION_FINALIZATION";
355
356 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000357 * Action: Bugreport sharing with device owner has been accepted by the user.
358 *
359 * @hide
360 */
361 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
362 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
363
364 /**
365 * Action: Bugreport sharing with device owner has been declined by the user.
366 *
367 * @hide
368 */
369 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
370 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
371
372 /**
373 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
374 *
375 * @hide
376 */
377 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
378 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
379
380 /**
381 * Extra for shared bugreport's SHA-256 hash.
382 *
383 * @hide
384 */
385 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
386 "android.intent.extra.REMOTE_BUGREPORT_HASH";
387
388 /**
389 * Extra for remote bugreport notification shown type.
390 *
391 * @hide
392 */
393 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
394 "android.app.extra.bugreport_notification_type";
395
396 /**
397 * Notification type for a started remote bugreport flow.
398 *
399 * @hide
400 */
401 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
402
403 /**
404 * Notification type for a bugreport that has already been accepted to be shared, but is still
405 * being taken.
406 *
407 * @hide
408 */
409 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
410
411 /**
412 * Notification type for a bugreport that has been taken and can be shared or declined.
413 *
414 * @hide
415 */
416 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
417
418 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100419 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100420 * allows a mobile device management application or NFC programmer application which starts
421 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100422 * <p>
423 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
424 * sends the intent to pass data to itself on the newly created profile.
425 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
426 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100427 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
428 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
429 * message should contain a stringified {@link java.util.Properties} instance, whose string
430 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
431 * management application after provisioning.
432 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100433 * <p>
434 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700435 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
436 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100437 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100438 */
439 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100440 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100441
442 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100443 * A String extra holding the package name of the mobile device management application that
444 * will be set as the profile owner or device owner.
445 *
446 * <p>If an application starts provisioning directly via an intent with action
447 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
448 * application that started provisioning. The package will be set as profile owner in that case.
449 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000450 * <p>This package is set as device owner when device owner provisioning is started by an NFC
451 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000452 *
453 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700454 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000455 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000456 * @see DeviceAdminReceiver
457 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100458 * supported, but only if there is only one device admin receiver in the package that requires
459 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000460 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000461 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000462 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100463 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000464
465 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000466 * A ComponentName extra indicating the device admin receiver of the mobile device management
467 * application that will be set as the profile owner or device owner and active admin.
468 *
469 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100470 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
471 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
472 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000473 *
474 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100475 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
476 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000477 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000478 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000479 *
480 * @see DeviceAdminReceiver
481 */
482 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
483 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
484
485 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000486 * An {@link android.accounts.Account} extra holding the account to migrate during managed
487 * profile provisioning. If the account supplied is present in the primary user, it will be
488 * copied, along with its credentials to the managed profile and removed from the primary user.
489 *
490 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
491 */
492
493 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
494 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
495
496 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100497 * A String extra that, holds the email address of the account which a managed profile is
498 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
499 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100500 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100501 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
502 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100503 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
504 * contains this extra, it is forwarded in the
505 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
506 * device management application that was set as the profile owner during provisioning.
507 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100508 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100509 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
510 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100511
512 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000513 * A integer extra indicating the predominant color to show during the provisioning.
514 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000515 *
516 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
517 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
518 */
519 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
520 "android.app.extra.PROVISIONING_MAIN_COLOR";
521
522 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000523 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700524 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000525 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100526 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
527 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000528 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000529 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
530 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000531
532 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100533 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
534 * will be set to.
535 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000536 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
537 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100538 */
539 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100540 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100541
542 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100543 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
544 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100545 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000546 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
547 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100548 */
549 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100550 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100551
552 /**
553 * A String extra holding the {@link java.util.Locale} that the device will be set to.
554 * Format: xx_yy, where xx is the language code, and yy the country code.
555 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000556 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
557 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100558 */
559 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100560 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100561
562 /**
563 * A String extra holding the ssid of the wifi network that should be used during nfc device
564 * owner provisioning for downloading the mobile device management application.
565 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000566 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
567 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100568 */
569 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100570 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571
572 /**
573 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
574 * is hidden or not.
575 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000576 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
577 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100578 */
579 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100580 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581
582 /**
583 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100584 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
585 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100586 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000587 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
588 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 */
590 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100591 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592
593 /**
594 * A String extra holding the password of the wifi network in
595 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
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 Alewijnse1cc4ecc2014-06-23 19:56:52 +0100599 */
600 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100601 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602
603 /**
604 * A String extra holding the proxy host for the wifi network in
605 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
606 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000607 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
608 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100609 */
610 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100611 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612
613 /**
614 * An int extra holding the proxy port for the wifi network in
615 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
616 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000617 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
618 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100619 */
620 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100621 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622
623 /**
624 * A String extra holding the proxy bypass for the wifi network in
625 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
626 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000627 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
628 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100629 */
630 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100631 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632
633 /**
634 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
635 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
636 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000637 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
638 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100639 */
640 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100641 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642
643 /**
644 * A String extra holding a url that specifies the download location of the device admin
645 * package. When not provided it is assumed that the device admin package is already installed.
646 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000647 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
648 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100649 */
650 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100651 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100652
653 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400654 * An int extra holding a minimum required version code for the device admin package. If the
655 * device admin is already installed on the device, it will only be re-downloaded from
656 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
657 * installed package is less than this version code.
658 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400659 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400660 * provisioning via an NFC bump.
661 */
662 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
663 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
664
665 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100666 * A String extra holding a http cookie header which should be used in the http request to the
667 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
668 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000669 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
670 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100671 */
672 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100673 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100674
675 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100676 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
677 * the file at download location specified in
678 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100679 *
Benjamin Franzea956242016-03-21 15:45:56 +0000680 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
681 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100682 * location. If the checksum doesn't match an error will be shown to the user and the user will
683 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100684 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000685 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
686 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100687 *
688 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
689 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700690 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100691 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100692 */
693 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100694 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100695
696 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100697 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100698 * android package archive at the download location specified in {@link
699 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
700 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100701 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100702 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
703 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
704 *
Benjamin Franzea956242016-03-21 15:45:56 +0000705 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
706 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100707 * the download location. If the checksum does not match an error will be shown to the user and
708 * the user will be asked to factory reset the device.
709 *
710 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
711 * provisioning via an NFC bump.
712 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100713 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
714 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100715
716 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000717 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
718 * has completed successfully.
719 *
720 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700721 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000722 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800723 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000724 * corresponds to the account requested to be migrated at provisioning time, if any.
725 */
726 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
727 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
728 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
729
730 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000731 * A boolean extra indicating whether device encryption can be skipped as part of device owner
732 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500733 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400734 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100735 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000736 *
737 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
738 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500739 */
740 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
741 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
742
743 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000744 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
745 * provisioning. If this extra is not passed, a default image will be shown.
746 * <h5>The following URI schemes are accepted:</h5>
747 * <ul>
748 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
749 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
750 * </ul>
751 *
752 * <p> It is the responsability of the caller to provide an image with a reasonable
753 * pixed density for the device.
754 *
755 * <p> If a content: URI is passed, the intent should have the flag
756 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
757 * {@link android.content.ClipData} of the intent too.
758 *
759 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
760 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
761 */
762 public static final String EXTRA_PROVISIONING_LOGO_URI =
763 "android.app.extra.PROVISIONING_LOGO_URI";
764
765 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000766 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
767 * during setup-wizard.
768 *
769 * <p>If unspecified, defaults to {@code true} to match the behavior in
770 * {@link android.os.Build.VERSION_CODES#M} and earlier.
771 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000772 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
773 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000774 *
775 * @hide
776 */
777 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
778 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
779
780 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000781 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100782 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400783 * <p>During device owner provisioning a device admin app is set as the owner of the device.
784 * A device owner has full control over the device. The device owner can not be modified by the
785 * user and the only way of resetting the device is if the device owner app calls a factory
786 * reset.
787 *
788 * <p> A typical use case would be a device that is owned by a company, but used by either an
789 * employee or client.
790 *
Benjamin Franzea956242016-03-21 15:45:56 +0000791 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100792 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000793 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100794 * contains the following properties:
795 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400796 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
797 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100798 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400799 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100800 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
801 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
802 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
803 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
804 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
805 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
806 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
807 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
808 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
809 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100810 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
811 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
812 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100813 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000814 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700815 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400816 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
817 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
818 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400819 */
820 public static final String MIME_TYPE_PROVISIONING_NFC
821 = "application/com.android.managedprovisioning";
822
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100823 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 * Activity action: ask the user to add a new device administrator to the system.
825 * The desired policy is the ComponentName of the policy in the
826 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
827 * bring the user through adding the device administrator to the system (or
828 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700829 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800830 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
831 * field to provide the user with additional explanation (in addition
832 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800833 *
834 * <p>If your administrator is already active, this will ordinarily return immediately (without
835 * user intervention). However, if your administrator has been updated and is requesting
836 * additional uses-policy flags, the user will be presented with the new list. New policies
837 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800838 */
839 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
840 public static final String ACTION_ADD_DEVICE_ADMIN
841 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700842
Dianne Hackbornd6847842010-01-12 18:14:19 -0800843 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700844 * @hide
845 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700846 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700847 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700848 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
849 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700850 * to remotely control restrictions on the user.
851 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800852 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700853 * result of whether or not the user approved the action. If approved, the result will
854 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
855 * as a profile owner.
856 *
857 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
858 * field to provide the user with additional explanation (in addition
859 * to your component's description) about what is being added.
860 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700861 * <p>If there is already a profile owner active or the caller is not a system app, the
862 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700863 */
864 @SystemApi
865 public static final String ACTION_SET_PROFILE_OWNER
866 = "android.app.action.SET_PROFILE_OWNER";
867
868 /**
869 * @hide
870 * Name of the profile owner admin that controls the user.
871 */
872 @SystemApi
873 public static final String EXTRA_PROFILE_OWNER_NAME
874 = "android.app.extra.PROFILE_OWNER_NAME";
875
876 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100877 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700878 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700879 *
Jim Miller284b62e2010-06-08 14:27:42 -0700880 * @hide
881 */
882 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
883 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
884
885 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100886 * Broadcast action: sent when the device owner is set or changed.
887 *
888 * This broadcast is sent only to the primary user.
889 * @see #ACTION_PROVISION_MANAGED_DEVICE
890 */
891 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
892 public static final String ACTION_DEVICE_OWNER_CHANGED
893 = "android.app.action.DEVICE_OWNER_CHANGED";
894
895 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800896 * The ComponentName of the administrator component.
897 *
898 * @see #ACTION_ADD_DEVICE_ADMIN
899 */
900 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700901
Dianne Hackbornd6847842010-01-12 18:14:19 -0800902 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800903 * An optional CharSequence providing additional explanation for why the
904 * admin is being added.
905 *
906 * @see #ACTION_ADD_DEVICE_ADMIN
907 */
908 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700909
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800910 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700911 * Activity action: have the user enter a new password. This activity should
912 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
913 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
914 * enter a new password that meets the current requirements. You can use
915 * {@link #isActivePasswordSufficient()} to determine whether you need to
916 * have the user select a new password in order to meet the current
917 * constraints. Upon being resumed from this activity, you can check the new
918 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000919 *
920 * If the intent is launched from within a managed profile with a profile
921 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
922 * this will trigger entering a new password for the parent of the profile.
923 * For all other cases it will trigger entering a new password for the user
924 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000925 *
926 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800927 */
928 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
929 public static final String ACTION_SET_NEW_PASSWORD
930 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700931
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000932 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000933 * Activity action: have the user enter a new password for the parent profile.
934 * If the intent is launched from within a managed profile, this will trigger
935 * entering a new password for the parent of the profile. In all other cases
936 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
937 */
938 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
939 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
940 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
941
942 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000943 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
944 * the parent profile to access intents sent from the managed profile.
945 * That is, when an app in the managed profile calls
946 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
947 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000948 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100949 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000950
951 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000952 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
953 * the managed profile to access intents sent from the parent profile.
954 * That is, when an app in the parent profile calls
955 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
956 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000957 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100958 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700959
Dianne Hackbornd6847842010-01-12 18:14:19 -0800960 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100961 * Broadcast action: notify that a new local system update policy has been set by the device
962 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000963 */
964 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100965 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
966 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000967
Amith Yamasanid49489b2015-04-28 14:00:26 -0700968 /**
969 * Permission policy to prompt user for new permission requests for runtime permissions.
970 * Already granted or denied permissions are not affected by this.
971 */
972 public static final int PERMISSION_POLICY_PROMPT = 0;
973
974 /**
975 * Permission policy to always grant new permission requests for runtime permissions.
976 * Already granted or denied permissions are not affected by this.
977 */
978 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
979
980 /**
981 * Permission policy to always deny new permission requests for runtime permissions.
982 * Already granted or denied permissions are not affected by this.
983 */
984 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
985
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700986 /**
987 * Runtime permission state: The user can manage the permission
988 * through the UI.
989 */
990 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
991
992 /**
993 * Runtime permission state: The permission is granted to the app
994 * and the user cannot manage the permission through the UI.
995 */
996 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
997
998 /**
999 * Runtime permission state: The permission is denied to the app
1000 * and the user cannot manage the permission through the UI.
1001 */
1002 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001003
1004 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001005 * No management for current user in-effect. This is the default.
1006 * @hide
1007 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001008 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001009 public static final int STATE_USER_UNMANAGED = 0;
1010
1011 /**
1012 * Management partially setup, user setup needs to be completed.
1013 * @hide
1014 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001015 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001016 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1017
1018 /**
1019 * Management partially setup, user setup completed.
1020 * @hide
1021 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001022 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001023 public static final int STATE_USER_SETUP_COMPLETE = 2;
1024
1025 /**
1026 * Management setup and active on current user.
1027 * @hide
1028 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001029 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001030 public static final int STATE_USER_SETUP_FINALIZED = 3;
1031
1032 /**
1033 * Management partially setup on a managed profile.
1034 * @hide
1035 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001036 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001037 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1038
1039 /**
1040 * @hide
1041 */
1042 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1043 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1044 @Retention(RetentionPolicy.SOURCE)
1045 public @interface UserProvisioningState {}
1046
1047 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001048 * Return true if the given administrator component is currently active (enabled) in the system.
1049 *
1050 * @param admin The administrator component to check for.
1051 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1052 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001053 */
Robin Lee25e26452015-06-02 09:56:29 -07001054 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001055 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001056 }
1057
1058 /**
1059 * @see #isAdminActive(ComponentName)
1060 * @hide
1061 */
Robin Lee25e26452015-06-02 09:56:29 -07001062 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001063 if (mService != null) {
1064 try {
Robin Lee25e26452015-06-02 09:56:29 -07001065 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001066 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001067 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001068 }
1069 }
1070 return false;
1071 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001072 /**
1073 * Return true if the given administrator component is currently being removed
1074 * for the user.
1075 * @hide
1076 */
Robin Lee25e26452015-06-02 09:56:29 -07001077 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001078 if (mService != null) {
1079 try {
Robin Lee25e26452015-06-02 09:56:29 -07001080 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001082 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001083 }
1084 }
1085 return false;
1086 }
1087
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001088
Dianne Hackbornd6847842010-01-12 18:14:19 -08001089 /**
Robin Lee25e26452015-06-02 09:56:29 -07001090 * Return a list of all currently active device administrators' component
1091 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001092 * returned.
1093 */
1094 public List<ComponentName> getActiveAdmins() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001095 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001096 }
1097
1098 /**
1099 * @see #getActiveAdmins()
1100 * @hide
1101 */
1102 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001103 if (mService != null) {
1104 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001105 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001106 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001107 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001108 }
1109 }
1110 return null;
1111 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001112
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001113 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001114 * Used by package administration code to determine if a package can be stopped
1115 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001116 * @hide
1117 */
1118 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001119 return packageHasActiveAdmins(packageName, myUserId());
1120 }
1121
1122 /**
1123 * Used by package administration code to determine if a package can be stopped
1124 * or uninstalled.
1125 * @hide
1126 */
1127 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001128 if (mService != null) {
1129 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001130 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001131 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001132 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001133 }
1134 }
1135 return false;
1136 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001137
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001138 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001139 * Remove a current administration component. This can only be called
1140 * by the application that owns the administration component; if you
1141 * try to remove someone else's component, a security exception will be
1142 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001143 *
1144 * <p>Note that the operation is not synchronous and the admin might still be active (as
1145 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001146 *
1147 * @param admin The administration compononent to remove.
1148 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001149 */
Robin Lee25e26452015-06-02 09:56:29 -07001150 public void removeActiveAdmin(@NonNull ComponentName admin) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001151 if (mService != null) {
1152 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001153 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001154 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001155 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001156 }
1157 }
1158 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001159
Dianne Hackbornd6847842010-01-12 18:14:19 -08001160 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001161 * Returns true if an administrator has been granted a particular device policy. This can be
1162 * used to check whether the administrator was activated under an earlier set of policies, but
1163 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001164 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1166 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001167 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001168 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001169 */
Robin Lee25e26452015-06-02 09:56:29 -07001170 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001171 if (mService != null) {
1172 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001173 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001174 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001175 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001176 }
1177 }
1178 return false;
1179 }
1180
1181 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001182 * Returns true if the Profile Challenge is available to use for the given profile user.
1183 *
1184 * @hide
1185 */
1186 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1187 if (mService != null) {
1188 try {
1189 return mService.isSeparateProfileChallengeAllowed(userHandle);
1190 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001191 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001192 }
1193 }
1194 return false;
1195 }
1196
1197 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001198 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1199 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001200 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001201 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001202 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001203
Dianne Hackbornd6847842010-01-12 18:14:19 -08001204 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001205 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1206 * recognition technology. This implies technologies that can recognize the identity of
1207 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1208 * Note that quality constants are ordered so that higher values are more restrictive.
1209 */
1210 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1211
1212 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001213 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001214 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001215 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001216 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001217 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001218
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001219 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001220 * Constant for {@link #setPasswordQuality}: the user must have entered a
1221 * password containing at least numeric characters. Note that quality
1222 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001223 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001224 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001225
Dianne Hackbornd6847842010-01-12 18:14:19 -08001226 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001227 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001228 * password containing at least numeric characters with no repeating (4444)
1229 * or ordered (1234, 4321, 2468) sequences. Note that quality
1230 * constants are ordered so that higher values are more restrictive.
1231 */
1232 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1233
1234 /**
1235 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001236 * password containing at least alphabetic (or other symbol) characters.
1237 * Note that quality constants are ordered so that higher values are more
1238 * restrictive.
1239 */
1240 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001241
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001242 /**
1243 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001244 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001245 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001246 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001247 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001248 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001249
Dianne Hackbornd6847842010-01-12 18:14:19 -08001250 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001251 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001252 * password containing at least a letter, a numerical digit and a special
1253 * symbol, by default. With this password quality, passwords can be
1254 * restricted to contain various sets of characters, like at least an
1255 * uppercase letter, etc. These are specified using various methods,
1256 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1257 * that quality constants are ordered so that higher values are more
1258 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001259 */
1260 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1261
1262 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001263 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1264 * modify password. In case this password quality is set, the password is
1265 * managed by a profile owner. The profile owner can set any password,
1266 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1267 * that quality constants are ordered so that higher values are more
1268 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1269 * the highest.
1270 * @hide
1271 */
1272 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1273
1274 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001275 * Called by an application that is administering the device to set the password restrictions it
1276 * is imposing. After setting this, the user will not be able to enter a new password that is
1277 * not at least as restrictive as what has been set. Note that the current password will remain
1278 * until the user has set a new one, so the change does not take place immediately. To prompt
1279 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001280 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001281 * <p>
1282 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1283 * requested quality constant (between the policy set here, the user's preference, and any other
1284 * considerations) is the one that is in effect.
1285 * <p>
1286 * The calling device admin must have requested
1287 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1288 * not, a security exception will be thrown.
1289 * <p>
1290 * This method can be called on the {@link DevicePolicyManager} instance returned by
1291 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1292 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001293 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001294 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001295 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1296 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1297 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1298 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1299 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1300 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001301 */
Robin Lee25e26452015-06-02 09:56:29 -07001302 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001303 if (mService != null) {
1304 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001305 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001306 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001307 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001308 }
1309 }
1310 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001311
Dianne Hackbornd6847842010-01-12 18:14:19 -08001312 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001313 * Retrieve the current minimum password quality for a particular admin or all admins that set
1314 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1315 * a separate challenge are not taken into account.
1316 *
1317 * <p>This method can be called on the {@link DevicePolicyManager} instance
1318 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1319 * restrictions on the parent profile.
1320 *
Robin Lee25e26452015-06-02 09:56:29 -07001321 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001322 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001323 */
Robin Lee25e26452015-06-02 09:56:29 -07001324 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001325 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001326 }
1327
1328 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001329 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001330 if (mService != null) {
1331 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001332 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001333 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001334 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001335 }
1336 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001337 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001338 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001339
Dianne Hackbornd6847842010-01-12 18:14:19 -08001340 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001341 * Called by an application that is administering the device to set the minimum allowed password
1342 * length. After setting this, the user will not be able to enter a new password that is not at
1343 * least as restrictive as what has been set. Note that the current password will remain until
1344 * the user has set a new one, so the change does not take place immediately. To prompt the user
1345 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1346 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1347 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1348 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1349 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1350 * {@link #setPasswordQuality}.
1351 * <p>
1352 * The calling device admin must have requested
1353 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1354 * not, a security exception will be thrown.
1355 * <p>
1356 * This method can be called on the {@link DevicePolicyManager} instance returned by
1357 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1358 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001359 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001360 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001361 * @param length The new desired minimum password length. A value of 0 means there is no
1362 * restriction.
1363 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1364 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001365 */
Robin Lee25e26452015-06-02 09:56:29 -07001366 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001367 if (mService != null) {
1368 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001369 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001370 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001371 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001372 }
1373 }
1374 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001375
Dianne Hackbornd6847842010-01-12 18:14:19 -08001376 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001377 * Retrieve the current minimum password length for a particular admin or all admins that set
1378 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1379 * a separate challenge are not taken into account.
1380 *
1381 * <p>This method can be called on the {@link DevicePolicyManager} instance
1382 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1383 * restrictions on the parent profile.
1384 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001385 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001386 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001387 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001388 */
Robin Lee25e26452015-06-02 09:56:29 -07001389 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001390 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001391 }
1392
1393 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001394 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001395 if (mService != null) {
1396 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001397 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001398 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001399 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001400 }
1401 }
1402 return 0;
1403 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001404
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001405 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001406 * Called by an application that is administering the device to set the minimum number of upper
1407 * case letters required in the password. After setting this, the user will not be able to enter
1408 * a new password that is not at least as restrictive as what has been set. Note that the
1409 * current password will remain until the user has set a new one, so the change does not take
1410 * place immediately. To prompt the user for a new password, use
1411 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1412 * setting this value. This constraint is only imposed if the administrator has also requested
1413 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001414 * <p>
1415 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001416 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1417 * not, a security exception will be thrown.
1418 * <p>
1419 * This method can be called on the {@link DevicePolicyManager} instance returned by
1420 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1421 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001422 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001423 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1424 * @param length The new desired minimum number of upper case letters required in the password.
1425 * A value of 0 means there is no restriction.
1426 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1427 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001428 */
Robin Lee25e26452015-06-02 09:56:29 -07001429 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001430 if (mService != null) {
1431 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001432 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001433 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001434 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001435 }
1436 }
1437 }
1438
1439 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001440 * Retrieve the current number of upper case letters required in the password
1441 * for a particular admin or all admins that set retrictions on this user and
1442 * its participating profiles. Restrictions on profiles that have a separate challenge
1443 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001444 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001445 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001446 * and only applies when the password quality is
1447 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001448 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001449 * <p>This method can be called on the {@link DevicePolicyManager} instance
1450 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1451 * restrictions on the parent profile.
1452 *
Robin Lee25e26452015-06-02 09:56:29 -07001453 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001454 * aggregate all admins.
1455 * @return The minimum number of upper case letters required in the
1456 * password.
1457 */
Robin Lee25e26452015-06-02 09:56:29 -07001458 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001459 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001460 }
1461
1462 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001463 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001464 if (mService != null) {
1465 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001466 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001467 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001468 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001469 }
1470 }
1471 return 0;
1472 }
1473
1474 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001475 * Called by an application that is administering the device to set the minimum number of lower
1476 * case letters required in the password. After setting this, the user will not be able to enter
1477 * a new password that is not at least as restrictive as what has been set. Note that the
1478 * current password will remain until the user has set a new one, so the change does not take
1479 * place immediately. To prompt the user for a new password, use
1480 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1481 * setting this value. This constraint is only imposed if the administrator has also requested
1482 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001483 * <p>
1484 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001485 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1486 * not, a security exception will be thrown.
1487 * <p>
1488 * This method can be called on the {@link DevicePolicyManager} instance returned by
1489 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1490 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001491 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1493 * @param length The new desired minimum number of lower case letters required in the password.
1494 * A value of 0 means there is no restriction.
1495 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1496 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001497 */
Robin Lee25e26452015-06-02 09:56:29 -07001498 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001499 if (mService != null) {
1500 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001501 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001503 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001504 }
1505 }
1506 }
1507
1508 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001509 * Retrieve the current number of lower case letters required in the password
1510 * for a particular admin or all admins that set retrictions on this user
1511 * and its participating profiles. Restrictions on profiles that have
1512 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001513 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001514 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001515 * and only applies when the password quality is
1516 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001517 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001518 * <p>This method can be called on the {@link DevicePolicyManager} instance
1519 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1520 * restrictions on the parent profile.
1521 *
Robin Lee25e26452015-06-02 09:56:29 -07001522 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001523 * aggregate all admins.
1524 * @return The minimum number of lower case letters required in the
1525 * password.
1526 */
Robin Lee25e26452015-06-02 09:56:29 -07001527 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001528 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001529 }
1530
1531 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001532 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001533 if (mService != null) {
1534 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001535 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001536 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001537 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001538 }
1539 }
1540 return 0;
1541 }
1542
1543 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001544 * Called by an application that is administering the device to set the minimum number of
1545 * letters required in the password. After setting this, the user will not be able to enter a
1546 * new password that is not at least as restrictive as what has been set. Note that the current
1547 * password will remain until the user has set a new one, so the change does not take place
1548 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1549 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1550 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1551 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001552 * <p>
1553 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001554 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1555 * not, a security exception will be thrown.
1556 * <p>
1557 * This method can be called on the {@link DevicePolicyManager} instance returned by
1558 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1559 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001560 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001561 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1562 * @param length The new desired minimum number of letters required in the password. A value of
1563 * 0 means there is no restriction.
1564 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1565 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001566 */
Robin Lee25e26452015-06-02 09:56:29 -07001567 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001568 if (mService != null) {
1569 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001570 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001572 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001573 }
1574 }
1575 }
1576
1577 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001578 * Retrieve the current number of letters required in the password
1579 * for a particular admin or all admins that set retrictions on this user
1580 * and its participating profiles. Restrictions on profiles that have
1581 * a separate challenge are not taken into account.
1582 * This is the same value as set by
1583 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001584 * and only applies when the password quality is
1585 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001586 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001587 * <p>This method can be called on the {@link DevicePolicyManager} instance
1588 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1589 * restrictions on the parent profile.
1590 *
Robin Lee25e26452015-06-02 09:56:29 -07001591 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001592 * aggregate all admins.
1593 * @return The minimum number of letters required in the password.
1594 */
Robin Lee25e26452015-06-02 09:56:29 -07001595 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001596 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001597 }
1598
1599 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001600 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001601 if (mService != null) {
1602 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001603 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001604 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001605 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001606 }
1607 }
1608 return 0;
1609 }
1610
1611 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001612 * Called by an application that is administering the device to set the minimum number of
1613 * numerical digits required in the password. After setting this, the user will not be able to
1614 * enter a new password that is not at least as restrictive as what has been set. Note that the
1615 * current password will remain until the user has set a new one, so the change does not take
1616 * place immediately. To prompt the user for a new password, use
1617 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1618 * setting this value. This constraint is only imposed if the administrator has also requested
1619 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001620 * <p>
1621 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001622 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1623 * not, a security exception will be thrown.
1624 * <p>
1625 * This method can be called on the {@link DevicePolicyManager} instance returned by
1626 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1627 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001628 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001629 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1630 * @param length The new desired minimum number of numerical digits required in the password. A
1631 * value of 0 means there is no restriction.
1632 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1633 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001634 */
Robin Lee25e26452015-06-02 09:56:29 -07001635 public void setPasswordMinimumNumeric(@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.setPasswordMinimumNumeric(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 /**
1646 * Retrieve the current number of numerical digits required in the password
Esteban Talaverac1c83592016-02-17 17:56:15 +00001647 * 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.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001650 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001651 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001652 * and only applies when the password quality is
1653 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001654 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001655 * <p>This method can be called on the {@link DevicePolicyManager} instance
1656 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1657 * restrictions on the parent profile.
1658 *
Robin Lee25e26452015-06-02 09:56:29 -07001659 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001660 * aggregate all admins.
1661 * @return The minimum number of numerical digits required in the password.
1662 */
Robin Lee25e26452015-06-02 09:56:29 -07001663 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001664 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001665 }
1666
1667 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001668 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001669 if (mService != null) {
1670 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001671 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001672 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001673 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001674 }
1675 }
1676 return 0;
1677 }
1678
1679 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001680 * Called by an application that is administering the device to set the minimum number of
1681 * symbols required in the password. After setting this, the user will not be able to enter a
1682 * new password that is not at least as restrictive as what has been set. Note that the current
1683 * password will remain until the user has set a new one, so the change does not take place
1684 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1685 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1686 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1687 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001688 * <p>
1689 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001690 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1691 * not, a security exception will be thrown.
1692 * <p>
1693 * This method can be called on the {@link DevicePolicyManager} instance returned by
1694 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1695 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001696 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001697 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1698 * @param length The new desired minimum number of symbols required in the password. A value of
1699 * 0 means there is no restriction.
1700 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1701 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001702 */
Robin Lee25e26452015-06-02 09:56:29 -07001703 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001704 if (mService != null) {
1705 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001706 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001707 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001708 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001709 }
1710 }
1711 }
1712
1713 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001714 * Retrieve the current number of symbols required in the password
1715 * for a particular admin or all admins that set retrictions on this user
1716 * and its participating profiles. Restrictions on profiles that have
1717 * a separate challenge are not taken into account. This is the same value as
1718 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001719 * and only applies when the password quality is
1720 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001721 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001722 * <p>This method can be called on the {@link DevicePolicyManager} instance
1723 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1724 * restrictions on the parent profile.
1725 *
Robin Lee25e26452015-06-02 09:56:29 -07001726 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001727 * aggregate all admins.
1728 * @return The minimum number of symbols required in the password.
1729 */
Robin Lee25e26452015-06-02 09:56:29 -07001730 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001731 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001732 }
1733
1734 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001735 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001736 if (mService != null) {
1737 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001738 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001739 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001740 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001741 }
1742 }
1743 return 0;
1744 }
1745
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001746 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001747 * Called by an application that is administering the device to set the minimum number of
1748 * non-letter characters (numerical digits or symbols) required in the password. After setting
1749 * this, the user will not be able to enter a new password that is not at least as restrictive
1750 * as what has been set. Note that the current password will remain until the user has set a new
1751 * one, so the change does not take place immediately. To prompt the user for a new password,
1752 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1753 * setting this value. This constraint is only imposed if the administrator has also requested
1754 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001755 * <p>
1756 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001757 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1758 * not, a security exception will be thrown.
1759 * <p>
1760 * This method can be called on the {@link DevicePolicyManager} instance returned by
1761 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1762 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001763 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001764 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1765 * @param length The new desired minimum number of letters required in the password. A value of
1766 * 0 means there is no restriction.
1767 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1768 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001769 */
Robin Lee25e26452015-06-02 09:56:29 -07001770 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001771 if (mService != null) {
1772 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001773 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001774 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001775 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001776 }
1777 }
1778 }
1779
1780 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001781 * Retrieve the current number of non-letter characters required in the password
1782 * for a particular admin or all admins that set retrictions on this user
1783 * and its participating profiles. Restrictions on profiles that have
1784 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001785 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001786 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001787 * and only applies when the password quality is
1788 * {@link #PASSWORD_QUALITY_COMPLEX}.
1789 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001790 * <p>This method can be called on the {@link DevicePolicyManager} instance
1791 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1792 * restrictions on the parent profile.
1793 *
Robin Lee25e26452015-06-02 09:56:29 -07001794 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001795 * aggregate all admins.
1796 * @return The minimum number of letters required in the password.
1797 */
Robin Lee25e26452015-06-02 09:56:29 -07001798 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001799 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001800 }
1801
1802 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001803 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001804 if (mService != null) {
1805 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001806 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001807 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001808 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001809 }
1810 }
1811 return 0;
1812 }
1813
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001814 /**
1815 * Called by an application that is administering the device to set the length of the password
1816 * history. After setting this, the user will not be able to enter a new password that is the
1817 * same as any password in the history. Note that the current password will remain until the
1818 * user has set a new one, so the change does not take place immediately. To prompt the user for
1819 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1820 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1821 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1822 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1823 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1824 * <p>
1825 * The calling device admin must have requested
1826 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1827 * not, a security exception will be thrown.
1828 * <p>
1829 * This method can be called on the {@link DevicePolicyManager} instance returned by
1830 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1831 * profile.
1832 *
1833 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1834 * @param length The new desired length of password history. A value of 0 means there is no
1835 * restriction.
1836 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1837 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1838 */
Robin Lee25e26452015-06-02 09:56:29 -07001839 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001840 if (mService != null) {
1841 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001842 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001843 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001844 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001845 }
1846 }
1847 }
1848
1849 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001850 * Called by a device admin to set the password expiration timeout. Calling this method will
1851 * restart the countdown for password expiration for the given admin, as will changing the
1852 * device password (for all admins).
1853 * <p>
1854 * The provided timeout is the time delta in ms and will be added to the current time. For
1855 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1856 * 432000000 ms for timeout.
1857 * <p>
1858 * To disable password expiration, a value of 0 may be used for timeout.
1859 * <p>
1860 * The calling device admin must have requested
1861 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1862 * not, a security exception will be thrown.
1863 * <p>
1864 * Note that setting the password will automatically reset the expiration time for all active
1865 * admins. Active admins do not need to explicitly call this method in that case.
1866 * <p>
1867 * This method can be called on the {@link DevicePolicyManager} instance returned by
1868 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1869 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001870 *
Jim Millera4e28d12010-11-08 16:15:47 -08001871 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001872 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1873 * there is no restriction (unlimited).
1874 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1875 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001876 */
Robin Lee25e26452015-06-02 09:56:29 -07001877 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001878 if (mService != null) {
1879 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001880 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001881 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001882 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001883 }
1884 }
1885 }
1886
1887 /**
Jim Miller6b857682011-02-16 16:27:41 -08001888 * Get the password expiration timeout for the given admin. The expiration timeout is the
1889 * recurring expiration timeout provided in the call to
1890 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001891 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1892 * have set restrictions on profiles that have a separate challenge are not taken into account.
1893 *
1894 * <p>This method can be called on the {@link DevicePolicyManager} instance
1895 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1896 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001897 *
Robin Lee25e26452015-06-02 09:56:29 -07001898 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001899 * @return The timeout for the given admin or the minimum of all timeouts
1900 */
Robin Lee25e26452015-06-02 09:56:29 -07001901 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001902 if (mService != null) {
1903 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001904 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001905 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001906 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001907 }
1908 }
1909 return 0;
1910 }
1911
1912 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001913 * Get the current password expiration time for a particular admin or all admins that set
1914 * retrictions on this user and its participating profiles. Restrictions on profiles that have
1915 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1916 * of all expiration times is returned - which will be the minimum of all of them.
1917 *
1918 * <p>This method can be called on the {@link DevicePolicyManager} instance
1919 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1920 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001921 *
Robin Lee25e26452015-06-02 09:56:29 -07001922 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001923 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001924 */
Robin Lee25e26452015-06-02 09:56:29 -07001925 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001926 if (mService != null) {
1927 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001928 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001929 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001930 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001931 }
1932 }
1933 return 0;
1934 }
1935
1936 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001937 * Retrieve the current password history length for a particular admin or all admins that
1938 * set retrictions on this user and its participating profiles. Restrictions on profiles that
1939 * have a separate challenge are not taken into account.
1940 *
1941 * <p>This method can be called on the {@link DevicePolicyManager} instance
1942 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1943 * restrictions on the parent profile.
1944 *
Robin Lee25e26452015-06-02 09:56:29 -07001945 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001946 * all admins.
1947 * @return The length of the password history
1948 */
Robin Lee25e26452015-06-02 09:56:29 -07001949 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001950 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001951 }
1952
1953 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001954 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001955 if (mService != null) {
1956 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001957 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001959 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001960 }
1961 }
1962 return 0;
1963 }
1964
Dianne Hackbornd6847842010-01-12 18:14:19 -08001965 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001966 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001967 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08001968 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08001969 * @return Returns the maximum length that the user can enter.
1970 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001971 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08001972 // Kind-of arbitrary.
1973 return 16;
1974 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001975
Dianne Hackborn254cb442010-01-27 19:23:59 -08001976 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001977 * Determine whether the current password the user has set is sufficient to meet the policy
1978 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
1979 * user and its participating profiles. Restrictions on profiles that have a separate challenge
1980 * are not taken into account.
1981 * <p>
1982 * The calling device admin must have requested
1983 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1984 * not, a security exception will be thrown.
1985 * <p>
1986 * This method can be called on the {@link DevicePolicyManager} instance returned by
1987 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
1988 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001989 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001990 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001991 * @throws SecurityException if the calling application does not own an active administrator
1992 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001993 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001994 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001995 if (mService != null) {
1996 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001997 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001998 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001999 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002000 }
2001 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002002 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002003 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002004
Dianne Hackbornd6847842010-01-12 18:14:19 -08002005 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002006 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002007 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002008 * requested by the admins of the parent user and its profiles.
2009 *
2010 * @param userHandle the userId of the profile to check the password for.
2011 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002012 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002013 * @hide
2014 */
2015 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2016 if (mService != null) {
2017 try {
2018 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2019 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002020 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002021 }
2022 }
2023 return false;
2024 }
2025
2026 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002027 * Retrieve the number of times the user has failed at entering a password since that last
2028 * successful password entry.
2029 * <p>
2030 * This method can be called on the {@link DevicePolicyManager} instance returned by
2031 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2032 * password attemts for the parent user.
2033 * <p>
2034 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2035 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002036 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002037 * @return The number of times user has entered an incorrect password since the last correct
2038 * password entry.
2039 * @throws SecurityException if the calling application does not own an active administrator
2040 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002041 */
2042 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002043 return getCurrentFailedPasswordAttempts(myUserId());
2044 }
2045
2046 /**
2047 * Retrieve the number of times the given user has failed at entering a
2048 * password since that last successful password entry.
2049 *
2050 * <p>The calling device admin must have requested
2051 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2052 * not and it is not the system uid, a security exception will be thrown.
2053 *
2054 * @hide
2055 */
2056 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002057 if (mService != null) {
2058 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002059 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002060 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002061 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002062 }
2063 }
2064 return -1;
2065 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002066
2067 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002068 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002069 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002070 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002071 * @hide
2072 */
2073 public boolean getDoNotAskCredentialsOnBoot() {
2074 if (mService != null) {
2075 try {
2076 return mService.getDoNotAskCredentialsOnBoot();
2077 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002078 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002079 }
2080 }
2081 return false;
2082 }
2083
2084 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002085 * Setting this to a value greater than zero enables a built-in policy that will perform a
2086 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2087 * This built-in policy combines watching for failed passwords and wiping the device, and
2088 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002089 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002090 * <p>
2091 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2092 * revoking credentials, or reporting the failure to a server), you should implement
2093 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2094 * use this API, because if the maximum count is reached, the device or profile will be wiped
2095 * immediately, and your callback will not be invoked.
2096 * <p>
2097 * This method can be called on the {@link DevicePolicyManager} instance returned by
2098 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2099 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002100 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002101 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002102 * @param num The number of failed password attempts at which point the device or profile will
2103 * be wiped.
2104 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2105 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2106 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002107 */
Robin Lee25e26452015-06-02 09:56:29 -07002108 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002109 if (mService != null) {
2110 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002111 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002112 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002113 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002114 }
2115 }
2116 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002117
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002118 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002119 * Retrieve the current maximum number of login attempts that are allowed before the device
2120 * or profile is wiped, for a particular admin or all admins that set retrictions on this user
2121 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2122 * not taken into account.
2123 *
2124 * <p>This method can be called on the {@link DevicePolicyManager} instance
2125 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2126 * the value for the parent profile.
2127 *
Robin Lee25e26452015-06-02 09:56:29 -07002128 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002129 * all admins.
2130 */
Robin Lee25e26452015-06-02 09:56:29 -07002131 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002132 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002133 }
2134
2135 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002136 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002137 if (mService != null) {
2138 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002139 return mService.getMaximumFailedPasswordsForWipe(
2140 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002141 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002142 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002143 }
2144 }
2145 return 0;
2146 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002147
Dianne Hackborn254cb442010-01-27 19:23:59 -08002148 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002149 * Returns the profile with the smallest maximum failed passwords for wipe,
2150 * for the given user. So for primary user, it might return the primary or
2151 * a managed profile. For a secondary user, it would be the same as the
2152 * user passed in.
2153 * @hide Used only by Keyguard
2154 */
2155 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2156 if (mService != null) {
2157 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002158 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2159 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002160 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002161 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002162 }
2163 }
2164 return UserHandle.USER_NULL;
2165 }
2166
2167 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002168 * Flag for {@link #resetPassword}: don't allow other admins to change
2169 * the password again until the user has entered it.
2170 */
2171 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002172
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002173 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002174 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2175 * If the flag is set, the device can be booted without asking for user password.
2176 * The absence of this flag does not change the current boot requirements. This flag
2177 * can be set by the device owner only. If the app is not the device owner, the flag
2178 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2179 * device to factory defaults.
2180 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002181 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002182
2183 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002184 * Force a new device unlock password (the password needed to access the entire device, not for
2185 * individual accounts) on the user. This takes effect immediately.
2186 * <p>
2187 * Calling this from a managed profile that shares the password with the owner profile will
2188 * throw a security exception.
2189 * <p>
2190 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002191 * device admins that are not device owner and not profile owner.
2192 * The password can now only be changed if there is currently no password set. Device owner
2193 * and profile owner can still do this.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002194 * <p>
2195 * The given password must be sufficient for the current password quality and length constraints
2196 * as returned by {@link #getPasswordQuality(ComponentName)} and
2197 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2198 * it will be rejected and false returned. Note that the password may be a stronger quality
2199 * (containing alphanumeric characters when the requested quality is only numeric), in which
2200 * case the currently active quality will be increased to match.
2201 * <p>
2202 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
2203 * current password constraints allow it. <em>Note: This will not
Makoto Onuki70f929e2015-11-11 12:40:15 -08002204 * work in {@link android.os.Build.VERSION_CODES#N} and later for device admins that are not
2205 * device owner and not profile owner. Once set, the password cannot be changed to null or
2206 * empty, except by device owner or profile owner.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002207 * <p>
2208 * The calling device admin must have requested
2209 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2210 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002211 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002212 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002213 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002214 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2215 * @return Returns true if the password was applied, or false if it is not acceptable for the
2216 * current constraints or if the user has not been decrypted yet.
2217 * @throws SecurityException if the calling application does not own an active administrator
2218 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002219 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002220 public boolean resetPassword(String password, int flags) {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002221 if (mParentInstance) {
2222 throw new SecurityException("Reset password does not work across profiles.");
2223 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002224 if (mService != null) {
2225 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002226 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002227 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002228 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002229 }
2230 }
2231 return false;
2232 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002233
Dianne Hackbornd6847842010-01-12 18:14:19 -08002234 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002235 * Called by an application that is administering the device to set the maximum time for user
2236 * activity until the device will lock. This limits the length that the user can set. It takes
2237 * effect immediately.
2238 * <p>
2239 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2240 * to be able to call this method; if it has not, a security exception will be thrown.
2241 * <p>
2242 * This method can be called on the {@link DevicePolicyManager} instance returned by
2243 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2244 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002245 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002247 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2248 * is no restriction.
2249 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2250 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002251 */
Robin Lee25e26452015-06-02 09:56:29 -07002252 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002253 if (mService != null) {
2254 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002255 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002257 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002258 }
2259 }
2260 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002261
Dianne Hackbornd6847842010-01-12 18:14:19 -08002262 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002263 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
2264 * retrictions on this user and its participating profiles. Restrictions on profiles that have
2265 * a separate challenge are not taken into account.
2266 *
2267 * <p>This method can be called on the {@link DevicePolicyManager} instance
2268 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2269 * restrictions on the parent profile.
2270 *
Robin Lee25e26452015-06-02 09:56:29 -07002271 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002272 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002273 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002274 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002275 */
Robin Lee25e26452015-06-02 09:56:29 -07002276 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002277 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002278 }
2279
2280 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002281 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002282 if (mService != null) {
2283 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002284 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002285 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002286 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002287 }
2288 }
2289 return 0;
2290 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002291
Dianne Hackbornd6847842010-01-12 18:14:19 -08002292 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002293 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2294 * this call.
2295 * <p>
2296 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2297 * to be able to call this method; if it has not, a security exception will be thrown.
2298 * <p>
2299 * This method can be called on the {@link DevicePolicyManager} instance returned by
2300 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002301 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002302 * @throws SecurityException if the calling application does not own an active administrator
2303 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002304 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002305 public void lockNow() {
2306 if (mService != null) {
2307 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002308 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002309 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002310 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002311 }
2312 }
2313 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002314
Dianne Hackbornd6847842010-01-12 18:14:19 -08002315 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002316 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002317 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002318 */
2319 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2320
2321 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002322 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2323 * data.
2324 *
Paul Crowley2934b262014-12-02 11:21:13 +00002325 * <p>This flag may only be set by device owner admins; if it is set by
2326 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002327 */
2328 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2329
2330 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002331 * Ask the user data be wiped. Wiping the primary user will cause the device to reboot, erasing
2332 * all user data while next booting up.
2333 * <p>
2334 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2335 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002336 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002337 * @param flags Bit mask of additional options: currently supported flags are
2338 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2339 * @throws SecurityException if the calling application does not own an active administrator
2340 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002341 */
2342 public void wipeData(int flags) {
2343 if (mService != null) {
2344 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002345 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002346 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002347 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002348 }
2349 }
2350 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002351
Dianne Hackbornd6847842010-01-12 18:14:19 -08002352 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002353 * Called by an application that is administering the device to set the
2354 * global proxy and exclusion list.
2355 * <p>
2356 * The calling device admin must have requested
2357 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2358 * this method; if it has not, a security exception will be thrown.
2359 * Only the first device admin can set the proxy. If a second admin attempts
2360 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002361 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002362 * be returned.
2363 * The method can be called repeatedly by the device admin alrady setting the
2364 * proxy to update the proxy and exclusion list.
2365 *
Robin Lee25e26452015-06-02 09:56:29 -07002366 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002367 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2368 * Pass Proxy.NO_PROXY to reset the proxy.
2369 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002370 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2371 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002372 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002373 */
Robin Lee25e26452015-06-02 09:56:29 -07002374 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002375 List<String> exclusionList ) {
2376 if (proxySpec == null) {
2377 throw new NullPointerException();
2378 }
2379 if (mService != null) {
2380 try {
2381 String hostSpec;
2382 String exclSpec;
2383 if (proxySpec.equals(Proxy.NO_PROXY)) {
2384 hostSpec = null;
2385 exclSpec = null;
2386 } else {
2387 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2388 throw new IllegalArgumentException();
2389 }
2390 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2391 String hostName = sa.getHostName();
2392 int port = sa.getPort();
2393 StringBuilder hostBuilder = new StringBuilder();
2394 hostSpec = hostBuilder.append(hostName)
2395 .append(":").append(Integer.toString(port)).toString();
2396 if (exclusionList == null) {
2397 exclSpec = "";
2398 } else {
2399 StringBuilder listBuilder = new StringBuilder();
2400 boolean firstDomain = true;
2401 for (String exclDomain : exclusionList) {
2402 if (!firstDomain) {
2403 listBuilder = listBuilder.append(",");
2404 } else {
2405 firstDomain = false;
2406 }
2407 listBuilder = listBuilder.append(exclDomain.trim());
2408 }
2409 exclSpec = listBuilder.toString();
2410 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002411 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2412 != android.net.Proxy.PROXY_VALID)
2413 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002414 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002415 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002416 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002417 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002418 }
2419 }
2420 return null;
2421 }
2422
2423 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002424 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2425 * HTTP proxies - they are generally network dependent. However if you're doing something
2426 * unusual like general internal filtering this may be useful. On a private network where the
2427 * proxy is not accessible, you may break HTTP using this.
2428 * <p>
2429 * This method requires the caller to be the device owner.
2430 * <p>
2431 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002432 *
Jason Monk03bc9912014-05-13 09:44:57 -04002433 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002434 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2435 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2436 * {@code null} value will clear the global HTTP proxy.
2437 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002438 */
Robin Lee25e26452015-06-02 09:56:29 -07002439 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2440 proxyInfo) {
Jason Monk03bc9912014-05-13 09:44:57 -04002441 if (mService != null) {
2442 try {
2443 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2444 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002445 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002446 }
2447 }
2448 }
2449
2450 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002451 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002452 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2453 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002454 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002455 */
2456 public ComponentName getGlobalProxyAdmin() {
2457 if (mService != null) {
2458 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002459 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002460 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002461 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002462 }
2463 }
2464 return null;
2465 }
2466
2467 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002468 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002469 * indicating that encryption is not supported.
2470 */
2471 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2472
2473 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002474 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002475 * indicating that encryption is supported, but is not currently active.
2476 */
2477 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2478
2479 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002480 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002481 * indicating that encryption is not currently active, but is currently
2482 * being activated. This is only reported by devices that support
2483 * encryption of data and only when the storage is currently
2484 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2485 * to become encrypted will never return this value.
2486 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002487 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002488
2489 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002490 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002491 * indicating that encryption is active.
2492 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002493 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002494
2495 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002496 * Result code for {@link #getStorageEncryptionStatus}:
2497 * indicating that encryption is active, but an encryption key has not
2498 * been set by the user.
2499 */
2500 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2501
2502 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002503 * Result code for {@link #getStorageEncryptionStatus}:
2504 * indicating that encryption is active and the encryption key is tied to the user.
2505 */
2506 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2507
2508 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002509 * Activity action: begin the process of encrypting data on the device. This activity should
2510 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2511 * After resuming from this activity, use {@link #getStorageEncryption}
2512 * to check encryption status. However, on some devices this activity may never return, as
2513 * it may trigger a reboot and in some cases a complete data wipe of the device.
2514 */
2515 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2516 public static final String ACTION_START_ENCRYPTION
2517 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002518 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002519 * Widgets are enabled in keyguard
2520 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002521 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002522
2523 /**
Jim Miller50e62182014-04-23 17:25:00 -07002524 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002525 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002526 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2527
2528 /**
2529 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2530 */
2531 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2532
2533 /**
Jim Miller50e62182014-04-23 17:25:00 -07002534 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2535 */
2536 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2537
2538 /**
2539 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2540 */
2541 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2542
2543 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002544 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002545 * (e.g. PIN/Pattern/Password).
2546 */
2547 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2548
2549 /**
Jim Miller06e34502014-07-17 14:46:05 -07002550 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2551 */
2552 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2553
2554 /**
Jim Miller35207742012-11-02 15:33:20 -07002555 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002556 */
2557 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002558
2559 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002560 * Called by an application that is administering the device to request that the storage system
2561 * be encrypted.
2562 * <p>
2563 * When multiple device administrators attempt to control device encryption, the most secure,
2564 * supported setting will always be used. If any device administrator requests device
2565 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2566 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002567 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002568 * <p>
2569 * This policy controls encryption of the secure (application data) storage area. Data written
2570 * to other storage areas may or may not be encrypted, and this policy does not require or
2571 * control the encryption of any other storage areas. There is one exception: If
2572 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2573 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2574 * written to disk within the encrypted storage area.
2575 * <p>
2576 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2577 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2578 * encryption key may not be fully secured. For maximum security, the administrator should also
2579 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002580 *
2581 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2582 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002583 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002584 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2585 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2586 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2587 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2588 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002589 */
Robin Lee25e26452015-06-02 09:56:29 -07002590 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002591 if (mService != null) {
2592 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002593 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002594 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002595 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002596 }
2597 }
2598 return ENCRYPTION_STATUS_UNSUPPORTED;
2599 }
2600
2601 /**
2602 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002603 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002604 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002605 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2606 * this will return the requested encryption setting as an aggregate of all active
2607 * administrators.
2608 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002609 */
Robin Lee25e26452015-06-02 09:56:29 -07002610 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002611 if (mService != null) {
2612 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002613 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002614 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002615 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002616 }
2617 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002618 return false;
2619 }
2620
2621 /**
2622 * Called by an application that is administering the device to
2623 * determine the current encryption status of the device.
2624 *
2625 * Depending on the returned status code, the caller may proceed in different
2626 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2627 * storage system does not support encryption. If the
2628 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2629 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002630 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2631 * storage system has enabled encryption but no password is set so further action
2632 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING} or
Andy Stadler22dbfda2011-01-17 12:47:31 -08002633 * {@link #ENCRYPTION_STATUS_ACTIVE}, no further action is required.
2634 *
Robin Lee7e678712014-07-24 16:41:31 +01002635 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002636 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002637 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
2638 * or {@link #ENCRYPTION_STATUS_ACTIVE}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002639 */
2640 public int getStorageEncryptionStatus() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002641 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002642 }
2643
2644 /** @hide per-user version */
2645 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002646 if (mService != null) {
2647 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002648 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002649 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002650 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002651 }
2652 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002653 return ENCRYPTION_STATUS_UNSUPPORTED;
2654 }
2655
2656 /**
Robin Lee7e678712014-07-24 16:41:31 +01002657 * Installs the given certificate as a user CA.
2658 *
Robin Lee25e26452015-06-02 09:56:29 -07002659 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2660 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002661 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002662 *
2663 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002664 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002665 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2666 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002667 */
Robin Lee25e26452015-06-02 09:56:29 -07002668 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002669 if (mService != null) {
2670 try {
Robin Lee7e678712014-07-24 16:41:31 +01002671 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002672 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002673 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002674 }
2675 }
2676 return false;
2677 }
2678
2679 /**
Robin Lee7e678712014-07-24 16:41:31 +01002680 * Uninstalls the given certificate from trusted user CAs, if present.
2681 *
Robin Lee25e26452015-06-02 09:56:29 -07002682 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2683 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002684 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002685 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2686 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002687 */
Robin Lee25e26452015-06-02 09:56:29 -07002688 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Maggie Benthallda51e682013-08-08 22:35:44 -04002689 if (mService != null) {
2690 try {
Robin Lee306fe082014-06-19 14:04:24 +00002691 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002692 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002693 } catch (CertificateException e) {
2694 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002695 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002696 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002697 }
2698 }
2699 }
2700
2701 /**
Robin Lee7e678712014-07-24 16:41:31 +01002702 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2703 * If a user has installed any certificates by other means than device policy these will be
2704 * included too.
2705 *
Robin Lee25e26452015-06-02 09:56:29 -07002706 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2707 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002708 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002709 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2710 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002711 */
Robin Lee25e26452015-06-02 09:56:29 -07002712 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002713 List<byte[]> certs = new ArrayList<byte[]>();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002714 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002715 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002716 mService.enforceCanManageCaCerts(admin);
2717 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2718 for (String alias : certStore.userAliases()) {
2719 try {
2720 certs.add(certStore.getCertificate(alias).getEncoded());
2721 } catch (CertificateException ce) {
2722 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2723 }
2724 }
2725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002726 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002727 }
2728 }
2729 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002730 }
2731
2732 /**
Robin Lee7e678712014-07-24 16:41:31 +01002733 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2734 * means other than device policy will also be removed, except for system CA certificates.
2735 *
Robin Lee25e26452015-06-02 09:56:29 -07002736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2737 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002738 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2739 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002740 */
Robin Lee25e26452015-06-02 09:56:29 -07002741 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002742 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002743 try {
2744 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2745 .toArray(new String[0]));
2746 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002747 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002748 }
2749 }
2750 }
2751
2752 /**
2753 * Returns whether this certificate is installed as a trusted CA.
2754 *
Robin Lee25e26452015-06-02 09:56:29 -07002755 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2756 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002757 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002758 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2759 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002760 */
Robin Lee25e26452015-06-02 09:56:29 -07002761 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002762 if (mService != null) {
2763 try {
2764 mService.enforceCanManageCaCerts(admin);
2765 return getCaCertAlias(certBuffer) != null;
2766 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002767 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002768 } catch (CertificateException ce) {
2769 Log.w(TAG, "Could not parse certificate", ce);
2770 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002771 }
2772 return false;
2773 }
2774
2775 /**
Robin Leece3399f2016-02-24 12:08:32 +00002776 * Called by a device or profile owner, or delegated certificate installer, to install a
2777 * certificate and corresponding private key. All apps within the profile will be able to access
2778 * the certificate and use the private key, given direct user approval.
2779 *
2780 * <p>Access to the installed credentials will not be granted to the caller of this API without
2781 * direct user approval. This is for security - should a certificate installer become
2782 * compromised, certificates it had already installed will be protected.
2783 *
2784 * <p>If the installer must have access to the credentials, call
2785 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate, String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002786 *
Robin Lee25e26452015-06-02 09:56:29 -07002787 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2788 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002789 * @param privKey The private key to install.
2790 * @param cert The certificate to install.
2791 * @param alias The private key alias under which to install the certificate. If a certificate
2792 * with that alias already exists, it will be overwritten.
2793 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002794 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2795 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002796 */
Robin Leefbc65642015-08-03 16:21:22 +01002797 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2798 @NonNull Certificate cert, @NonNull String alias) {
Robin Leece3399f2016-02-24 12:08:32 +00002799 return installKeyPair(admin, privKey, cert, alias, false);
2800 }
2801
2802 /**
2803 * Called by a device or profile owner, or delegated certificate installer, to install a
2804 * certificate and corresponding private key. All apps within the profile will be able to access
2805 * the certificate and use the private key, given direct user approval.
2806 *
Robin Leea1b290e2016-03-09 14:38:36 +00002807 * <p>The caller of this API may grant itself access to the certificate and private key
2808 * immediately, without user approval. It is a best practice not to request this unless strictly
2809 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00002810 *
2811 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002812 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00002813 * @param privKey The private key to install.
2814 * @param cert The certificate to install.
2815 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00002816 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00002817 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00002818 * credentials immediately. Otherwise, access to the credentials will be gated by user
2819 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00002820 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002821 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2822 * owner.
Robin Leece3399f2016-02-24 12:08:32 +00002823 */
2824 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2825 @NonNull Certificate cert, @NonNull String alias, boolean requestAccess) {
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002826 try {
2827 final byte[] pemCert = Credentials.convertToPem(cert);
Robin Lee0d5ccb72014-09-12 17:41:44 +01002828 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
2829 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Robin Leece3399f2016-02-24 12:08:32 +00002830 return mService.installKeyPair(admin, pkcs8Key, pemCert, alias, requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002831 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002832 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01002833 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
2834 Log.w(TAG, "Failed to obtain private key material", e);
2835 } catch (CertificateException | IOException e) {
2836 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002837 }
2838 return false;
2839 }
2840
2841 /**
Robin Leea1b290e2016-03-09 14:38:36 +00002842 * Called by a device or profile owner, or delegated certificate installer, to remove a
2843 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01002844 *
2845 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00002846 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01002847 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00002848 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002849 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2850 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01002851 */
2852 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
2853 try {
2854 return mService.removeKeyPair(admin, alias);
2855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002856 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01002857 }
Robin Leefbc65642015-08-03 16:21:22 +01002858 }
2859
2860 /**
Robin Lee25e26452015-06-02 09:56:29 -07002861 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00002862 * doesn't exist.
2863 */
2864 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
2865 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
2866 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
2867 new ByteArrayInputStream(certBuffer));
2868 return new TrustedCertificateStore().getCertificateAlias(cert);
2869 }
2870
2871 /**
Rubin Xuec32b562015-03-03 17:34:05 +00002872 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01002873 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00002874 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01002875 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00002876 * <p>
2877 * Delegated certificate installer is a per-user state. The delegated access is persistent until
2878 * it is later cleared by calling this method with a null value or uninstallling the certificate
2879 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002880 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00002881 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
2882 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002883 * supplied certificate installer package must be installed when calling this API, otherwise an
2884 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00002885 *
Robin Lee25e26452015-06-02 09:56:29 -07002886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00002887 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002888 * access. If {@code null} is given the current package will be cleared.
2889 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002890 */
Robin Lee25e26452015-06-02 09:56:29 -07002891 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
2892 installerPackage) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002893 if (mService != null) {
2894 try {
Robin Lee25e26452015-06-02 09:56:29 -07002895 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00002896 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002897 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002898 }
2899 }
2900 }
2901
2902 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002903 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
2904 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00002905 *
Robin Lee25e26452015-06-02 09:56:29 -07002906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002907 * @return The package name of the current delegated certificate installer, or {@code null} if
2908 * none is set.
2909 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00002910 */
Robin Lee25e26452015-06-02 09:56:29 -07002911 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Rubin Xuec32b562015-03-03 17:34:05 +00002912 if (mService != null) {
2913 try {
Robin Lee25e26452015-06-02 09:56:29 -07002914 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00002915 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002916 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00002917 }
2918 }
2919 return null;
2920 }
2921
2922 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00002923 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002924 * specific application for the current user. This connection is automatically granted and
2925 * persisted after a reboot.
2926 * <p>
2927 * The designated package should declare a {@link android.net.VpnService} in its manifest
2928 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
2929 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00002930 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002931 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
2932 * remove an existing always-on VPN configuration.
2933 * @return {@code true} if the package is set as always-on VPN controller; {@code false}
2934 * otherwise.
2935 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00002936 */
2937 public boolean setAlwaysOnVpnPackage(@NonNull ComponentName admin,
2938 @Nullable String vpnPackage) {
2939 if (mService != null) {
2940 try {
2941 return mService.setAlwaysOnVpnPackage(admin, vpnPackage);
2942 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002943 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002944 }
2945 }
2946 return false;
2947 }
2948
2949 /**
2950 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002951 * always-on VPN connection for the current user. If there is no such package, or the always-on
2952 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00002953 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002954 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
2955 * is set.
2956 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00002957 */
2958 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
2959 if (mService != null) {
2960 try {
2961 return mService.getAlwaysOnVpnPackage(admin);
2962 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002963 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00002964 }
2965 }
2966 return null;
2967 }
2968
2969 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002970 * Called by an application that is administering the device to disable all cameras on the
2971 * device, for this user. After setting this, no applications running as this user will be able
2972 * to access any cameras on the device.
2973 * <p>
2974 * If the caller is device owner, then the restriction will be applied to all users.
2975 * <p>
2976 * The calling device admin must have requested
2977 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
2978 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07002979 *
2980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2981 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002982 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2983 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07002984 */
Robin Lee25e26452015-06-02 09:56:29 -07002985 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Ben Komalo2447edd2011-05-09 16:05:33 -07002986 if (mService != null) {
2987 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002988 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07002989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002990 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07002991 }
2992 }
2993 }
2994
2995 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07002996 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08002997 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07002998 * @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 -07002999 * have disabled the camera
3000 */
Robin Lee25e26452015-06-02 09:56:29 -07003001 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003002 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003003 }
3004
3005 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003006 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003007 if (mService != null) {
3008 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003009 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003010 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003011 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003012 }
3013 }
3014 return false;
3015 }
3016
3017 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003018 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003019 * <p>
3020 * There must be only one user on the device, managed by the device owner. Otherwise a
3021 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003022 *
3023 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003024 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3025 * wasn't triggered because a previous bugreport operation is still active (either the
3026 * bugreport is still running or waiting for the user to share or decline)
3027 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3028 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003029 */
3030 public boolean requestBugreport(@NonNull ComponentName admin) {
3031 if (mService != null) {
3032 try {
3033 return mService.requestBugreport(admin);
3034 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003035 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003036 }
3037 }
3038 return false;
3039 }
3040
3041 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003042 * Determine whether or not creating a guest user has been disabled for the device
3043 *
3044 * @hide
3045 */
3046 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3047 // Currently guest users can always be created if multi-user is enabled
3048 // TODO introduce a policy for guest user creation
3049 return false;
3050 }
3051
3052 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003053 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3054 * screen capture also prevents the content from being shown on display devices that do not have
3055 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3056 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003057 * <p>
3058 * The calling device admin must be a device or profile owner. If it is not, a security
3059 * exception will be thrown.
3060 * <p>
3061 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3062 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003063 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003064 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003065 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003066 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003067 */
Robin Lee25e26452015-06-02 09:56:29 -07003068 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003069 if (mService != null) {
3070 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003071 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003072 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003073 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003074 }
3075 }
3076 }
3077
3078 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003079 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003080 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003081 * @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 +01003082 * have disabled screen capture.
3083 */
Robin Lee25e26452015-06-02 09:56:29 -07003084 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003085 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003086 }
3087
3088 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003089 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003090 if (mService != null) {
3091 try {
3092 return mService.getScreenCaptureDisabled(admin, userHandle);
3093 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003094 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003095 }
3096 }
3097 return false;
3098 }
3099
3100 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003101 * Called by a device owner to set whether auto time is required. If auto time is required the
3102 * user cannot set the date and time, but has to use network date and time.
3103 * <p>
3104 * Note: if auto time is required the user can still manually set the time zone.
3105 * <p>
3106 * The calling device admin must be a device owner. If it is not, a security exception will be
3107 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003108 *
3109 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3110 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003111 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003112 */
Robin Lee25e26452015-06-02 09:56:29 -07003113 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003114 if (mService != null) {
3115 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003116 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003117 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003118 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003119 }
3120 }
3121 }
3122
3123 /**
3124 * @return true if auto time is required.
3125 */
3126 public boolean getAutoTimeRequired() {
3127 if (mService != null) {
3128 try {
3129 return mService.getAutoTimeRequired();
3130 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003131 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003132 }
3133 }
3134 return false;
3135 }
3136
3137 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003138 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003139 * <p>
3140 * The system user is exempt from this policy - it is never ephemeral.
3141 * <p>
3142 * The calling device admin must be the device owner. If it is not, a security exception will be
3143 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003144 *
3145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3146 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003147 * subsequently created users will be ephemeral.
3148 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003149 * @hide
3150 */
3151 public void setForceEphemeralUsers(
3152 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
3153 if (mService != null) {
3154 try {
3155 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3156 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003157 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003158 }
3159 }
3160 }
3161
3162 /**
3163 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003164 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003165 * @hide
3166 */
3167 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
3168 if (mService != null) {
3169 try {
3170 return mService.getForceEphemeralUsers(admin);
3171 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003172 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003173 }
3174 }
3175 return false;
3176 }
3177
3178 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003179 * Called by an application that is administering the device to disable keyguard customizations,
3180 * such as widgets. After setting this, keyguard features will be disabled according to the
3181 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003182 * <p>
3183 * The calling device admin must have requested
3184 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3185 * if it has not, a security exception will be thrown.
3186 * <p>
3187 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3188 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3189 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003190 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003191 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003192 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003193 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003194 * there is one, or the parent user otherwise.
3195 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3196 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003197 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003198 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3199 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003200 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3201 * profile.
3202 * <p>
3203 * Requests to disable other features on a managed profile will be ignored.
3204 * <p>
3205 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003206 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003207 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003208 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003209 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003210 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3211 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3212 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3213 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3214 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3215 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3216 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003217 */
Robin Lee25e26452015-06-02 09:56:29 -07003218 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003219 if (mService != null) {
3220 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003221 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003222 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003223 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003224 }
3225 }
3226 }
3227
3228 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003229 * Determine whether or not features have been disabled in keyguard either by the calling
Esteban Talaverac1c83592016-02-17 17:56:15 +00003230 * admin, if specified, or all admins that set retrictions on this user and its participating
3231 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3232 *
3233 * <p>This method can be called on the {@link DevicePolicyManager} instance
3234 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3235 * restrictions on the parent profile.
3236 *
Esteban Talavera62399912016-01-11 15:37:55 +00003237 * @param admin The name of the admin component to check, or {@code null} to check whether any
3238 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003239 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3240 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003241 */
Robin Lee25e26452015-06-02 09:56:29 -07003242 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003243 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003244 }
3245
3246 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003247 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003248 if (mService != null) {
3249 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003250 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003251 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003252 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003253 }
3254 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003255 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003256 }
3257
3258 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003259 * @hide
3260 */
Robin Lee25e26452015-06-02 09:56:29 -07003261 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3262 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003263 if (mService != null) {
3264 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003265 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003266 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003267 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003268 }
3269 }
3270 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003271
Dianne Hackbornd6847842010-01-12 18:14:19 -08003272 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003273 * @hide
3274 */
Robin Lee25e26452015-06-02 09:56:29 -07003275 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003276 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003277 }
3278
3279 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003280 * @hide
3281 */
Robin Lee25e26452015-06-02 09:56:29 -07003282 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003283 if (mService != null) {
3284 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003285 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003286 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003287 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003288 }
3289 }
3290 }
3291
3292 /**
3293 * @hide
3294 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003295 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003296 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003297 if (mService != null) {
3298 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003299 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003300 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003301 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003302 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003303 }
3304 }
3305 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003306
Dianne Hackbornd6847842010-01-12 18:14:19 -08003307 /**
3308 * @hide
3309 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003310 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003311 if (mService != null) {
3312 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003313 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003314 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003315 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003316 }
3317 }
3318 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003319
Dianne Hackbornd6847842010-01-12 18:14:19 -08003320 /**
3321 * @hide
3322 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003323 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003324 if (mService != null) {
3325 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003326 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003327 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003328 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003329 }
3330 }
3331 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003332
3333 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003334 * @hide
3335 */
3336 public void reportFailedFingerprintAttempt(int userHandle) {
3337 if (mService != null) {
3338 try {
3339 mService.reportFailedFingerprintAttempt(userHandle);
3340 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003341 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003342 }
3343 }
3344 }
3345
3346 /**
3347 * @hide
3348 */
3349 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3350 if (mService != null) {
3351 try {
3352 mService.reportSuccessfulFingerprintAttempt(userHandle);
3353 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003354 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003355 }
3356 }
3357 }
3358
3359 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003360 * Should be called when keyguard has been dismissed.
3361 * @hide
3362 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003363 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003364 if (mService != null) {
3365 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003366 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003367 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003368 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003369 }
3370 }
3371 }
3372
3373 /**
3374 * Should be called when keyguard view has been shown to the user.
3375 * @hide
3376 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003377 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003378 if (mService != null) {
3379 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003380 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003381 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003382 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003383 }
3384 }
3385 }
3386
3387 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003388 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003389 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003390 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3391 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003392 * @return whether the package was successfully registered as the device owner.
3393 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003394 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003395 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003396 public boolean setDeviceOwner(ComponentName who) {
3397 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003398 }
3399
3400 /**
3401 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003402 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003403 public boolean setDeviceOwner(ComponentName who, int userId) {
3404 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003405 }
3406
3407 /**
3408 * @hide
3409 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003410 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3411 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003412 }
3413
3414 /**
3415 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003416 * Sets the given package as the device owner. The package must already be installed. There
3417 * must not already be a device owner.
3418 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3419 * this method.
3420 * Calling this after the setup phase of the primary user has completed is allowed only if
3421 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003422 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003423 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003424 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003425 * @return whether the package was successfully registered as the device owner.
3426 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003427 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003428 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003429 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003430 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003431 if (mService != null) {
3432 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003433 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003434 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003435 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003436 }
3437 }
3438 return false;
3439 }
3440
3441 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003442 * Used to determine if a particular package has been registered as a Device Owner app.
3443 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003444 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003445 * package is currently registered as the device owner app, pass in the package name from
3446 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003447 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003448 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3449 * the setup process.
3450 * @param packageName the package name of the app, to compare with the registered device owner
3451 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003452 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003453 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003454 public boolean isDeviceOwnerApp(String packageName) {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003455 return isDeviceOwnerAppOnCallingUser(packageName);
3456 }
3457
3458 /**
3459 * @return true if a package is registered as device owner, only when it's running on the
3460 * calling user.
3461 *
3462 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3463 * @hide
3464 */
3465 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3466 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3467 }
3468
3469 /**
3470 * @return true if a package is registered as device owner, even if it's running on a different
3471 * user.
3472 *
3473 * <p>Requires the MANAGE_USERS permission.
3474 *
3475 * @hide
3476 */
3477 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3478 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3479 }
3480
3481 /**
3482 * @return device owner component name, only when it's running on the calling user.
3483 *
3484 * @hide
3485 */
3486 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3487 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3488 }
3489
3490 /**
3491 * @return device owner component name, even if it's running on a different user.
3492 *
3493 * <p>Requires the MANAGE_USERS permission.
3494 *
3495 * @hide
3496 */
3497 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3498 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3499 }
3500
3501 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003502 if (packageName == null) {
3503 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003504 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003505 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003506 if (deviceOwner == null) {
3507 return false;
3508 }
3509 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003510 }
3511
Makoto Onukic8a5a552015-11-19 14:29:12 -08003512 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3513 if (mService != null) {
3514 try {
3515 return mService.getDeviceOwnerComponent(callingUserOnly);
3516 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003517 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003518 }
3519 }
3520 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003521 }
3522
Jason Monkb0dced82014-06-06 14:36:20 -04003523 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003524 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3525 * no device owner.
3526 *
3527 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003528 *
3529 * @hide
3530 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003531 public int getDeviceOwnerUserId() {
3532 if (mService != null) {
3533 try {
3534 return mService.getDeviceOwnerUserId();
3535 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003536 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003537 }
3538 }
3539 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003540 }
3541
3542 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003543 * Clears the current device owner. The caller must be the device owner. This function should be
3544 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3545 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003546 *
3547 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003548 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3549 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003550 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003551 public void clearDeviceOwnerApp(String packageName) {
Jason Monkb0dced82014-06-06 14:36:20 -04003552 if (mService != null) {
3553 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003554 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003555 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003556 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003557 }
3558 }
3559 }
3560
Makoto Onukia52562c2015-10-01 16:12:31 -07003561 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003562 * Returns the device owner package name, only if it's running on the calling user.
3563 *
3564 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003565 *
3566 * @hide
3567 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003568 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003569 public String getDeviceOwner() {
Makoto Onukic8a5a552015-11-19 14:29:12 -08003570 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3571 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003572 }
3573
3574 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003575 * @return true if the device is managed by any device owner.
3576 *
3577 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003578 *
3579 * @hide
3580 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003581 public boolean isDeviceManaged() {
3582 return getDeviceOwnerComponentOnAnyUser() != null;
3583 }
3584
3585 /**
3586 * Returns the device owner name. Note this method *will* return the device owner
3587 * name when it's running on a different user.
3588 *
3589 * <p>Requires the MANAGE_USERS permission.
3590 *
3591 * @hide
3592 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003593 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003594 public String getDeviceOwnerNameOnAnyUser() {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003595 if (mService != null) {
3596 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003597 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003598 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003599 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003600 }
3601 }
3602 return null;
3603 }
Adam Connors776c5552014-01-09 10:42:56 +00003604
3605 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003606 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003607 * @deprecated Do not use
3608 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003609 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003610 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003611 @SystemApi
3612 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003613 return null;
3614 }
3615
3616 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003617 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003618 * @deprecated Do not use
3619 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003620 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003621 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003622 @SystemApi
3623 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003624 return null;
3625 }
3626
Julia Reynolds20118f12015-02-11 12:34:08 -05003627 /**
Adam Connors776c5552014-01-09 10:42:56 +00003628 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003629 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303630 * Sets the given component as an active admin and registers the package as the profile
3631 * owner for this user. The package must already be installed and there shouldn't be
3632 * an existing profile owner registered for this user. Also, this method must be called
3633 * before the user setup has been completed.
3634 * <p>
3635 * This method can only be called by system apps that hold MANAGE_USERS permission and
3636 * MANAGE_DEVICE_ADMINS permission.
3637 * @param admin The component to register as an active admin and profile owner.
3638 * @param ownerName The user-visible name of the entity that is managing this user.
3639 * @return whether the admin was successfully registered as the profile owner.
3640 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3641 * the user has already been set up.
3642 */
Justin Morey80440cc2014-07-24 09:16:35 -05003643 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003644 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303645 throws IllegalArgumentException {
3646 if (mService != null) {
3647 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003648 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303649 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003650 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303651 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003652 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303653 }
3654 }
3655 return false;
3656 }
3657
3658 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003659 * Clears the active profile owner and removes all user restrictions. The caller must be from
3660 * the same package as the active profile owner for this user, otherwise a SecurityException
3661 * will be thrown.
3662 * <p>
3663 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003664 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003665 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003666 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003667 */
Robin Lee25e26452015-06-02 09:56:29 -07003668 public void clearProfileOwner(@NonNull ComponentName admin) {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003669 if (mService != null) {
3670 try {
3671 mService.clearProfileOwner(admin);
3672 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003673 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003674 }
3675 }
3676 }
3677
3678 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003679 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003680 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003681 */
3682 public boolean hasUserSetupCompleted() {
3683 if (mService != null) {
3684 try {
3685 return mService.hasUserSetupCompleted();
3686 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003687 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003688 }
3689 }
3690 return true;
3691 }
3692
3693 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003694 * @hide
3695 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003696 * already be installed. There must not already be a profile owner for this user.
3697 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3698 * this method.
3699 * Calling this after the setup phase of the specified user has completed is allowed only if:
3700 * - the caller is SYSTEM_UID.
3701 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003702 * @param admin the component name to be registered as profile owner.
3703 * @param ownerName the human readable name of the organisation associated with this DPM.
3704 * @param userHandle the userId to set the profile owner for.
3705 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003706 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3707 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003708 */
Robin Lee25e26452015-06-02 09:56:29 -07003709 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003710 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003711 if (mService != null) {
3712 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003713 if (ownerName == null) {
3714 ownerName = "";
3715 }
3716 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003717 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003718 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003719 }
3720 }
3721 return false;
3722 }
3723
3724 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003725 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003726 * <p>
3727 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003728 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003729 * <p>
3730 * If the device owner information contains only whitespaces then the message on the lock screen
3731 * will be blank and the user will not be allowed to change it.
3732 * <p>
3733 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003734 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3735 * and set a new version of this string accordingly.
3736 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003737 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003738 * @param info Device owner information which will be displayed instead of the user owner info.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003739 * @return Whether the device owner information has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003740 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003741 */
3742 public boolean setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, String info) {
3743 if (mService != null) {
3744 try {
3745 return mService.setDeviceOwnerLockScreenInfo(admin, info);
3746 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003747 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003748 }
3749 }
3750 return false;
3751 }
3752
3753 /**
3754 * @return The device owner information. If it is not set returns {@code null}.
3755 */
3756 public String getDeviceOwnerLockScreenInfo() {
3757 if (mService != null) {
3758 try {
3759 return mService.getDeviceOwnerLockScreenInfo();
3760 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003761 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003762 }
3763 }
3764 return null;
3765 }
3766
3767 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003768 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003769 * <p>
3770 * A suspended package will not be able to start activities. Its notifications will be hidden,
3771 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
3772 * device.
3773 * <p>
3774 * The package must already be installed. If the package is uninstalled while suspended the
3775 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00003776 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003777 *
3778 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003779 * @param packageNames The package names to suspend or unsuspend.
3780 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003781 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003782 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003783 * this method.
3784 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003785 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003786 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003787 boolean suspended) {
3788 if (mService != null) {
3789 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003790 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003791 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003792 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003793 }
3794 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00003795 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003796 }
3797
3798 /**
3799 * Called by device or profile owners to determine if a package is suspended.
3800 *
3801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3802 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00003803 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003804 * suspended, could not be found or an error occurred.
3805 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003806 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003807 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003808 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
3809 throws NameNotFoundException {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003810 if (mService != null) {
3811 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003812 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003813 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003814 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00003815 } catch (IllegalArgumentException ex) {
3816 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00003817 }
3818 }
3819 return false;
3820 }
3821
3822 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003823 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
3824 * be used. Only the profile owner can call this.
3825 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01003826 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003827 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003828 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003829 */
Robin Lee25e26452015-06-02 09:56:29 -07003830 public void setProfileEnabled(@NonNull ComponentName admin) {
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003831 if (mService != null) {
3832 try {
3833 mService.setProfileEnabled(admin);
3834 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003835 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01003836 }
3837 }
3838 }
3839
3840 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003841 * Sets the name of the profile. In the device owner case it sets the name of the user which it
3842 * is called from. Only a profile owner or device owner can call this. If this is never called
3843 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003844 *
3845 * @see #isProfileOwnerApp
3846 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07003847 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003848 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003849 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01003850 */
Robin Lee25e26452015-06-02 09:56:29 -07003851 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Jessica Hummel1333ea12014-06-23 11:20:10 +01003852 if (mService != null) {
3853 try {
Robin Lee25e26452015-06-02 09:56:29 -07003854 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003856 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07003857 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003858 }
3859 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01003860
3861 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003862 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08003863 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07003864 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00003865 *
3866 * @param packageName The package name of the app to compare with the registered profile owner.
3867 * @return Whether or not the package is registered as the profile owner.
3868 */
3869 public boolean isProfileOwnerApp(String packageName) {
3870 if (mService != null) {
3871 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08003872 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01003873 return profileOwner != null
3874 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00003875 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003876 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003877 }
3878 }
3879 return false;
3880 }
3881
3882 /**
3883 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003884 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00003885 * owner has been set for that user.
3886 * @throws IllegalArgumentException if the userId is invalid.
3887 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003888 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003889 public ComponentName getProfileOwner() throws IllegalArgumentException {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003890 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
3891 }
3892
3893 /**
3894 * @see #getProfileOwner()
3895 * @hide
3896 */
3897 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003898 if (mService != null) {
3899 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01003900 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00003901 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003902 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003903 }
3904 }
3905 return null;
3906 }
3907
3908 /**
3909 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003910 * @return the human readable name of the organisation associated with this DPM or {@code null}
3911 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00003912 * @throws IllegalArgumentException if the userId is invalid.
3913 */
3914 public String getProfileOwnerName() throws IllegalArgumentException {
3915 if (mService != null) {
3916 try {
3917 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
3918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003919 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003920 }
3921 }
3922 return null;
3923 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003924
3925 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07003926 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08003927 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07003928 * @return the human readable name of the organisation associated with this profile owner or
3929 * null if one is not set.
3930 * @throws IllegalArgumentException if the userId is invalid.
3931 */
3932 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02003933 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Amith Yamasani38f836b2014-08-20 14:51:15 -07003934 if (mService != null) {
3935 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02003936 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07003937 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003938 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07003939 }
3940 }
3941 return null;
3942 }
3943
3944 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003945 * Called by a profile owner or device owner to add a default intent handler activity for
3946 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003947 * handler even if the set of potential event handlers for the intent filter changes and if the
3948 * intent preferences are reset.
3949 * <p>
3950 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
3951 * When the activity is (re)installed, it is automatically reset as default intent handler for
3952 * the filter.
3953 * <p>
3954 * The calling device admin must be a profile owner or device owner. If it is not, a security
3955 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003956 *
3957 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3958 * @param filter The IntentFilter for which a default handler is added.
3959 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003960 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003961 */
Robin Lee25e26452015-06-02 09:56:29 -07003962 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
3963 @NonNull ComponentName activity) {
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003964 if (mService != null) {
3965 try {
3966 mService.addPersistentPreferredActivity(admin, filter, activity);
3967 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003968 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003969 }
3970 }
3971 }
3972
3973 /**
3974 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00003975 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003976 * <p>
3977 * The calling device admin must be a profile owner. If it is not, a security exception will be
3978 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003979 *
3980 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3981 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003982 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003983 */
Robin Lee25e26452015-06-02 09:56:29 -07003984 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003985 String packageName) {
3986 if (mService != null) {
3987 try {
3988 mService.clearPackagePersistentPreferredActivities(admin, packageName);
3989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003990 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00003991 }
3992 }
3993 }
Robin Lee66e5d962014-04-09 16:44:21 +01003994
3995 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00003996 * Called by a profile owner or device owner to grant permission to a package to manage
3997 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
3998 * {@link #getApplicationRestrictions}.
3999 * <p>
4000 * This permission is persistent until it is later cleared by calling this method with a
4001 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004002 * <p>
4003 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004004 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004005 *
4006 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4007 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004008 * APIs. If {@code null} is given the current package will be cleared.
4009 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004010 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004011 */
4012 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004013 @Nullable String packageName) throws NameNotFoundException {
Esteban Talaverabf60f722015-12-10 16:26:44 +00004014 if (mService != null) {
4015 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004016 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4017 throw new NameNotFoundException(packageName);
4018 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004019 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004020 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004021 }
4022 }
4023 }
4024
4025 /**
4026 * Called by a profile owner or device owner to retrieve the application restrictions managing
4027 * package for the current user, or {@code null} if none is set.
4028 *
4029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4030 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004031 * {@code null} if none is set.
4032 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004033 */
4034 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
4035 if (mService != null) {
4036 try {
4037 return mService.getApplicationRestrictionsManagingPackage(admin);
4038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004039 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004040 }
4041 }
4042 return null;
4043 }
4044
4045 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004046 * Called by any application to find out whether it has been granted permission via
4047 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4048 * for the calling user.
4049 *
4050 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4051 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004052 */
4053 public boolean isCallerApplicationRestrictionsManagingPackage() {
4054 if (mService != null) {
4055 try {
4056 return mService.isCallerApplicationRestrictionsManagingPackage();
4057 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004058 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004059 }
4060 }
4061 return false;
4062 }
4063
4064 /**
4065 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004066 * <p>
4067 * The caller must be a profile or device owner on that user, or the package allowed to manage
4068 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4069 * security exception will be thrown.
4070 * <p>
4071 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004072 * <ul>
4073 * <li>{@code boolean}
4074 * <li>{@code int}
4075 * <li>{@code String} or {@code String[]}
4076 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4077 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004078 * <p>
4079 * If the restrictions are not available yet, but may be applied in the near future, the caller
4080 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004081 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004082 * <p>
4083 * The application restrictions are only made visible to the target application via
4084 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4085 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004086 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004087 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004089 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004090 * @param packageName The name of the package to update restricted settings for.
4091 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004092 * set of active restrictions.
4093 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004094 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004095 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004096 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004097 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004098 Bundle settings) {
4099 if (mService != null) {
4100 try {
4101 mService.setApplicationRestrictions(admin, packageName, settings);
4102 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004103 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004104 }
4105 }
4106 }
4107
4108 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004109 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4110 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4111 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004112 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004113 * <p>
4114 * The calling device admin must have requested
4115 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4116 * if not, a security exception will be thrown.
Jim Miller604e7552014-07-18 19:00:02 -07004117 *
4118 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004119 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004120 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4121 * strictly disabled according to the state of the
4122 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4123 * <p>
4124 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4125 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4126 * device admins.
4127 * <p>
4128 * Consult documentation for the specific TrustAgent to determine legal options
4129 * parameters.
4130 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4131 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004132 */
Robin Lee25e26452015-06-02 09:56:29 -07004133 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4134 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004135 if (mService != null) {
4136 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08004137 mService.setTrustAgentConfiguration(admin, target, configuration);
Jim Miller604e7552014-07-18 19:00:02 -07004138 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004139 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004140 }
4141 }
4142 }
4143
4144 /**
Jim Millere303bf42014-08-26 17:12:29 -07004145 * Gets configuration for the given trust agent based on aggregating all calls to
4146 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4147 * all device admins.
Jim Miller604e7552014-07-18 19:00:02 -07004148 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004149 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4150 * this function returns a list of configurations for all admins that declare
4151 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4152 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4153 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4154 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004155 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004156 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004157 */
Robin Lee25e26452015-06-02 09:56:29 -07004158 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4159 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004160 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004161 }
4162
4163 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004164 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4165 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004166 if (mService != null) {
4167 try {
Jim Millere303bf42014-08-26 17:12:29 -07004168 return mService.getTrustAgentConfiguration(admin, agent, userHandle);
Jim Miller604e7552014-07-18 19:00:02 -07004169 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004170 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004171 }
4172 }
Jim Millere303bf42014-08-26 17:12:29 -07004173 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004174 }
4175
4176 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004177 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4178 * managed profile will be shown in the parent profile, for incoming calls.
4179 * <p>
4180 * The calling device admin must be a profile owner. If it is not, a security exception will be
4181 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004182 *
Robin Lee25e26452015-06-02 09:56:29 -07004183 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004184 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004185 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004186 */
Robin Lee25e26452015-06-02 09:56:29 -07004187 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Adam Connors210fe212014-07-17 15:41:43 +01004188 if (mService != null) {
4189 try {
Robin Lee25e26452015-06-02 09:56:29 -07004190 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004191 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004192 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004193 }
4194 }
4195 }
4196
4197 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004198 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4199 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004200 * <p>
4201 * The calling device admin must be a profile owner. If it is not, a security exception will be
4202 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004203 *
Robin Lee25e26452015-06-02 09:56:29 -07004204 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004205 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004206 */
Robin Lee25e26452015-06-02 09:56:29 -07004207 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Adam Connors210fe212014-07-17 15:41:43 +01004208 if (mService != null) {
4209 try {
Robin Lee25e26452015-06-02 09:56:29 -07004210 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004211 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004212 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004213 }
4214 }
4215 return false;
4216 }
4217
4218 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004219 * Determine whether or not caller-Id information has been disabled.
4220 *
4221 * @param userHandle The user for whom to check the caller-id permission
4222 * @hide
4223 */
4224 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4225 if (mService != null) {
4226 try {
4227 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4228 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004229 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004230 }
4231 }
4232 return false;
4233 }
4234
4235 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004236 * Called by a profile owner of a managed profile to set whether contacts search from the
4237 * managed profile will be shown in the parent profile, for incoming calls.
4238 * <p>
4239 * The calling device admin must be a profile owner. If it is not, a security exception will be
4240 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004241 *
4242 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4243 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004244 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004245 */
4246 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4247 boolean disabled) {
4248 if (mService != null) {
4249 try {
4250 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4251 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004252 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004253 }
4254 }
4255 }
4256
4257 /**
4258 * Called by a profile owner of a managed profile to determine whether or not contacts search
4259 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004260 * <p>
4261 * The calling device admin must be a profile owner. If it is not, a security exception will be
4262 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004263 *
4264 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004265 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004266 */
4267 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
4268 if (mService != null) {
4269 try {
4270 return mService.getCrossProfileContactsSearchDisabled(admin);
4271 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004272 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004273 }
4274 }
4275 return false;
4276 }
4277
4278
4279 /**
4280 * Determine whether or not contacts search has been disabled.
4281 *
4282 * @param userHandle The user for whom to check the contacts search permission
4283 * @hide
4284 */
4285 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4286 if (mService != null) {
4287 try {
4288 return mService
4289 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4290 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004291 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004292 }
4293 }
4294 return false;
4295 }
4296
4297 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004298 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004299 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004300 * @hide
4301 */
4302 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004303 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004304 if (mService != null) {
4305 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004306 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4307 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004308 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004309 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004310 }
4311 }
4312 }
4313
4314 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004315 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004316 * @hide
4317 */
4318 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4319 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004320 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004321 originalIntent);
4322 }
4323
4324 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004325 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4326 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004327 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004328 * The calling device admin must be a profile owner. If it is not, a security exception will be
4329 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004330 * <p>
4331 * This API works on managed profile only.
4332 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004333 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4334 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4335 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004336 */
Robin Lee25e26452015-06-02 09:56:29 -07004337 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Ricky Wai778ba132015-03-31 14:21:22 +01004338 if (mService != null) {
4339 try {
Robin Lee25e26452015-06-02 09:56:29 -07004340 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004342 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004343 }
4344 }
4345 }
4346
4347 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004348 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4349 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004350 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004351 * The calling device admin must be a profile owner. If it is not, a security exception will be
4352 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004353 * <p>
4354 * This API works on managed profile only.
4355 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004356 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4357 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004358 */
Robin Lee25e26452015-06-02 09:56:29 -07004359 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Ricky Wai778ba132015-03-31 14:21:22 +01004360 if (mService != null) {
4361 try {
Robin Lee25e26452015-06-02 09:56:29 -07004362 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004364 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004365 }
4366 }
4367 return true;
4368 }
4369
4370 /**
4371 * Determine whether or not Bluetooth devices cannot access contacts.
4372 * <p>
4373 * This API works on managed profile UserHandle only.
4374 *
4375 * @param userHandle The user for whom to check the caller-id permission
4376 * @hide
4377 */
4378 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4379 if (mService != null) {
4380 try {
4381 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4382 .getIdentifier());
4383 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004384 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004385 }
4386 }
4387 return true;
4388 }
4389
4390 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004391 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004392 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4393 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004394 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004395 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004396 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004397 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004398 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004399 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4400 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004401 */
Robin Lee25e26452015-06-02 09:56:29 -07004402 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004403 if (mService != null) {
4404 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004405 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004406 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004407 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004408 }
4409 }
4410 }
4411
4412 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004413 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4414 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004415 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004416 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004417 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004418 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004419 */
Robin Lee25e26452015-06-02 09:56:29 -07004420 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004421 if (mService != null) {
4422 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004423 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004424 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004425 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004426 }
4427 }
4428 }
4429
4430 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004431 * Called by a profile or device owner to set the permitted accessibility services. When set by
4432 * a device owner or profile owner the restriction applies to all profiles of the user the
4433 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4434 * service. When zero or more packages have been added, accessiblity services that are not in
4435 * the list and not part of the system can not be enabled by the user.
4436 * <p>
4437 * Calling with a null value for the list disables the restriction so that all services can be
4438 * used, calling with an empty list only allows the builtin system's services.
4439 * <p>
4440 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004441 *
4442 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4443 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004444 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4445 * accessibility services enabled, that are not in the list.
4446 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004447 */
Robin Lee25e26452015-06-02 09:56:29 -07004448 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004449 List<String> packageNames) {
4450 if (mService != null) {
4451 try {
4452 return mService.setPermittedAccessibilityServices(admin, packageNames);
4453 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004454 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004455 }
4456 }
4457 return false;
4458 }
4459
4460 /**
4461 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004462 * <p>
4463 * An empty list means no accessibility services except system services are allowed. Null means
4464 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004465 *
4466 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4467 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004468 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004469 */
Robin Lee25e26452015-06-02 09:56:29 -07004470 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004471 if (mService != null) {
4472 try {
4473 return mService.getPermittedAccessibilityServices(admin);
4474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004475 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004476 }
4477 }
4478 return null;
4479 }
4480
4481 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004482 * Called by the system to check if a specific accessibility service is disabled by admin.
4483 *
4484 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4485 * @param packageName Accessibility service package name that needs to be checked.
4486 * @param userHandle user id the admin is running as.
4487 * @return true if the accessibility service is permitted, otherwise false.
4488 *
4489 * @hide
4490 */
4491 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4492 @NonNull String packageName, int userHandle) {
4493 if (mService != null) {
4494 try {
4495 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4496 userHandle);
4497 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004498 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004499 }
4500 }
4501 return false;
4502 }
4503
4504 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004505 * Returns the list of accessibility services permitted by the device or profiles
4506 * owners of this user.
4507 *
4508 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4509 * it will contain the intersection of the permitted lists for any device or profile
4510 * owners that apply to this user. It will also include any system accessibility services.
4511 *
4512 * @param userId which user to check for.
4513 * @return List of accessiblity service package names.
4514 * @hide
4515 */
4516 @SystemApi
4517 public List<String> getPermittedAccessibilityServices(int userId) {
4518 if (mService != null) {
4519 try {
4520 return mService.getPermittedAccessibilityServicesForUser(userId);
4521 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004522 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004523 }
4524 }
4525 return null;
4526 }
4527
4528 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004529 * Called by a profile or device owner to set the permitted input methods services. When set by
4530 * a device owner or profile owner the restriction applies to all profiles of the user the
4531 * device owner or profile owner is an admin for. By default the user can use any input method.
4532 * When zero or more packages have been added, input method that are not in the list and not
4533 * part of the system can not be enabled by the user. This method will fail if it is called for
4534 * a admin that is not for the foreground user or a profile of the foreground user.
4535 * <p>
4536 * Calling with a null value for the list disables the restriction so that all input methods can
4537 * be used, calling with an empty list disables all but the system's own input methods.
4538 * <p>
4539 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004540 *
4541 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4542 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004543 * @return true if setting the restriction succeeded. It will fail if there are one or more
4544 * non-system input methods currently enabled that are not in the packageNames list.
4545 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004546 */
Robin Lee25e26452015-06-02 09:56:29 -07004547 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004548 if (mService != null) {
4549 try {
4550 return mService.setPermittedInputMethods(admin, packageNames);
4551 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004552 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004553 }
4554 }
4555 return false;
4556 }
4557
4558
4559 /**
4560 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004561 * <p>
4562 * An empty list means no input methods except system input methods are allowed. Null means all
4563 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004564 *
4565 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4566 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004567 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004568 */
Robin Lee25e26452015-06-02 09:56:29 -07004569 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004570 if (mService != null) {
4571 try {
4572 return mService.getPermittedInputMethods(admin);
4573 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004574 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004575 }
4576 }
4577 return null;
4578 }
4579
4580 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004581 * Called by the system to check if a specific input method is disabled by admin.
4582 *
4583 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4584 * @param packageName Input method package name that needs to be checked.
4585 * @param userHandle user id the admin is running as.
4586 * @return true if the input method is permitted, otherwise false.
4587 *
4588 * @hide
4589 */
4590 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4591 @NonNull String packageName, int userHandle) {
4592 if (mService != null) {
4593 try {
4594 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004596 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004597 }
4598 }
4599 return false;
4600 }
4601
4602 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004603 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004604 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004605 *
4606 * <p>Null means all input methods are allowed, if a non-null list is returned
4607 * it will contain the intersection of the permitted lists for any device or profile
4608 * owners that apply to this user. It will also include any system input methods.
4609 *
4610 * @return List of input method package names.
4611 * @hide
4612 */
4613 @SystemApi
4614 public List<String> getPermittedInputMethodsForCurrentUser() {
4615 if (mService != null) {
4616 try {
4617 return mService.getPermittedInputMethodsForCurrentUser();
4618 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004619 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004620 }
4621 }
4622 return null;
4623 }
4624
4625 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004626 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4627 * currently installed it.
4628 *
4629 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4630 *
4631 * @return List of package names to keep cached.
4632 * @hide
4633 */
4634 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
4635 if (mService != null) {
4636 try {
4637 return mService.getKeepUninstalledPackages(admin);
4638 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004639 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004640 }
4641 }
4642 return null;
4643 }
4644
4645 /**
4646 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4647 * currently installed it.
4648 *
4649 * <p>Please note that setting this policy does not imply that specified apps will be
4650 * automatically pre-cached.</p>
4651 *
4652 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4653 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004654 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004655 * @hide
4656 */
4657 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4658 @NonNull List<String> packageNames) {
4659 if (mService != null) {
4660 try {
4661 mService.setKeepUninstalledPackages(admin, packageNames);
4662 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004663 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004664 }
4665 }
4666 }
4667
4668 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004669 * Called by a device owner to create a user with the specified name. The UserHandle returned
4670 * by this method should not be persisted as user handles are recycled as users are removed and
4671 * created. If you need to persist an identifier for this user, use
4672 * {@link UserManager#getSerialNumberForUser}.
4673 *
4674 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4675 * @param name the user's name
4676 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004677 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4678 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004679 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004680 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004681 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004682 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004683 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004684 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004685 return null;
4686 }
4687
4688 /**
Jason Monk03978a42014-06-10 15:05:30 -04004689 * Called by a device owner to create a user with the specified name. The UserHandle returned
4690 * by this method should not be persisted as user handles are recycled as users are removed and
4691 * created. If you need to persist an identifier for this user, use
4692 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4693 * immediately.
4694 *
4695 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4696 * as registered as an active admin on the new user. The profile owner package will be
4697 * installed on the new user if it already is installed on the device.
4698 *
4699 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4700 * profileOwnerComponent when onEnable is called.
4701 *
4702 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4703 * @param name the user's name
4704 * @param ownerName the human readable name of the organisation associated with this DPM.
4705 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4706 * the user.
4707 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4708 * on the new user.
4709 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004710 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4711 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004712 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004713 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004714 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004715 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004716 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004717 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4718 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004719 return null;
4720 }
4721
4722 /**
phweissa92e1212016-01-25 17:14:10 +01004723 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01004724 */
4725 public static final int SKIP_SETUP_WIZARD = 0x0001;
4726
4727 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01004728 * Flag used by {@link #createAndManageUser} to specify that the user should be created
4729 * ephemeral.
4730 * @hide
4731 */
4732 public static final int MAKE_USER_EPHEMERAL = 0x0002;
4733
4734 /**
phweissa92e1212016-01-25 17:14:10 +01004735 * Called by a device owner to create a user with the specified name and a given component of
4736 * the calling package as profile owner. The UserHandle returned by this method should not be
4737 * persisted as user handles are recycled as users are removed and created. If you need to
4738 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
4739 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004740 * <p>
4741 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
4742 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
4743 * be registered as an active admin on the new user. The profile owner package will be installed
4744 * on the new user.
4745 * <p>
4746 * If the adminExtras are not null, they will be stored on the device until the user is started
4747 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01004748 *
4749 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4750 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01004751 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004752 * same package as admin, otherwise no user is created and an
4753 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01004754 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004755 * user.
phweissa92e1212016-01-25 17:14:10 +01004756 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01004757 * @see UserHandle
4758 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4759 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004760 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01004761 */
4762 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01004763 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
4764 int flags) {
phweiss343fb332016-01-25 14:48:59 +01004765 try {
phweissa92e1212016-01-25 17:14:10 +01004766 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01004767 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004768 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01004769 }
phweiss343fb332016-01-25 14:48:59 +01004770 }
4771
4772 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004773 * Called by a device owner to remove a user and all associated data. The primary user can not
4774 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04004775 *
4776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4777 * @param userHandle the user to remove.
4778 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004779 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04004780 */
Robin Lee25e26452015-06-02 09:56:29 -07004781 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004782 try {
4783 return mService.removeUser(admin, userHandle);
4784 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004785 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04004786 }
4787 }
4788
4789 /**
Jason Monk582d9112014-07-09 19:57:08 -04004790 * Called by a device owner to switch the specified user to the foreground.
4791 *
4792 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4793 * @param userHandle the user to switch to; null will switch to primary.
4794 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004795 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04004796 * @see Intent#ACTION_USER_FOREGROUND
4797 */
Robin Lee25e26452015-06-02 09:56:29 -07004798 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Jason Monk582d9112014-07-09 19:57:08 -04004799 try {
4800 return mService.switchUser(admin, userHandle);
4801 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004802 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04004803 }
4804 }
4805
4806 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004807 * Retrieves the application restrictions for a given target application running in the calling
4808 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004809 * <p>
4810 * The caller must be a profile or device owner on that user, or the package allowed to manage
4811 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4812 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01004813 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004814 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004815 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004816 * @param packageName The name of the package to fetch restricted settings of.
4817 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004818 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
4819 * {@link Bundle} if no restrictions have been set.
4820 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004821 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01004822 */
Esteban Talaverabf60f722015-12-10 16:26:44 +00004823 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Robin Lee66e5d962014-04-09 16:44:21 +01004824 if (mService != null) {
4825 try {
4826 return mService.getApplicationRestrictions(admin, packageName);
4827 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004828 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004829 }
4830 }
4831 return null;
4832 }
Amith Yamasanibe465322014-04-24 13:45:17 -07004833
4834 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004835 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004836 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004837 * The calling device admin must be a profile or device owner; if it is not, a security
4838 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004839 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4841 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
4842 * for the list of keys.
4843 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07004844 */
Robin Lee25e26452015-06-02 09:56:29 -07004845 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004846 if (mService != null) {
4847 try {
4848 mService.setUserRestriction(admin, key, true);
4849 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004850 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004851 }
4852 }
4853 }
4854
4855 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004856 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07004857 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004858 * The calling device admin must be a profile or device owner; if it is not, a security
4859 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07004860 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4862 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
4863 * for the list of keys.
4864 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07004865 */
Robin Lee25e26452015-06-02 09:56:29 -07004866 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Amith Yamasanibe465322014-04-24 13:45:17 -07004867 if (mService != null) {
4868 try {
4869 mService.setUserRestriction(admin, key, false);
4870 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004871 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07004872 }
4873 }
4874 }
Adam Connors010cfd42014-04-16 12:48:13 +01004875
4876 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004877 * Called by a profile or device owner to get user restrictions set with
4878 * {@link #addUserRestriction(ComponentName, String)}.
4879 * <p>
4880 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004881 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004882 * {@link UserManager#getUserRestrictions()}.
4883 *
4884 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004885 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004886 */
4887 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004888 return getUserRestrictions(admin, myUserId());
4889 }
4890
4891 /** @hide per-user version */
4892 public Bundle getUserRestrictions(@NonNull ComponentName admin, int userHandle) {
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004893 Bundle ret = null;
4894 if (mService != null) {
4895 try {
Sudheer Shanka1c277a52015-11-11 21:58:24 +00004896 ret = mService.getUserRestrictions(admin, userHandle);
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004897 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004898 throw e.rethrowFromSystemServer();
Makoto Onuki3a3092f2015-10-30 11:07:51 -07004899 }
4900 }
4901 return ret == null ? new Bundle() : ret;
4902 }
4903
4904 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004905 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
4906 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04004907 *
4908 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004909 * @param packageName The name of the package to hide or unhide.
4910 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004911 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004912 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004913 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04004914 */
Robin Lee25e26452015-06-02 09:56:29 -07004915 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004916 boolean hidden) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004917 if (mService != null) {
4918 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004919 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04004920 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004921 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004922 }
4923 }
4924 return false;
4925 }
4926
4927 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004928 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04004929 *
4930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004931 * @param packageName The name of the package to retrieve the hidden status of.
4932 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004933 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04004934 */
Robin Lee25e26452015-06-02 09:56:29 -07004935 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Julia Reynolds966881e2014-05-14 12:23:08 -04004936 if (mService != null) {
4937 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07004938 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04004939 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004940 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04004941 }
4942 }
4943 return false;
4944 }
4945
4946 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05004947 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004948 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004949 *
4950 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08004951 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004952 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00004953 */
Robin Lee25e26452015-06-02 09:56:29 -07004954 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Adam Connors655be2a2014-07-14 09:01:25 +00004955 if (mService != null) {
4956 try {
4957 mService.enableSystemApp(admin, packageName);
4958 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004959 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004960 }
4961 }
4962 }
4963
4964 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004965 * Called by profile or device owners to re-enable system apps by intent that were disabled by
4966 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00004967 *
4968 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4969 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004970 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00004971 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004972 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00004973 */
Robin Lee25e26452015-06-02 09:56:29 -07004974 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Adam Connors655be2a2014-07-14 09:01:25 +00004975 if (mService != null) {
4976 try {
4977 return mService.enableSystemAppWithIntent(admin, intent);
4978 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004979 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00004980 }
4981 }
4982 return 0;
4983 }
4984
4985 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00004986 * Called by a device owner or profile owner to disable account management for a specific type
4987 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004988 * <p>
4989 * The calling device admin must be a device owner or profile owner. If it is not, a security
4990 * exception will be thrown.
4991 * <p>
4992 * When account management is disabled for an account type, adding or removing an account of
4993 * that type will not be possible.
4994 * <p>
4995 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00004996 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
4997 * management for a specific type is disabled.
4998 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01004999 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5000 * @param accountType For which account management is disabled or enabled.
5001 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005002 * enabled (false).
5003 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005004 */
Robin Lee25e26452015-06-02 09:56:29 -07005005 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005006 boolean disabled) {
5007 if (mService != null) {
5008 try {
5009 mService.setAccountManagementDisabled(admin, accountType, disabled);
5010 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005011 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005012 }
5013 }
5014 }
5015
5016 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005017 * Gets the array of accounts for which account management is disabled by the profile owner.
5018 *
5019 * <p> Account management can be disabled/enabled by calling
5020 * {@link #setAccountManagementDisabled}.
5021 *
5022 * @return a list of account types for which account management has been disabled.
5023 *
5024 * @see #setAccountManagementDisabled
5025 */
5026 public String[] getAccountTypesWithManagementDisabled() {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005027 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005028 }
5029
5030 /**
5031 * @see #getAccountTypesWithManagementDisabled()
5032 * @hide
5033 */
5034 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005035 if (mService != null) {
5036 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005037 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005038 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005039 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005040 }
5041 }
5042
5043 return null;
5044 }
justinzhang511e0d82014-03-24 16:09:24 -04005045
5046 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005047 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005048 * <p>
5049 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5050 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5051 * package list results in locked tasks belonging to those packages to be finished. This
5052 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005053 *
Jason Monkd7b86212014-06-16 13:15:38 -04005054 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005055 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005056 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005057 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005058 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5059 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005060 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005061 */
Robin Lee25e26452015-06-02 09:56:29 -07005062 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005063 throws SecurityException {
justinzhang511e0d82014-03-24 16:09:24 -04005064 if (mService != null) {
5065 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005066 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005067 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005068 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005069 }
5070 }
5071 }
5072
5073 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005074 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005075 *
5076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005077 * @hide
5078 */
Robin Lee25e26452015-06-02 09:56:29 -07005079 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
justinzhang511e0d82014-03-24 16:09:24 -04005080 if (mService != null) {
5081 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005082 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005083 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005084 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005085 }
5086 }
5087 return null;
5088 }
5089
5090 /**
5091 * This function lets the caller know whether the given component is allowed to start the
5092 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005093 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005094 */
Jason Monkd7b86212014-06-16 13:15:38 -04005095 public boolean isLockTaskPermitted(String pkg) {
justinzhang511e0d82014-03-24 16:09:24 -04005096 if (mService != null) {
5097 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005098 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005099 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005100 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005101 }
5102 }
5103 return false;
5104 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005105
5106 /**
5107 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5108 * of the setting is in the correct form for the setting type should be performed by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005109 * <p>
5110 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005111 * <ul>
5112 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5113 * <li>{@link Settings.Global#AUTO_TIME}</li>
5114 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005115 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005116 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005117 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005118 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5119 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5120 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5121 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5122 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005123 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005124 * <p>
5125 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005126 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005127 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5128 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5129 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005130 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005131 * <li>{@link Settings.Global#MODE_RINGER}. Use
5132 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005133 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005134 * <li>{@link Settings.Global#WIFI_ON}. Use
5135 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005136 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005137 *
5138 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5139 * @param setting The name of the setting to update.
5140 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005141 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005142 */
Robin Lee25e26452015-06-02 09:56:29 -07005143 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005144 if (mService != null) {
5145 try {
5146 mService.setGlobalSetting(admin, setting, value);
5147 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005148 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005149 }
5150 }
5151 }
5152
5153 /**
5154 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5155 * that the value of the setting is in the correct form for the setting type should be performed
5156 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005157 * <p>
5158 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005159 * <ul>
5160 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005161 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005162 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5163 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005164 * <p>
5165 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005166 * <ul>
5167 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5168 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005169 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5171 * @param setting The name of the setting to update.
5172 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005173 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005174 */
Robin Lee25e26452015-06-02 09:56:29 -07005175 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Julia Reynoldsda551652014-05-14 17:15:16 -04005176 if (mService != null) {
5177 try {
5178 mService.setSecureSetting(admin, setting, value);
5179 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005180 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005181 }
5182 }
5183 }
5184
Amith Yamasanif20d6402014-05-24 15:34:37 -07005185 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005186 * Designates a specific service component as the provider for making permission requests of a
5187 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005188 * <p/>
5189 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005190 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005191 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005192 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005193 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5194 * provider previously assigned.
5195 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005196 */
Robin Lee25e26452015-06-02 09:56:29 -07005197 public void setRestrictionsProvider(@NonNull ComponentName admin,
5198 @Nullable ComponentName provider) {
Amith Yamasanif20d6402014-05-24 15:34:37 -07005199 if (mService != null) {
5200 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005201 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005202 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005203 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005204 }
5205 }
5206 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005207
5208 /**
5209 * Called by profile or device owners to set the master volume mute on or off.
5210 *
5211 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5212 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005213 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005214 */
Robin Lee25e26452015-06-02 09:56:29 -07005215 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005216 if (mService != null) {
5217 try {
5218 mService.setMasterVolumeMuted(admin, on);
5219 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005220 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005221 }
5222 }
5223 }
5224
5225 /**
5226 * Called by profile or device owners to check whether the master volume mute is on or off.
5227 *
5228 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5229 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005230 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005231 */
Robin Lee25e26452015-06-02 09:56:29 -07005232 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Julia Reynolds4a21b252014-06-04 11:11:43 -04005233 if (mService != null) {
5234 try {
5235 return mService.isMasterVolumeMuted(admin);
5236 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005237 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005238 }
5239 }
5240 return false;
5241 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005242
5243 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005244 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005245 *
5246 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5247 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005248 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005249 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005250 */
Robin Lee25e26452015-06-02 09:56:29 -07005251 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005252 boolean uninstallBlocked) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005253 if (mService != null) {
5254 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005255 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005256 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005257 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005258 }
5259 }
5260 }
5261
5262 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005263 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005264 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005265 * <p>
5266 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005267 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5268 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5269 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005270 *
Robin Lee25e26452015-06-02 09:56:29 -07005271 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005272 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005273 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005274 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005275 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005276 */
Robin Lee25e26452015-06-02 09:56:29 -07005277 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Kenny Guyc13053b2014-05-29 14:17:17 +01005278 if (mService != null) {
5279 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005280 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005281 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005282 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005283 }
5284 }
5285 return false;
5286 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005287
5288 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005289 * Called by the profile owner of a managed profile to enable widget providers from a given
5290 * package to be available in the parent profile. As a result the user will be able to add
5291 * widgets from the white-listed package running under the profile to a widget host which runs
5292 * under the parent profile, for example the home screen. Note that a package may have zero or
5293 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005294 * <p>
5295 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005296 *
5297 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5298 * @param packageName The package from which widget providers are white-listed.
5299 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005300 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005301 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5302 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5303 */
Robin Lee25e26452015-06-02 09:56:29 -07005304 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005305 if (mService != null) {
5306 try {
5307 return mService.addCrossProfileWidgetProvider(admin, packageName);
5308 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005309 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005310 }
5311 }
5312 return false;
5313 }
5314
5315 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005316 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005317 * package to be available in the parent profile. For this method to take effect the package
5318 * should have been added via
5319 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005320 * <p>
5321 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005322 *
5323 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005324 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005325 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005326 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005327 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5328 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5329 */
Esteban Talavera62399912016-01-11 15:37:55 +00005330 public boolean removeCrossProfileWidgetProvider(
5331 @NonNull ComponentName admin, String packageName) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005332 if (mService != null) {
5333 try {
5334 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5335 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005336 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005337 }
5338 }
5339 return false;
5340 }
5341
5342 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005343 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005344 * available in the parent profile.
5345 *
5346 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5347 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005348 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5349 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005350 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005351 */
Robin Lee25e26452015-06-02 09:56:29 -07005352 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Svetoslav976e8bd2014-07-16 15:12:03 -07005353 if (mService != null) {
5354 try {
5355 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5356 if (providers != null) {
5357 return providers;
5358 }
5359 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005360 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005361 }
5362 }
5363 return Collections.emptyList();
5364 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005365
5366 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005367 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005368 *
5369 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5370 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005371 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005372 */
Robin Lee25e26452015-06-02 09:56:29 -07005373 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005374 try {
5375 mService.setUserIcon(admin, icon);
5376 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005377 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005378 }
5379 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005380
5381 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005382 * Called by device owners to set a local system update policy. When a new policy is set,
5383 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005384 *
Robin Lee25e26452015-06-02 09:56:29 -07005385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005386 * components in the device owner package can set system update policies and the most
5387 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005388 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005389 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005390 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005391 */
Robin Lee25e26452015-06-02 09:56:29 -07005392 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005393 if (mService != null) {
5394 try {
Robin Lee25e26452015-06-02 09:56:29 -07005395 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005396 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005397 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005398 }
5399 }
5400 }
5401
5402 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005403 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005404 *
Robin Lee25e26452015-06-02 09:56:29 -07005405 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005406 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005407 public SystemUpdatePolicy getSystemUpdatePolicy() {
Rubin Xu8027a4f2015-03-10 17:52:37 +00005408 if (mService != null) {
5409 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005410 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005411 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005412 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005413 }
5414 }
5415 return null;
5416 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005417
5418 /**
5419 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005420 * <p>
5421 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5422 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5423 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5424 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005425 *
5426 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005427 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005428 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005429 * place. {@code true} otherwise.
5430 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005431 */
Robin Lee25e26452015-06-02 09:56:29 -07005432 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franze36087e2015-04-07 16:40:34 +01005433 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005434 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005435 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005436 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005437 }
5438 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005439
5440 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005441 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005442 * notifications, quick settings and other screen overlays that allow escaping from a single use
5443 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005444 *
5445 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005446 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005447 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5448 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005449 */
Robin Lee25e26452015-06-02 09:56:29 -07005450 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzea2ec972015-03-16 17:18:09 +00005451 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005452 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005453 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005454 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005455 }
5456 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005457
5458 /**
5459 * Callable by the system update service to notify device owners about pending updates.
5460 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5461 * permission.
5462 *
5463 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5464 * when the current pending update was first available. -1 if no update is available.
5465 * @hide
5466 */
5467 @SystemApi
5468 public void notifyPendingSystemUpdate(long updateReceivedTime) {
5469 if (mService != null) {
5470 try {
5471 mService.notifyPendingSystemUpdate(updateReceivedTime);
5472 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005473 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005474 }
5475 }
5476 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005477
5478 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005479 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005480 * requests by applications. The policy can allow for normal operation which prompts the user to
5481 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5482 * by an application. This also applies to new permissions declared by app updates. When a
5483 * permission is denied or granted this way, the effect is equivalent to setting the permission
5484 * grant state via {@link #setPermissionGrantState}.
5485 * <p/>
5486 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005487 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005488 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005489 * @param admin Which profile or device owner this request is associated with.
5490 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005491 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5492 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005493 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005494 */
Robin Lee25e26452015-06-02 09:56:29 -07005495 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005496 try {
5497 mService.setPermissionPolicy(admin, policy);
5498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005499 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005500 }
5501 }
5502
5503 /**
5504 * Returns the current runtime permission policy set by the device or profile owner. The
5505 * default is {@link #PERMISSION_POLICY_PROMPT}.
5506 * @param admin Which profile or device owner this request is associated with.
5507 * @return the current policy for future permission requests.
5508 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005509 public int getPermissionPolicy(ComponentName admin) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005510 try {
5511 return mService.getPermissionPolicy(admin);
5512 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005513 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005514 }
5515 }
5516
5517 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005518 * Sets the grant state of a runtime permission for a specific application. The state can be
5519 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5520 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5521 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5522 * the permission is granted and the user cannot manage it through the UI. This might affect all
5523 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005524 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005525 * <p/>
5526 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5527 * the permission. It retains the previous grant, if any.
5528 * <p/>
5529 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005530 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005531 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005532 * @param admin Which profile or device owner this request is associated with.
5533 * @param packageName The application to grant or revoke a permission to.
5534 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005535 * @param grantState The permission grant state which is one of
5536 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5537 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005538 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005539 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005540 * @see #PERMISSION_GRANT_STATE_DENIED
5541 * @see #PERMISSION_GRANT_STATE_DEFAULT
5542 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005543 */
Robin Lee25e26452015-06-02 09:56:29 -07005544 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005545 String permission, int grantState) {
Amith Yamasanid49489b2015-04-28 14:00:26 -07005546 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005547 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005548 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005549 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005550 }
5551 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005552
5553 /**
5554 * Returns the current grant state of a runtime permission for a specific application.
5555 *
5556 * @param admin Which profile or device owner this request is associated with.
5557 * @param packageName The application to check the grant state for.
5558 * @param permission The permission to check for.
5559 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005560 * has not set a grant state, the return value is
5561 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5562 * permission is currently granted for the package.
5563 * <p/>
5564 * If a grant state was set by the profile or device owner, then the return value will
5565 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5566 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5567 * currently denied or granted.
5568 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005569 * @see #setPermissionGrantState(ComponentName, String, String, int)
5570 * @see PackageManager#checkPermission(String, String)
5571 */
Robin Lee25e26452015-06-02 09:56:29 -07005572 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005573 String permission) {
5574 try {
5575 return mService.getPermissionGrantState(admin, packageName, permission);
5576 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005577 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005578 }
5579 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005580
5581 /**
5582 * Returns if provisioning a managed profile or device is possible or not.
5583 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5584 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005585 * @return if provisioning a managed profile or device is possible or not.
5586 * @throws IllegalArgumentException if the supplied action is not valid.
5587 */
5588 public boolean isProvisioningAllowed(String action) {
5589 try {
5590 return mService.isProvisioningAllowed(action);
5591 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005592 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005593 }
5594 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005595
5596 /**
5597 * @hide
5598 * Return if this user is a managed profile of another user. An admin can become the profile
5599 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
5600 * user with {@link #ACTION_PROVISION_MANAGED_USER}.
5601 * @param admin Which profile owner this request is associated with.
5602 * @return if this user is a managed profile of another user.
5603 */
5604 public boolean isManagedProfile(@NonNull ComponentName admin) {
5605 try {
5606 return mService.isManagedProfile(admin);
5607 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005608 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005609 }
5610 }
5611
5612 /**
5613 * @hide
5614 * Return if this user is a system-only user. An admin can manage a device from a system only
5615 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5616 * @param admin Which device owner this request is associated with.
5617 * @return if this user is a system-only user.
5618 */
5619 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5620 try {
5621 return mService.isSystemOnlyUser(admin);
5622 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005623 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005624 }
5625 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005626
5627 /**
5628 * Called by device owner to get the MAC address of the Wi-Fi device.
5629 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005630 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005631 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5632 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5633 * <p>
5634 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5635 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005636 */
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005637 public String getWifiMacAddress(@NonNull ComponentName admin) {
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005638 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005639 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005640 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005641 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005642 }
5643 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005644
5645 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005646 * Called by device owner to reboot the device. If there is an ongoing call on the device,
5647 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005648 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005649 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005650 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005651 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005652 */
5653 public void reboot(@NonNull ComponentName admin) {
5654 try {
5655 mService.reboot(admin);
5656 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005657 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005658 }
5659 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005660
5661 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005662 * Called by a device admin to set the short support message. This will be displayed to the user
5663 * in settings screens where funtionality has been disabled by the admin. The message should be
5664 * limited to a short statement such as "This setting is disabled by your administrator. Contact
5665 * someone@example.com for support." If the message is longer than 200 characters it may be
5666 * truncated.
5667 * <p>
5668 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005669 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5670 * and set a new version of this string accordingly.
5671 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005672 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005674 * @param message Short message to be displayed to the user in settings or null to clear the
5675 * existing message.
5676 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005677 */
5678 public void setShortSupportMessage(@NonNull ComponentName admin,
5679 @Nullable String message) {
5680 if (mService != null) {
5681 try {
5682 mService.setShortSupportMessage(admin, message);
5683 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005684 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005685 }
5686 }
5687 }
5688
5689 /**
5690 * Called by a device admin to get the short support message.
5691 *
5692 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005693 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)} or null if
5694 * no message has been set.
5695 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005696 */
5697 public String getShortSupportMessage(@NonNull ComponentName admin) {
5698 if (mService != null) {
5699 try {
5700 return mService.getShortSupportMessage(admin);
5701 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005702 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005703 }
5704 }
5705 return null;
5706 }
5707
5708 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005709 * Called by a device admin to set the long support message. This will be displayed to the user
5710 * in the device administators settings screen.
5711 * <p>
5712 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005713 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5714 * and set a new version of this string accordingly.
5715 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005716 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005717 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005718 * @param message Long message to be displayed to the user in settings or null to clear the
5719 * existing message.
5720 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005721 */
5722 public void setLongSupportMessage(@NonNull ComponentName admin,
5723 @Nullable String message) {
5724 if (mService != null) {
5725 try {
5726 mService.setLongSupportMessage(admin, message);
5727 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005728 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005729 }
5730 }
5731 }
5732
5733 /**
5734 * Called by a device admin to get the long support message.
5735 *
5736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005737 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)} or null if
5738 * no message has been set.
5739 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005740 */
5741 public String getLongSupportMessage(@NonNull ComponentName admin) {
5742 if (mService != null) {
5743 try {
5744 return mService.getLongSupportMessage(admin);
5745 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005746 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005747 }
5748 }
5749 return null;
5750 }
5751
5752 /**
5753 * Called by the system to get the short support message.
5754 *
5755 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5756 * @param userHandle user id the admin is running as.
5757 * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
5758 *
5759 * @hide
5760 */
5761 public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5762 if (mService != null) {
5763 try {
5764 return mService.getShortSupportMessageForUser(admin, userHandle);
5765 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005766 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005767 }
5768 }
5769 return null;
5770 }
5771
5772
5773 /**
5774 * Called by the system to get the long support message.
5775 *
5776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5777 * @param userHandle user id the admin is running as.
5778 * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
5779 *
5780 * @hide
5781 */
5782 public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
5783 if (mService != null) {
5784 try {
5785 return mService.getLongSupportMessageForUser(admin, userHandle);
5786 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005787 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00005788 }
5789 }
5790 return null;
5791 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005792
5793 /**
Esteban Talavera62399912016-01-11 15:37:55 +00005794 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
5795 * whose calls act on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005796 * <p>
5797 * Note only some methods will work on the parent Manager.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005798 *
5799 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005800 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005801 */
5802 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
5803 try {
5804 if (!mService.isManagedProfile(admin)) {
5805 throw new SecurityException("The current user does not have a parent profile.");
5806 }
5807 return new DevicePolicyManager(mContext, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005809 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005810 }
5811 }
5812
5813 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005814 * Called by device owner to control the security logging feature. Logging can only be
5815 * enabled on single user devices where the sole user is managed by the device owner.
5816 *
5817 * <p> Security logs contain various information intended for security auditing purposes.
5818 * See {@link SecurityEvent} for details.
5819 *
5820 * <p>There must be only one user on the device, managed by the device owner.
5821 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005822 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005823 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00005824 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005825 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00005826 * @see #retrieveSecurityLogs
5827 */
5828 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
5829 try {
5830 mService.setSecurityLoggingEnabled(admin, enabled);
5831 } catch (RemoteException re) {
5832 throw re.rethrowFromSystemServer();
5833 }
5834 }
5835
5836 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005837 * Return whether security logging is enabled or not by the device owner.
5838 *
5839 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
5840 * thrown.
5841 *
5842 * @param admin Which device owner this request is associated with.
5843 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
5844 * @throws SecurityException if {@code admin} is not a device owner.
5845 */
5846 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005847 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005848 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005849 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005850 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005851 }
5852 }
5853
5854 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00005855 * Called by device owner to retrieve all new security logging entries since the last call to
5856 * this API after device boots.
5857 *
5858 * <p> Access to the logs is rate limited and it will only return new logs after the device
5859 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
5860 *
5861 * <p>There must be only one user on the device, managed by the device owner.
5862 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005863 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005864 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00005865 * @return the new batch of security logs which is a list of {@link SecurityEvent},
5866 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005867 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005868 */
Michal Karpinski6235a942016-03-15 12:07:23 +00005869 public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005870 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005871 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005872 if (list != null) {
5873 return list.getList();
5874 } else {
5875 // Rate limit exceeded.
5876 return null;
5877 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005878 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005879 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00005880 }
5881 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00005882
5883 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00005884 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
5885 * profile.
5886 *
5887 * @hide
5888 */
5889 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
5890 mContext.checkSelfPermission(
5891 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
5892 if (!uInfo.isManagedProfile()) {
5893 throw new SecurityException("The user " + uInfo.id
5894 + " does not have a parent profile.");
5895 }
5896 return new DevicePolicyManager(mContext, true);
5897 }
5898
5899 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005900 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005901 * <p>
5902 * <strong> The device logs are retrieved from a RAM region which is not guaranteed to be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005903 * corruption-free during power cycles, due to hardware variations and limitations. As a result,
5904 * this API is provided as best-effort and the returned logs may contain corrupted
5905 * data. </strong>
5906 * <p>
5907 * There must be only one user on the device, managed by the device owner. Otherwise a
5908 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00005909 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005910 * @param admin Which device owner this request is associated with.
5911 * @return Device logs from before the latest reboot of the system.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005912 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005913 */
Michal Karpinski6235a942016-03-15 12:07:23 +00005914 public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) {
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005915 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00005916 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005917 return list.getList();
5918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005919 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00005920 }
5921 }
5922
5923 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005924 * Called by a profile owner of a managed profile to set the color used for customization. This
5925 * color is used as background color of the confirm credentials screen for that user. The
5926 * default color is {@link android.graphics.Color#GRAY}.
5927 * <p>
5928 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00005929 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
5930 *
5931 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5932 * @param color The 32bit representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005933 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00005934 */
5935 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
5936 try {
5937 mService.setOrganizationColor(admin, color);
5938 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005939 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005940 }
5941 }
5942
5943 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005944 * @hide
5945 *
5946 * Sets the color used for customization.
5947 *
5948 * @param color The 32bit representation of the color to be used.
5949 * @param userId which user to set the color to.
5950 * @RequiresPermission(allOf = {
5951 * Manifest.permission.MANAGE_USERS,
5952 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5953 */
5954 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
5955 try {
5956 mService.setOrganizationColorForUser(color, userId);
5957 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005958 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00005959 }
5960 }
5961
5962 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00005963 * Called by a profile owner of a managed profile to retrieve the color used for customization.
5964 * This color is used as background color of the confirm credentials screen for that user.
5965 *
5966 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5967 * @return The 32bit representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005968 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00005969 */
5970 public int getOrganizationColor(@NonNull ComponentName admin) {
5971 try {
5972 return mService.getOrganizationColor(admin);
5973 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005974 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005975 }
5976 }
5977
5978 /**
5979 * @hide
5980 * Retrieve the customization color for a given user.
5981 *
5982 * @param userHandle The user id of the user we're interested in.
5983 * @return The 32bit representation of the color to be used.
5984 */
5985 public int getOrganizationColorForUser(int userHandle) {
5986 try {
5987 return mService.getOrganizationColorForUser(userHandle);
5988 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005989 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00005990 }
5991 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01005992
5993 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005994 * Called by a profile owner of a managed profile to set the name of the organization under
5995 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005996 * <p>
5997 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005998 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5999 * and set a new version of this string accordingly.
6000 *
6001 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6002 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006003 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006004 */
6005 public void setOrganizationName(@NonNull ComponentName admin, @Nullable String title) {
6006 try {
6007 mService.setOrganizationName(admin, title);
6008 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006009 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006010 }
6011 }
6012
6013 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006014 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6015 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006016 *
6017 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6018 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006019 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006020 */
6021 public String getOrganizationName(@NonNull ComponentName admin) {
6022 try {
6023 return mService.getOrganizationName(admin);
6024 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006025 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006026 }
6027 }
6028
6029 /**
6030 * Retrieve the default title message used in the confirm credentials screen for a given user.
6031 *
6032 * @param userHandle The user id of the user we're interested in.
6033 * @return The organization name or {@code null} if none is set.
6034 *
6035 * @hide
6036 */
6037 public String getOrganizationNameForUser(int userHandle) {
6038 try {
6039 return mService.getOrganizationNameForUser(userHandle);
6040 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006041 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006042 }
6043 }
6044
6045 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006046 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6047 * return {@link #STATE_USER_UNMANAGED}
6048 * @hide
6049 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006050 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006051 @UserProvisioningState
6052 public int getUserProvisioningState() {
6053 if (mService != null) {
6054 try {
6055 return mService.getUserProvisioningState();
6056 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006057 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006058 }
6059 }
6060 return STATE_USER_UNMANAGED;
6061 }
6062
6063 /**
6064 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6065 *
6066 * @param state to store
6067 * @param userHandle for user
6068 * @hide
6069 */
6070 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6071 if (mService != null) {
6072 try {
6073 mService.setUserProvisioningState(state, userHandle);
6074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006075 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006076 }
6077 }
6078 }
6079
6080 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006081 * @hide
6082 * Indicates the entity that controls the device or profile owner. A user/profile is considered
6083 * affiliated if it is managed by the same entity as the device.
6084 *
6085 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
6086 * user/profile is considered affiliated if the following conditions are both met:
6087 * <ul>
6088 * <li>The device owner and the user's/profile's profile owner have called this method,
6089 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
6090 * and a profile owner intersect, they must have come from the same source, which means that
6091 * the device owner and profile owner are controlled by the same entity.</li>
6092 * <li>The device owner's and profile owner's package names are the same.</li>
6093 * </ul>
6094 *
6095 * @param admin Which profile or device owner this request is associated with.
6096 * @param ids A set of opaque affiliation ids.
6097 */
6098 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
6099 try {
6100 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
6101 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006102 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006103 }
6104 }
6105
6106 /**
6107 * @hide
6108 * Returns whether this user/profile is affiliated with the device. See
6109 * {@link #setAffiliationIds} for the definition of affiliation.
6110 *
6111 * @return whether this user/profile is affiliated with the device.
6112 */
6113 public boolean isAffiliatedUser() {
6114 try {
6115 return mService != null && mService.isAffiliatedUser();
6116 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006117 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006118 }
6119 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006120
6121 /**
6122 * @hide
6123 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6124 * to be started
6125 * @param packageName the package to check for
6126 * @return whether the uninstall intent for {@code packageName} is pending
6127 */
6128 public boolean isUninstallInQueue(String packageName) {
6129 try {
6130 return mService.isUninstallInQueue(packageName);
6131 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006132 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006133 }
6134 }
6135
6136 /**
6137 * @hide
6138 * @param packageName the package containing active DAs to be uninstalled
6139 */
6140 public void uninstallPackageWithActiveAdmins(String packageName) {
6141 try {
6142 mService.uninstallPackageWithActiveAdmins(packageName);
6143 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006144 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006145 }
6146 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006147}