blob: 4ddcfe546f95ca2f22b3d47e29dc2dc95d4ed6e9 [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;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070027import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040028import android.app.Activity;
Michal Karpinski6235a942016-03-15 12:07:23 +000029import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080030import android.content.ComponentName;
31import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010032import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000033import android.content.IntentFilter;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000035import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000036import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000037import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050038import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040039import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000040import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010041import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070042import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000043import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080044import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080045import android.os.RemoteException;
46import android.os.ServiceManager;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070047import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040048import android.os.UserManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060049import android.os.ServiceManager.ServiceNotFoundException;
Ricky Wai494b95d2015-11-20 16:07:15 +000050import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000051import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010052import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070053import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000054import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080055import android.util.Log;
56
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070057import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040058import com.android.org.conscrypt.TrustedCertificateStore;
59
60import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080061import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000062import java.lang.annotation.Retention;
63import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070064import java.net.InetSocketAddress;
65import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010066import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000067import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010068import java.security.PrivateKey;
69import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040070import java.security.cert.CertificateException;
71import java.security.cert.CertificateFactory;
72import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010073import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000074import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070075import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000076import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070077import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080078import java.util.List;
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +010079import java.util.Set;
Dianne Hackbornd6847842010-01-12 18:14:19 -080080
81/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000082 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070083 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
84 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
85 * device owner. A given method is accessible to all device administrators unless the documentation
86 * for that method specifies that it is restricted to either device or profile owners. Any
87 * application calling an api may only pass as an argument a device administrator component it
88 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080089 * <div class="special reference">
90 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070091 * <p>
92 * For more information about managing policies for device administration, read the <a href=
93 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
94 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080095 */
96public class DevicePolicyManager {
97 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080098
99 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000101 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700102
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600103 /** @hide */
104 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
105 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800106 }
107
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800108 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600110 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
111 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700112 mContext = context;
113 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000114 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700115 }
116
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 /** @hide test will override it. */
118 @VisibleForTesting
119 protected int myUserId() {
120 return UserHandle.myUserId();
121 }
122
Dianne Hackbornd6847842010-01-12 18:14:19 -0800123 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000124 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100126 * <p>A managed profile allows data separation for example for the usage of a
127 * device as a personal and corporate device. The user which provisioning is started from and
128 * the managed profile share a launcher.
129 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800130 * <p>This intent will typically be sent by a mobile device management application (MDM).
131 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
132 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100133 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000134 * <p>It is possible to check if provisioning is allowed or not by querying the method
135 * {@link #isProvisioningAllowed(String)}.
136 *
137 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000138 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700139 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000140 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
141 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000142 *
Benjamin Franzea956242016-03-21 15:45:56 +0000143 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000144 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000145 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
146 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
147 * {@link android.os.Build.VERSION_CODES#N}</li>
148 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
149 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
150 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000151 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000152 *
Benjamin Franzea956242016-03-21 15:45:56 +0000153 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000154 * in the provisioning intent. The
155 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
156 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
157 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100158 *
Benjamin Franzea956242016-03-21 15:45:56 +0000159 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100160 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100161 *
162 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
163 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
164 * the provisioning flow was successful, although this doesn't guarantee the full flow will
165 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
166 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000167 */
168 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
169 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100170 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000171
172 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000173 * Activity action: Starts the provisioning flow which sets up a managed user.
174 *
175 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800176 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000177 * owner who has full control over the user. Provisioning can only happen before user setup has
178 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
179 * allowed.
180 *
Benjamin Franzea956242016-03-21 15:45:56 +0000181 * <p>The intent contains the following extras:
182 * <ul>
183 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
184 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
185 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
186 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
187 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
188 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000189 *
Benjamin Franzea956242016-03-21 15:45:56 +0000190 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000191 *
192 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
193 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
194 * the provisioning flow was successful, although this doesn't guarantee the full flow will
195 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
196 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000197 *
198 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000199 */
200 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
201 public static final String ACTION_PROVISION_MANAGED_USER
202 = "android.app.action.PROVISION_MANAGED_USER";
203
204 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100205 * Activity action: Starts the provisioning flow which sets up a managed device.
206 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
207 *
208 * <p> During device owner provisioning a device admin app is set as the owner of the device.
209 * A device owner has full control over the device. The device owner can not be modified by the
210 * user.
211 *
212 * <p> A typical use case would be a device that is owned by a company, but used by either an
213 * employee or client.
214 *
215 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000216 * It is possible to check if provisioning is allowed or not by querying the method
217 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100218 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000219 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100220 * <ul>
221 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
222 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
223 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100224 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000225 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000226 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100227 * </ul>
228 *
Benjamin Franzea956242016-03-21 15:45:56 +0000229 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100230 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
231 * device owner.
232 *
Benjamin Franzea956242016-03-21 15:45:56 +0000233 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100234 *
Alan Treadway4582f812015-07-28 11:49:35 +0100235 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
236 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
237 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
238 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 */
240 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
241 public static final String ACTION_PROVISION_MANAGED_DEVICE
242 = "android.app.action.PROVISION_MANAGED_DEVICE";
243
244 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000245 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000246 *
247 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
248 * the device. A device owner has full control over the device. The device owner can not be
249 * modified by the user and the only way of resetting the device is via factory reset.
250 *
251 * <p>A typical use case would be a device that is owned by a company, but used by either an
252 * employee or client.
253 *
254 * <p>The provisioning message should be sent to an unprovisioned device.
255 *
256 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
257 * by a privileged app with the permission
258 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
259 *
260 * <p>The provisioning intent contains the following properties:
261 * <ul>
262 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
263 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
264 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
265 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
266 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
267 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
268 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
269 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
270 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
271 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
272 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
273 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
274 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
275 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
276 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
278 *
279 * @hide
280 */
281 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
282 @SystemApi
283 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
284 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
285
286 /**
287 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000288 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
289 *
290 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
291 * management state that is distinct from that reached by
292 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
293 * user, and only has control over device-wide policies, not individual users and their data.
294 * The primary benefit is that multiple non-system users are supported when provisioning using
295 * this form of device management.
296 *
Benjamin Franzea956242016-03-21 15:45:56 +0000297 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000298 * A device owner has full control over the device. The device owner can not be modified by the
299 * user.
300 *
Benjamin Franzea956242016-03-21 15:45:56 +0000301 * <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 +0000302 * employee or client.
303 *
Benjamin Franzea956242016-03-21 15:45:56 +0000304 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000305 * It is possible to check if provisioning is allowed or not by querying the method
306 * {@link #isProvisioningAllowed(String)}.
307 *
308 * <p>The intent contains the following extras:
309 * <ul>
310 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
311 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
312 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
313 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000314 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
315 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000316 * </ul>
317 *
Benjamin Franzea956242016-03-21 15:45:56 +0000318 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000319 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
320 * device owner.
321 *
Benjamin Franzea956242016-03-21 15:45:56 +0000322 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000323 *
324 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
325 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
326 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
327 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
328 *
329 * @hide
330 */
331 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
332 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
333 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
334
335 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000336 * Activity action: Finalizes management provisioning, should be used after user-setup
337 * has been completed and {@link #getUserProvisioningState()} returns one of:
338 * <ul>
339 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
340 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
341 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
342 * </ul>
343 *
344 * @hide
345 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000346 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000347 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
348 public static final String ACTION_PROVISION_FINALIZATION
349 = "android.app.action.PROVISION_FINALIZATION";
350
351 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000352 * Action: Bugreport sharing with device owner has been accepted by the user.
353 *
354 * @hide
355 */
356 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
357 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
358
359 /**
360 * Action: Bugreport sharing with device owner has been declined by the user.
361 *
362 * @hide
363 */
364 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
365 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
366
367 /**
368 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
369 *
370 * @hide
371 */
372 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
373 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
374
375 /**
376 * Extra for shared bugreport's SHA-256 hash.
377 *
378 * @hide
379 */
380 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
381 "android.intent.extra.REMOTE_BUGREPORT_HASH";
382
383 /**
384 * Extra for remote bugreport notification shown type.
385 *
386 * @hide
387 */
388 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
389 "android.app.extra.bugreport_notification_type";
390
391 /**
392 * Notification type for a started remote bugreport flow.
393 *
394 * @hide
395 */
396 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
397
398 /**
399 * Notification type for a bugreport that has already been accepted to be shared, but is still
400 * being taken.
401 *
402 * @hide
403 */
404 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
405
406 /**
407 * Notification type for a bugreport that has been taken and can be shared or declined.
408 *
409 * @hide
410 */
411 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
412
413 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100414 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
415 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
416 *
417 * @hide
418 */
419 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
420
421 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100422 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100423 * allows a mobile device management application or NFC programmer application which starts
424 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100425 * <p>
426 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
427 * sends the intent to pass data to itself on the newly created profile.
428 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
429 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100430 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
431 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
432 * message should contain a stringified {@link java.util.Properties} instance, whose string
433 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
434 * management application after provisioning.
435 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100436 * <p>
437 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700438 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
439 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100440 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100441 */
442 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100443 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100444
445 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100446 * A String extra holding the package name of the mobile device management application that
447 * will be set as the profile owner or device owner.
448 *
449 * <p>If an application starts provisioning directly via an intent with action
450 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
451 * application that started provisioning. The package will be set as profile owner in that case.
452 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000453 * <p>This package is set as device owner when device owner provisioning is started by an NFC
454 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000455 *
456 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700457 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000458 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000459 * @see DeviceAdminReceiver
460 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100461 * supported, but only if there is only one device admin receiver in the package that requires
462 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000463 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000464 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000465 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100466 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000467
468 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000469 * A ComponentName extra indicating the device admin receiver of the mobile device management
470 * application that will be set as the profile owner or device owner and active admin.
471 *
472 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100473 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
474 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
475 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000476 *
477 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100478 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
479 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000480 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000481 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000482 *
483 * @see DeviceAdminReceiver
484 */
485 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
486 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
487
488 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000489 * An {@link android.accounts.Account} extra holding the account to migrate during managed
490 * profile provisioning. If the account supplied is present in the primary user, it will be
491 * copied, along with its credentials to the managed profile and removed from the primary user.
492 *
493 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
494 */
495
496 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
497 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
498
499 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100500 * A String extra that, holds the email address of the account which a managed profile is
501 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
502 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100503 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100504 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
505 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100506 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
507 * contains this extra, it is forwarded in the
508 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
509 * device management application that was set as the profile owner during provisioning.
510 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100511 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100512 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
513 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100514
515 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000516 * A integer extra indicating the predominant color to show during the provisioning.
517 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000518 *
519 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
520 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
521 */
522 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
523 "android.app.extra.PROVISIONING_MAIN_COLOR";
524
525 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000526 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700527 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000528 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100529 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
530 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000531 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000532 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
533 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000534
535 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100536 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
537 * will be set to.
538 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000539 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
540 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100541 */
542 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100543 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100544
545 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100546 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
547 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100548 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000549 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
550 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100551 */
552 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100553 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100554
555 /**
556 * A String extra holding the {@link java.util.Locale} that the device will be set to.
557 * Format: xx_yy, where xx is the language code, and yy the country code.
558 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000559 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
560 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100561 */
562 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100563 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100564
565 /**
566 * A String extra holding the ssid of the wifi network that should be used during nfc device
567 * owner provisioning for downloading the mobile device management application.
568 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000569 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
570 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100571 */
572 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100573 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100574
575 /**
576 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
577 * is hidden or not.
578 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000579 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
580 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100581 */
582 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100583 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100584
585 /**
586 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100587 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
588 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100589 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000590 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
591 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592 */
593 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100594 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100595
596 /**
597 * A String extra holding the password of the wifi network in
598 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
599 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000600 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
601 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602 */
603 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100604 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605
606 /**
607 * A String extra holding the proxy host for the wifi network in
608 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
609 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000610 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
611 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612 */
613 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100614 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100615
616 /**
617 * An int extra holding the proxy port for the wifi network in
618 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
619 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000620 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
621 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100622 */
623 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100624 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625
626 /**
627 * A String extra holding the proxy bypass for the wifi network in
628 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
629 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000630 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
631 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100632 */
633 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100634 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100635
636 /**
637 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
638 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
639 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000640 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
641 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100642 */
643 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100644 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100645
646 /**
647 * A String extra holding a url that specifies the download location of the device admin
648 * package. When not provided it is assumed that the device admin package is already installed.
649 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000650 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
651 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100652 */
653 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100654 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100655
656 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400657 * An int extra holding a minimum required version code for the device admin package. If the
658 * device admin is already installed on the device, it will only be re-downloaded from
659 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
660 * installed package is less than this version code.
661 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400662 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400663 * provisioning via an NFC bump.
664 */
665 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
666 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
667
668 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100669 * A String extra holding a http cookie header which should be used in the http request to the
670 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
671 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000672 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
673 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100674 */
675 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100676 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100677
678 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100679 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
680 * the file at download location specified in
681 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100682 *
Benjamin Franzea956242016-03-21 15:45:56 +0000683 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
684 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100685 * location. If the checksum doesn't match an error will be shown to the user and the user will
686 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100687 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000688 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
689 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100690 *
691 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
692 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700693 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100694 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100695 */
696 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100697 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100698
699 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100700 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100701 * android package archive at the download location specified in {@link
702 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
703 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100704 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100705 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
706 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
707 *
Benjamin Franzea956242016-03-21 15:45:56 +0000708 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
709 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100710 * the download location. If the checksum does not match an error will be shown to the user and
711 * the user will be asked to factory reset the device.
712 *
713 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
714 * provisioning via an NFC bump.
715 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100716 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
717 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100718
719 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000720 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
721 * has completed successfully.
722 *
723 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700724 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000725 *
Ying Wang7f38aab2015-02-20 11:50:09 -0800726 * <p>This intent will contain the extra {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE} which
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000727 * corresponds to the account requested to be migrated at provisioning time, if any.
728 */
729 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
730 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
731 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
732
733 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000734 * A boolean extra indicating whether device encryption can be skipped as part of device owner
735 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500736 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400737 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100738 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000739 *
740 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
741 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500742 */
743 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
744 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
745
746 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000747 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
748 * provisioning. If this extra is not passed, a default image will be shown.
749 * <h5>The following URI schemes are accepted:</h5>
750 * <ul>
751 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
752 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
753 * </ul>
754 *
755 * <p> It is the responsability of the caller to provide an image with a reasonable
756 * pixed density for the device.
757 *
758 * <p> If a content: URI is passed, the intent should have the flag
759 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
760 * {@link android.content.ClipData} of the intent too.
761 *
762 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
763 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
764 */
765 public static final String EXTRA_PROVISIONING_LOGO_URI =
766 "android.app.extra.PROVISIONING_LOGO_URI";
767
768 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000769 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
770 * during setup-wizard.
771 *
772 * <p>If unspecified, defaults to {@code true} to match the behavior in
773 * {@link android.os.Build.VERSION_CODES#M} and earlier.
774 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000775 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
776 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000777 *
778 * @hide
779 */
780 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
781 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
782
783 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000784 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100785 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400786 * <p>During device owner provisioning a device admin app is set as the owner of the device.
787 * A device owner has full control over the device. The device owner can not be modified by the
788 * user and the only way of resetting the device is if the device owner app calls a factory
789 * reset.
790 *
791 * <p> A typical use case would be a device that is owned by a company, but used by either an
792 * employee or client.
793 *
Benjamin Franzea956242016-03-21 15:45:56 +0000794 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100795 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000796 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100797 * contains the following properties:
798 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400799 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
800 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100801 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400802 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100803 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
804 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
805 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
806 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
807 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
808 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
809 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
810 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
811 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
812 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100813 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
814 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
815 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100816 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000817 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700818 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400819 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
820 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
821 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400822 */
823 public static final String MIME_TYPE_PROVISIONING_NFC
824 = "application/com.android.managedprovisioning";
825
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100826 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800827 * Activity action: ask the user to add a new device administrator to the system.
828 * The desired policy is the ComponentName of the policy in the
829 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
830 * bring the user through adding the device administrator to the system (or
831 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700832 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800833 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
834 * field to provide the user with additional explanation (in addition
835 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800836 *
837 * <p>If your administrator is already active, this will ordinarily return immediately (without
838 * user intervention). However, if your administrator has been updated and is requesting
839 * additional uses-policy flags, the user will be presented with the new list. New policies
840 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800841 */
842 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
843 public static final String ACTION_ADD_DEVICE_ADMIN
844 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700845
Dianne Hackbornd6847842010-01-12 18:14:19 -0800846 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700847 * @hide
848 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700849 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700850 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700851 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
852 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700853 * to remotely control restrictions on the user.
854 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800855 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700856 * result of whether or not the user approved the action. If approved, the result will
857 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
858 * as a profile owner.
859 *
860 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
861 * field to provide the user with additional explanation (in addition
862 * to your component's description) about what is being added.
863 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700864 * <p>If there is already a profile owner active or the caller is not a system app, the
865 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700866 */
867 @SystemApi
868 public static final String ACTION_SET_PROFILE_OWNER
869 = "android.app.action.SET_PROFILE_OWNER";
870
871 /**
872 * @hide
873 * Name of the profile owner admin that controls the user.
874 */
875 @SystemApi
876 public static final String EXTRA_PROFILE_OWNER_NAME
877 = "android.app.extra.PROFILE_OWNER_NAME";
878
879 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100880 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700881 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700882 *
Jim Miller284b62e2010-06-08 14:27:42 -0700883 * @hide
884 */
885 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
886 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
887
888 /**
Tony Mak1970f972016-08-30 17:41:48 +0100889 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +0100890 *
891 * This broadcast is sent only to the primary user.
892 * @see #ACTION_PROVISION_MANAGED_DEVICE
893 */
894 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
895 public static final String ACTION_DEVICE_OWNER_CHANGED
896 = "android.app.action.DEVICE_OWNER_CHANGED";
897
898 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800899 * The ComponentName of the administrator component.
900 *
901 * @see #ACTION_ADD_DEVICE_ADMIN
902 */
903 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700904
Dianne Hackbornd6847842010-01-12 18:14:19 -0800905 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800906 * An optional CharSequence providing additional explanation for why the
907 * admin is being added.
908 *
909 * @see #ACTION_ADD_DEVICE_ADMIN
910 */
911 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700912
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800913 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700914 * Activity action: have the user enter a new password. This activity should
915 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
916 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
917 * enter a new password that meets the current requirements. You can use
918 * {@link #isActivePasswordSufficient()} to determine whether you need to
919 * have the user select a new password in order to meet the current
920 * constraints. Upon being resumed from this activity, you can check the new
921 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000922 *
923 * If the intent is launched from within a managed profile with a profile
924 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
925 * this will trigger entering a new password for the parent of the profile.
926 * For all other cases it will trigger entering a new password for the user
927 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000928 *
929 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800930 */
931 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
932 public static final String ACTION_SET_NEW_PASSWORD
933 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700934
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000935 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000936 * Activity action: have the user enter a new password for the parent profile.
937 * If the intent is launched from within a managed profile, this will trigger
938 * entering a new password for the parent of the profile. In all other cases
939 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
940 */
941 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
942 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
943 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
944
945 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000946 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
947 * the parent profile to access intents sent from the managed profile.
948 * That is, when an app in the managed profile calls
949 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
950 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000951 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100952 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000953
954 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +0000955 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
956 * the managed profile to access intents sent from the parent profile.
957 * That is, when an app in the parent profile calls
958 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
959 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000960 */
Nicolas Prevot86a96732014-09-08 12:13:05 +0100961 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700962
Dianne Hackbornd6847842010-01-12 18:14:19 -0800963 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +0100964 * Broadcast action: notify that a new local system update policy has been set by the device
965 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +0000966 */
967 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +0100968 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
969 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +0000970
Amith Yamasanid49489b2015-04-28 14:00:26 -0700971 /**
972 * Permission policy to prompt user for new permission requests for runtime permissions.
973 * Already granted or denied permissions are not affected by this.
974 */
975 public static final int PERMISSION_POLICY_PROMPT = 0;
976
977 /**
978 * Permission policy to always grant new permission requests for runtime permissions.
979 * Already granted or denied permissions are not affected by this.
980 */
981 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
982
983 /**
984 * Permission policy to always deny new permission requests for runtime permissions.
985 * Already granted or denied permissions are not affected by this.
986 */
987 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
988
Svet Ganovd8ecc5a2015-05-20 10:45:43 -0700989 /**
990 * Runtime permission state: The user can manage the permission
991 * through the UI.
992 */
993 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
994
995 /**
996 * Runtime permission state: The permission is granted to the app
997 * and the user cannot manage the permission through the UI.
998 */
999 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1000
1001 /**
1002 * Runtime permission state: The permission is denied to the app
1003 * and the user cannot manage the permission through the UI.
1004 */
1005 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001006
1007 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001008 * No management for current user in-effect. This is the default.
1009 * @hide
1010 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001011 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001012 public static final int STATE_USER_UNMANAGED = 0;
1013
1014 /**
1015 * Management partially setup, user setup needs to be completed.
1016 * @hide
1017 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001018 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001019 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1020
1021 /**
1022 * Management partially setup, user setup completed.
1023 * @hide
1024 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001025 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001026 public static final int STATE_USER_SETUP_COMPLETE = 2;
1027
1028 /**
1029 * Management setup and active on current user.
1030 * @hide
1031 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001032 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001033 public static final int STATE_USER_SETUP_FINALIZED = 3;
1034
1035 /**
1036 * Management partially setup on a managed profile.
1037 * @hide
1038 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001039 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001040 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1041
1042 /**
1043 * @hide
1044 */
1045 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1046 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1047 @Retention(RetentionPolicy.SOURCE)
1048 public @interface UserProvisioningState {}
1049
1050 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001051 * Return true if the given administrator component is currently active (enabled) in the system.
1052 *
1053 * @param admin The administrator component to check for.
1054 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1055 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001056 */
Robin Lee25e26452015-06-02 09:56:29 -07001057 public boolean isAdminActive(@NonNull ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001058 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001059 }
1060
1061 /**
1062 * @see #isAdminActive(ComponentName)
1063 * @hide
1064 */
Robin Lee25e26452015-06-02 09:56:29 -07001065 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001066 if (mService != null) {
1067 try {
Robin Lee25e26452015-06-02 09:56:29 -07001068 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001069 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001070 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001071 }
1072 }
1073 return false;
1074 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001075 /**
1076 * Return true if the given administrator component is currently being removed
1077 * for the user.
1078 * @hide
1079 */
Robin Lee25e26452015-06-02 09:56:29 -07001080 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001081 if (mService != null) {
1082 try {
Robin Lee25e26452015-06-02 09:56:29 -07001083 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001085 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001086 }
1087 }
1088 return false;
1089 }
1090
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001091
Dianne Hackbornd6847842010-01-12 18:14:19 -08001092 /**
Robin Lee25e26452015-06-02 09:56:29 -07001093 * Return a list of all currently active device administrators' component
1094 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001095 * returned.
1096 */
1097 public List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001098 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001099 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001100 }
1101
1102 /**
1103 * @see #getActiveAdmins()
1104 * @hide
1105 */
1106 public List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001107 if (mService != null) {
1108 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001109 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001110 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001111 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001112 }
1113 }
1114 return null;
1115 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001116
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001117 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001118 * Used by package administration code to determine if a package can be stopped
1119 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001120 * @hide
1121 */
1122 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001123 return packageHasActiveAdmins(packageName, myUserId());
1124 }
1125
1126 /**
1127 * Used by package administration code to determine if a package can be stopped
1128 * or uninstalled.
1129 * @hide
1130 */
1131 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001132 if (mService != null) {
1133 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001134 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001135 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001136 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001137 }
1138 }
1139 return false;
1140 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001141
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001142 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001143 * Remove a current administration component. This can only be called
1144 * by the application that owns the administration component; if you
1145 * try to remove someone else's component, a security exception will be
1146 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001147 *
1148 * <p>Note that the operation is not synchronous and the admin might still be active (as
1149 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001150 *
1151 * @param admin The administration compononent to remove.
1152 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001153 */
Robin Lee25e26452015-06-02 09:56:29 -07001154 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001155 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001156 if (mService != null) {
1157 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001158 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001159 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001160 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001161 }
1162 }
1163 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001164
Dianne Hackbornd6847842010-01-12 18:14:19 -08001165 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001166 * Returns true if an administrator has been granted a particular device policy. This can be
1167 * used to check whether the administrator was activated under an earlier set of policies, but
1168 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001169 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1171 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001172 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001173 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001174 */
Robin Lee25e26452015-06-02 09:56:29 -07001175 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001176 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001177 if (mService != null) {
1178 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001179 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001180 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001181 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001182 }
1183 }
1184 return false;
1185 }
1186
1187 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001188 * Returns true if the Profile Challenge is available to use for the given profile user.
1189 *
1190 * @hide
1191 */
1192 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1193 if (mService != null) {
1194 try {
1195 return mService.isSeparateProfileChallengeAllowed(userHandle);
1196 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001197 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001198 }
1199 }
1200 return false;
1201 }
1202
1203 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001204 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1205 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001206 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001207 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001208 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001209
Dianne Hackbornd6847842010-01-12 18:14:19 -08001210 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001211 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1212 * recognition technology. This implies technologies that can recognize the identity of
1213 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1214 * Note that quality constants are ordered so that higher values are more restrictive.
1215 */
1216 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1217
1218 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001219 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001220 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001221 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001222 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001223 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001224
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001225 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001226 * Constant for {@link #setPasswordQuality}: the user must have entered a
1227 * password containing at least numeric characters. Note that quality
1228 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001229 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001230 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001231
Dianne Hackbornd6847842010-01-12 18:14:19 -08001232 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001233 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001234 * password containing at least numeric characters with no repeating (4444)
1235 * or ordered (1234, 4321, 2468) sequences. Note that quality
1236 * constants are ordered so that higher values are more restrictive.
1237 */
1238 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1239
1240 /**
1241 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001242 * password containing at least alphabetic (or other symbol) characters.
1243 * Note that quality constants are ordered so that higher values are more
1244 * restrictive.
1245 */
1246 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001247
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001248 /**
1249 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001250 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001251 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001252 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001253 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001254 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001255
Dianne Hackbornd6847842010-01-12 18:14:19 -08001256 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001257 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001258 * password containing at least a letter, a numerical digit and a special
1259 * symbol, by default. With this password quality, passwords can be
1260 * restricted to contain various sets of characters, like at least an
1261 * uppercase letter, etc. These are specified using various methods,
1262 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1263 * that quality constants are ordered so that higher values are more
1264 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001265 */
1266 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1267
1268 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001269 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1270 * modify password. In case this password quality is set, the password is
1271 * managed by a profile owner. The profile owner can set any password,
1272 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1273 * that quality constants are ordered so that higher values are more
1274 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1275 * the highest.
1276 * @hide
1277 */
1278 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1279
1280 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001281 * @hide
1282 *
1283 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1284 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1285 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1286 * used by authenticator to exempt their accounts from this:
1287 *
1288 * <ul>
1289 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1290 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1291 * &lt;application&gt; tag in the manifest.
1292 *
1293 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1294 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1295 * Some authenticators claim to have any features, so to detect it, we also check
1296 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1297 * if any of the accounts have it.
1298 * </ul>
1299 */
1300 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1301 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1302
1303 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1304 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1305 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1306
1307 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001308 * Called by an application that is administering the device to set the password restrictions it
1309 * is imposing. After setting this, the user will not be able to enter a new password that is
1310 * not at least as restrictive as what has been set. Note that the current password will remain
1311 * until the user has set a new one, so the change does not take place immediately. To prompt
1312 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001313 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001314 * <p>
1315 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1316 * requested quality constant (between the policy set here, the user's preference, and any other
1317 * considerations) is the one that is in effect.
1318 * <p>
1319 * The calling device admin must have requested
1320 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1321 * not, a security exception will be thrown.
1322 * <p>
1323 * This method can be called on the {@link DevicePolicyManager} instance returned by
1324 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1325 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001326 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001327 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001328 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1329 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1330 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1331 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1332 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1333 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001334 */
Robin Lee25e26452015-06-02 09:56:29 -07001335 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001336 if (mService != null) {
1337 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001338 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001339 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001340 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001341 }
1342 }
1343 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001344
Dianne Hackbornd6847842010-01-12 18:14:19 -08001345 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001346 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001347 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001348 * a separate challenge are not taken into account.
1349 *
1350 * <p>This method can be called on the {@link DevicePolicyManager} instance
1351 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1352 * restrictions on the parent profile.
1353 *
Robin Lee25e26452015-06-02 09:56:29 -07001354 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001355 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001356 */
Robin Lee25e26452015-06-02 09:56:29 -07001357 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001358 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001359 }
1360
1361 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001362 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001363 if (mService != null) {
1364 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001365 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001366 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001367 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001368 }
1369 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001370 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001371 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001372
Dianne Hackbornd6847842010-01-12 18:14:19 -08001373 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001374 * Called by an application that is administering the device to set the minimum allowed password
1375 * length. After setting this, the user will not be able to enter a new password that is not at
1376 * least as restrictive as what has been set. Note that the current password will remain until
1377 * the user has set a new one, so the change does not take place immediately. To prompt the user
1378 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1379 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1380 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1381 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1382 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1383 * {@link #setPasswordQuality}.
1384 * <p>
1385 * The calling device admin must have requested
1386 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1387 * not, a security exception will be thrown.
1388 * <p>
1389 * This method can be called on the {@link DevicePolicyManager} instance returned by
1390 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1391 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001392 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001393 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001394 * @param length The new desired minimum password length. A value of 0 means there is no
1395 * restriction.
1396 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1397 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001398 */
Robin Lee25e26452015-06-02 09:56:29 -07001399 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001400 if (mService != null) {
1401 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001402 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001403 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001404 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001405 }
1406 }
1407 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001408
Dianne Hackbornd6847842010-01-12 18:14:19 -08001409 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001410 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001411 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001412 * a separate challenge are not taken into account.
1413 *
1414 * <p>This method can be called on the {@link DevicePolicyManager} instance
1415 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1416 * restrictions on the parent profile.
1417 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001418 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001419 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001420 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001421 */
Robin Lee25e26452015-06-02 09:56:29 -07001422 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001423 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001424 }
1425
1426 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001427 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001428 if (mService != null) {
1429 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001430 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001431 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001432 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001433 }
1434 }
1435 return 0;
1436 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001437
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001438 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001439 * Called by an application that is administering the device to set the minimum number of upper
1440 * case letters required in the password. After setting this, the user will not be able to enter
1441 * a new password that is not at least as restrictive as what has been set. Note that the
1442 * current password will remain until the user has set a new one, so the change does not take
1443 * place immediately. To prompt the user for a new password, use
1444 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1445 * setting this value. This constraint is only imposed if the administrator has also requested
1446 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001447 * <p>
1448 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001449 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1450 * not, a security exception will be thrown.
1451 * <p>
1452 * This method can be called on the {@link DevicePolicyManager} instance returned by
1453 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1454 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001455 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001456 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1457 * @param length The new desired minimum number of upper case letters required in the password.
1458 * A value of 0 means there is no restriction.
1459 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1460 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001461 */
Robin Lee25e26452015-06-02 09:56:29 -07001462 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001463 if (mService != null) {
1464 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001465 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001466 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001467 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001468 }
1469 }
1470 }
1471
1472 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001473 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001474 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001475 * its participating profiles. Restrictions on profiles that have a separate challenge
1476 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001477 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001478 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001479 * and only applies when the password quality is
1480 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001481 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001482 * <p>This method can be called on the {@link DevicePolicyManager} instance
1483 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1484 * restrictions on the parent profile.
1485 *
Robin Lee25e26452015-06-02 09:56:29 -07001486 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001487 * aggregate all admins.
1488 * @return The minimum number of upper case letters required in the
1489 * password.
1490 */
Robin Lee25e26452015-06-02 09:56:29 -07001491 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001492 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001493 }
1494
1495 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001496 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001497 if (mService != null) {
1498 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001499 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001500 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001501 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001502 }
1503 }
1504 return 0;
1505 }
1506
1507 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001508 * Called by an application that is administering the device to set the minimum number of lower
1509 * case letters required in the password. After setting this, the user will not be able to enter
1510 * a new password that is not at least as restrictive as what has been set. Note that the
1511 * current password will remain until the user has set a new one, so the change does not take
1512 * place immediately. To prompt the user for a new password, use
1513 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1514 * setting this value. This constraint is only imposed if the administrator has also requested
1515 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001516 * <p>
1517 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001518 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1519 * not, a security exception will be thrown.
1520 * <p>
1521 * This method can be called on the {@link DevicePolicyManager} instance returned by
1522 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1523 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001524 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001525 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1526 * @param length The new desired minimum number of lower case letters required in the password.
1527 * A value of 0 means there is no restriction.
1528 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1529 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001530 */
Robin Lee25e26452015-06-02 09:56:29 -07001531 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001532 if (mService != null) {
1533 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001534 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001535 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001536 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001537 }
1538 }
1539 }
1540
1541 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001542 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001543 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001544 * and its participating profiles. Restrictions on profiles that have
1545 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001546 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001547 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001548 * and only applies when the password quality is
1549 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001550 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001551 * <p>This method can be called on the {@link DevicePolicyManager} instance
1552 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1553 * restrictions on the parent profile.
1554 *
Robin Lee25e26452015-06-02 09:56:29 -07001555 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001556 * aggregate all admins.
1557 * @return The minimum number of lower case letters required in the
1558 * password.
1559 */
Robin Lee25e26452015-06-02 09:56:29 -07001560 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001561 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001562 }
1563
1564 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001565 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001566 if (mService != null) {
1567 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001568 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001569 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001570 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001571 }
1572 }
1573 return 0;
1574 }
1575
1576 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001577 * Called by an application that is administering the device to set the minimum number of
1578 * letters required in the password. After setting this, the user will not be able to enter a
1579 * new password that is not at least as restrictive as what has been set. Note that the current
1580 * password will remain until the user has set a new one, so the change does not take place
1581 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1582 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1583 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1584 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001585 * <p>
1586 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001587 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1588 * not, a security exception will be thrown.
1589 * <p>
1590 * This method can be called on the {@link DevicePolicyManager} instance returned by
1591 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1592 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001593 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001594 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1595 * @param length The new desired minimum number of letters required in the password. A value of
1596 * 0 means there is no restriction.
1597 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1598 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001599 */
Robin Lee25e26452015-06-02 09:56:29 -07001600 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001601 if (mService != null) {
1602 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001603 mService.setPasswordMinimumLetters(admin, length, 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 }
1609
1610 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001611 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001612 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001613 * and its participating profiles. Restrictions on profiles that have
1614 * a separate challenge are not taken into account.
1615 * This is the same value as set by
1616 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001617 * and only applies when the password quality is
1618 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001619 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001620 * <p>This method can be called on the {@link DevicePolicyManager} instance
1621 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1622 * restrictions on the parent profile.
1623 *
Robin Lee25e26452015-06-02 09:56:29 -07001624 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001625 * aggregate all admins.
1626 * @return The minimum number of letters required in the password.
1627 */
Robin Lee25e26452015-06-02 09:56:29 -07001628 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001629 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001630 }
1631
1632 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001633 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001634 if (mService != null) {
1635 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001636 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001637 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001638 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001639 }
1640 }
1641 return 0;
1642 }
1643
1644 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001645 * Called by an application that is administering the device to set the minimum number of
1646 * numerical digits required in the password. After setting this, the user will not be able to
1647 * enter a new password that is not at least as restrictive as what has been set. Note that the
1648 * current password will remain until the user has set a new one, so the change does not take
1649 * place immediately. To prompt the user for a new password, use
1650 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1651 * setting this value. This constraint is only imposed if the administrator has also requested
1652 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001653 * <p>
1654 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001655 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1656 * not, a security exception will be thrown.
1657 * <p>
1658 * This method can be called on the {@link DevicePolicyManager} instance returned by
1659 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1660 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001661 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001662 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1663 * @param length The new desired minimum number of numerical digits required in the password. A
1664 * value of 0 means there is no restriction.
1665 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1666 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001667 */
Robin Lee25e26452015-06-02 09:56:29 -07001668 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001669 if (mService != null) {
1670 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001671 mService.setPasswordMinimumNumeric(admin, length, 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 }
1677
1678 /**
1679 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001680 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001681 * and its participating profiles. Restrictions on profiles that have
1682 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001683 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001684 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001685 * and only applies when the password quality is
1686 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001687 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001688 * <p>This method can be called on the {@link DevicePolicyManager} instance
1689 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1690 * restrictions on the parent profile.
1691 *
Robin Lee25e26452015-06-02 09:56:29 -07001692 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001693 * aggregate all admins.
1694 * @return The minimum number of numerical digits required in the password.
1695 */
Robin Lee25e26452015-06-02 09:56:29 -07001696 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001697 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001698 }
1699
1700 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001701 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001702 if (mService != null) {
1703 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001704 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001705 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001706 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001707 }
1708 }
1709 return 0;
1710 }
1711
1712 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001713 * Called by an application that is administering the device to set the minimum number of
1714 * symbols required in the password. After setting this, the user will not be able to enter a
1715 * new password that is not at least as restrictive as what has been set. Note that the current
1716 * password will remain until the user has set a new one, so the change does not take place
1717 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1718 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1719 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1720 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001721 * <p>
1722 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001723 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1724 * not, a security exception will be thrown.
1725 * <p>
1726 * This method can be called on the {@link DevicePolicyManager} instance returned by
1727 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1728 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001729 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1731 * @param length The new desired minimum number of symbols required in the password. A value of
1732 * 0 means there is no restriction.
1733 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1734 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001735 */
Robin Lee25e26452015-06-02 09:56:29 -07001736 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001737 if (mService != null) {
1738 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001739 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001740 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001741 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001742 }
1743 }
1744 }
1745
1746 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001747 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001748 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001749 * and its participating profiles. Restrictions on profiles that have
1750 * a separate challenge are not taken into account. This is the same value as
1751 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001752 * and only applies when the password quality is
1753 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001754 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001755 * <p>This method can be called on the {@link DevicePolicyManager} instance
1756 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1757 * restrictions on the parent profile.
1758 *
Robin Lee25e26452015-06-02 09:56:29 -07001759 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001760 * aggregate all admins.
1761 * @return The minimum number of symbols required in the password.
1762 */
Robin Lee25e26452015-06-02 09:56:29 -07001763 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001764 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001765 }
1766
1767 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001768 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001769 if (mService != null) {
1770 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001771 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001772 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001773 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001774 }
1775 }
1776 return 0;
1777 }
1778
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001779 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001780 * Called by an application that is administering the device to set the minimum number of
1781 * non-letter characters (numerical digits or symbols) required in the password. After setting
1782 * this, the user will not be able to enter a new password that is not at least as restrictive
1783 * as what has been set. Note that the current password will remain until the user has set a new
1784 * one, so the change does not take place immediately. To prompt the user for a new password,
1785 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1786 * setting this value. This constraint is only imposed if the administrator has also requested
1787 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001788 * <p>
1789 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001790 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1791 * not, a security exception will be thrown.
1792 * <p>
1793 * This method can be called on the {@link DevicePolicyManager} instance returned by
1794 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1795 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001796 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001797 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1798 * @param length The new desired minimum number of letters required in the password. A value of
1799 * 0 means there is no restriction.
1800 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1801 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001802 */
Robin Lee25e26452015-06-02 09:56:29 -07001803 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001804 if (mService != null) {
1805 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001806 mService.setPasswordMinimumNonLetter(admin, length, 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 }
1812
1813 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001814 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001815 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001816 * and its participating profiles. Restrictions on profiles that have
1817 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001818 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001819 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001820 * and only applies when the password quality is
1821 * {@link #PASSWORD_QUALITY_COMPLEX}.
1822 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001823 * <p>This method can be called on the {@link DevicePolicyManager} instance
1824 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1825 * restrictions on the parent profile.
1826 *
Robin Lee25e26452015-06-02 09:56:29 -07001827 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001828 * aggregate all admins.
1829 * @return The minimum number of letters required in the password.
1830 */
Robin Lee25e26452015-06-02 09:56:29 -07001831 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001832 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001833 }
1834
1835 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001836 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001837 if (mService != null) {
1838 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001839 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001840 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001841 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001842 }
1843 }
1844 return 0;
1845 }
1846
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001847 /**
1848 * Called by an application that is administering the device to set the length of the password
1849 * history. After setting this, the user will not be able to enter a new password that is the
1850 * same as any password in the history. Note that the current password will remain until the
1851 * user has set a new one, so the change does not take place immediately. To prompt the user for
1852 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1853 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1854 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1855 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
1856 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
1857 * <p>
1858 * The calling device admin must have requested
1859 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1860 * not, a security exception will be thrown.
1861 * <p>
1862 * This method can be called on the {@link DevicePolicyManager} instance returned by
1863 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1864 * profile.
1865 *
1866 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1867 * @param length The new desired length of password history. A value of 0 means there is no
1868 * restriction.
1869 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1870 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
1871 */
Robin Lee25e26452015-06-02 09:56:29 -07001872 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001873 if (mService != null) {
1874 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001875 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001876 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001877 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001878 }
1879 }
1880 }
1881
1882 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001883 * Called by a device admin to set the password expiration timeout. Calling this method will
1884 * restart the countdown for password expiration for the given admin, as will changing the
1885 * device password (for all admins).
1886 * <p>
1887 * The provided timeout is the time delta in ms and will be added to the current time. For
1888 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
1889 * 432000000 ms for timeout.
1890 * <p>
1891 * To disable password expiration, a value of 0 may be used for timeout.
1892 * <p>
1893 * The calling device admin must have requested
1894 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
1895 * not, a security exception will be thrown.
1896 * <p>
1897 * Note that setting the password will automatically reset the expiration time for all active
1898 * admins. Active admins do not need to explicitly call this method in that case.
1899 * <p>
1900 * This method can be called on the {@link DevicePolicyManager} instance returned by
1901 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1902 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001903 *
Jim Millera4e28d12010-11-08 16:15:47 -08001904 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001905 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
1906 * there is no restriction (unlimited).
1907 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1908 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08001909 */
Robin Lee25e26452015-06-02 09:56:29 -07001910 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08001911 if (mService != null) {
1912 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001913 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001914 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001915 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001916 }
1917 }
1918 }
1919
1920 /**
Jim Miller6b857682011-02-16 16:27:41 -08001921 * Get the password expiration timeout for the given admin. The expiration timeout is the
1922 * recurring expiration timeout provided in the call to
1923 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00001924 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
1925 * have set restrictions on profiles that have a separate challenge are not taken into account.
1926 *
1927 * <p>This method can be called on the {@link DevicePolicyManager} instance
1928 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1929 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001930 *
Robin Lee25e26452015-06-02 09:56:29 -07001931 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08001932 * @return The timeout for the given admin or the minimum of all timeouts
1933 */
Robin Lee25e26452015-06-02 09:56:29 -07001934 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001935 if (mService != null) {
1936 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001937 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001938 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001939 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001940 }
1941 }
1942 return 0;
1943 }
1944
1945 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001946 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001947 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001948 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
1949 * of all expiration times is returned - which will be the minimum of all of them.
1950 *
1951 * <p>This method can be called on the {@link DevicePolicyManager} instance
1952 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1953 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08001954 *
Robin Lee25e26452015-06-02 09:56:29 -07001955 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001956 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08001957 */
Robin Lee25e26452015-06-02 09:56:29 -07001958 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08001959 if (mService != null) {
1960 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001961 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08001962 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001963 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08001964 }
1965 }
1966 return 0;
1967 }
1968
1969 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001970 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01001971 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00001972 * have a separate challenge are not taken into account.
1973 *
1974 * <p>This method can be called on the {@link DevicePolicyManager} instance
1975 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1976 * restrictions on the parent profile.
1977 *
Robin Lee25e26452015-06-02 09:56:29 -07001978 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001979 * all admins.
1980 * @return The length of the password history
1981 */
Robin Lee25e26452015-06-02 09:56:29 -07001982 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001983 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001984 }
1985
1986 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001987 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001988 if (mService != null) {
1989 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001990 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001991 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001992 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001993 }
1994 }
1995 return 0;
1996 }
1997
Dianne Hackbornd6847842010-01-12 18:14:19 -08001998 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08001999 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002000 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002001 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002002 * @return Returns the maximum length that the user can enter.
2003 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002004 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002005 // Kind-of arbitrary.
2006 return 16;
2007 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002008
Dianne Hackborn254cb442010-01-27 19:23:59 -08002009 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002010 * Determine whether the current password the user has set is sufficient to meet the policy
2011 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2012 * user and its participating profiles. Restrictions on profiles that have a separate challenge
2013 * are not taken into account.
2014 * <p>
2015 * The calling device admin must have requested
2016 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2017 * not, a security exception will be thrown.
2018 * <p>
2019 * This method can be called on the {@link DevicePolicyManager} instance returned by
2020 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2021 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002022 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002023 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002024 * @throws SecurityException if the calling application does not own an active administrator
2025 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002026 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002027 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002028 if (mService != null) {
2029 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002030 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002031 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002032 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002033 }
2034 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002035 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002036 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002037
Dianne Hackbornd6847842010-01-12 18:14:19 -08002038 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002039 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002040 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002041 * requested by the admins of the parent user and its profiles.
2042 *
2043 * @param userHandle the userId of the profile to check the password for.
2044 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002045 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002046 * @hide
2047 */
2048 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2049 if (mService != null) {
2050 try {
2051 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2052 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002053 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002054 }
2055 }
2056 return false;
2057 }
2058
2059 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002060 * Retrieve the number of times the user has failed at entering a password since that last
2061 * successful password entry.
2062 * <p>
2063 * This method can be called on the {@link DevicePolicyManager} instance returned by
2064 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2065 * password attemts for the parent user.
2066 * <p>
2067 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2068 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002069 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002070 * @return The number of times user has entered an incorrect password since the last correct
2071 * password entry.
2072 * @throws SecurityException if the calling application does not own an active administrator
2073 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002074 */
2075 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002076 return getCurrentFailedPasswordAttempts(myUserId());
2077 }
2078
2079 /**
2080 * Retrieve the number of times the given user has failed at entering a
2081 * password since that last successful password entry.
2082 *
2083 * <p>The calling device admin must have requested
2084 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2085 * not and it is not the system uid, a security exception will be thrown.
2086 *
2087 * @hide
2088 */
2089 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002090 if (mService != null) {
2091 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002092 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002093 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002094 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002095 }
2096 }
2097 return -1;
2098 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002099
2100 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002101 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002102 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002103 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002104 * @hide
2105 */
2106 public boolean getDoNotAskCredentialsOnBoot() {
2107 if (mService != null) {
2108 try {
2109 return mService.getDoNotAskCredentialsOnBoot();
2110 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002111 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002112 }
2113 }
2114 return false;
2115 }
2116
2117 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002118 * Setting this to a value greater than zero enables a built-in policy that will perform a
2119 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2120 * This built-in policy combines watching for failed passwords and wiping the device, and
2121 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002122 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002123 * <p>
2124 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2125 * revoking credentials, or reporting the failure to a server), you should implement
2126 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2127 * use this API, because if the maximum count is reached, the device or profile will be wiped
2128 * immediately, and your callback will not be invoked.
2129 * <p>
2130 * This method can be called on the {@link DevicePolicyManager} instance returned by
2131 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2132 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002133 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002134 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002135 * @param num The number of failed password attempts at which point the device or profile will
2136 * be wiped.
2137 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2138 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2139 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002140 */
Robin Lee25e26452015-06-02 09:56:29 -07002141 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002142 if (mService != null) {
2143 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002144 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002145 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002146 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002147 }
2148 }
2149 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002150
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002151 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002152 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002153 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002154 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2155 * not taken into account.
2156 *
2157 * <p>This method can be called on the {@link DevicePolicyManager} instance
2158 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2159 * the value for the parent profile.
2160 *
Robin Lee25e26452015-06-02 09:56:29 -07002161 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002162 * all admins.
2163 */
Robin Lee25e26452015-06-02 09:56:29 -07002164 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002165 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002166 }
2167
2168 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002169 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002170 if (mService != null) {
2171 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002172 return mService.getMaximumFailedPasswordsForWipe(
2173 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002174 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002175 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002176 }
2177 }
2178 return 0;
2179 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002180
Dianne Hackborn254cb442010-01-27 19:23:59 -08002181 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002182 * Returns the profile with the smallest maximum failed passwords for wipe,
2183 * for the given user. So for primary user, it might return the primary or
2184 * a managed profile. For a secondary user, it would be the same as the
2185 * user passed in.
2186 * @hide Used only by Keyguard
2187 */
2188 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2189 if (mService != null) {
2190 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002191 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2192 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002193 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002194 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002195 }
2196 }
2197 return UserHandle.USER_NULL;
2198 }
2199
2200 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002201 * Flag for {@link #resetPassword}: don't allow other admins to change
2202 * the password again until the user has entered it.
2203 */
2204 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002205
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002206 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002207 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2208 * If the flag is set, the device can be booted without asking for user password.
2209 * The absence of this flag does not change the current boot requirements. This flag
2210 * can be set by the device owner only. If the app is not the device owner, the flag
2211 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2212 * device to factory defaults.
2213 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002214 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002215
2216 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002217 * Force a new device unlock password (the password needed to access the entire device, not for
2218 * individual accounts) on the user. This takes effect immediately.
2219 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002220 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002221 * device admins that are not device owner and not profile owner.
2222 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002223 * and profile owner can still do this when user is unlocked and does not have a managed
2224 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002225 * <p>
2226 * The given password must be sufficient for the current password quality and length constraints
2227 * as returned by {@link #getPasswordQuality(ComponentName)} and
2228 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2229 * it will be rejected and false returned. Note that the password may be a stronger quality
2230 * (containing alphanumeric characters when the requested quality is only numeric), in which
2231 * case the currently active quality will be increased to match.
2232 * <p>
2233 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002234 * current password constraints allow it. <em>Note: This will not work in
2235 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2236 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2237 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002238 * <p>
2239 * The calling device admin must have requested
2240 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2241 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002242 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002243 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002244 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002245 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2246 * @return Returns true if the password was applied, or false if it is not acceptable for the
2247 * current constraints or if the user has not been decrypted yet.
2248 * @throws SecurityException if the calling application does not own an active administrator
2249 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002250 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002251 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002252 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002253 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002254 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002255 if (mService != null) {
2256 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002257 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002258 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002259 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002260 }
2261 }
2262 return false;
2263 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002264
Dianne Hackbornd6847842010-01-12 18:14:19 -08002265 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002266 * Called by an application that is administering the device to set the maximum time for user
2267 * activity until the device will lock. This limits the length that the user can set. It takes
2268 * effect immediately.
2269 * <p>
2270 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2271 * to be able to call this method; if it has not, a security exception will be thrown.
2272 * <p>
2273 * This method can be called on the {@link DevicePolicyManager} instance returned by
2274 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2275 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002276 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002278 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2279 * is no restriction.
2280 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2281 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002282 */
Robin Lee25e26452015-06-02 09:56:29 -07002283 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002284 if (mService != null) {
2285 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002286 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002287 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002288 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002289 }
2290 }
2291 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002292
Dianne Hackbornd6847842010-01-12 18:14:19 -08002293 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002294 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002295 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002296 * a separate challenge are not taken into account.
2297 *
2298 * <p>This method can be called on the {@link DevicePolicyManager} instance
2299 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2300 * restrictions on the parent profile.
2301 *
Robin Lee25e26452015-06-02 09:56:29 -07002302 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002303 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002304 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002305 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002306 */
Robin Lee25e26452015-06-02 09:56:29 -07002307 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002308 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002309 }
2310
2311 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002312 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002313 if (mService != null) {
2314 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002315 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002316 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002317 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002318 }
2319 }
2320 return 0;
2321 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002322
Dianne Hackbornd6847842010-01-12 18:14:19 -08002323 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002324 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2325 * do not have a separate timeout to lock for work challenge only.
2326 *
2327 * @hide
2328 */
2329 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2330 if (mService != null) {
2331 try {
2332 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2333 } catch (RemoteException e) {
2334 throw e.rethrowFromSystemServer();
2335 }
2336 }
2337 return 0;
2338 }
2339
2340 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002341 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2342 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2343 * authentication method like password, pin or pattern.
2344 *
2345 * <p>This timeout is used internally to reset the timer to require strong auth again after
2346 * specified timeout each time it has been successfully used.
2347 *
2348 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2349 *
2350 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2351 *
2352 * <p>The calling device admin must be a device or profile owner. If it is not,
2353 * a {@link SecurityException} will be thrown.
2354 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002355 * <p>The calling device admin can verify the value it has set by calling
2356 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2357 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002358 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2359 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2360 * profile.
2361 *
2362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2363 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002364 * authentication method. A value of 0 means the admin is not participating in
2365 * controlling the timeout.
2366 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2367 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2368 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2369 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002370 *
2371 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002372 *
2373 * @hide
2374 */
2375 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2376 long timeoutMs) {
2377 if (mService != null) {
2378 try {
2379 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2380 } catch (RemoteException e) {
2381 throw e.rethrowFromSystemServer();
2382 }
2383 }
2384 }
2385
2386 /**
2387 * Determine for how long the user will be able to use secondary, non strong auth for
2388 * authentication, since last strong method authentication (password, pin or pattern) was used.
2389 * After the returned timeout the user is required to use strong authentication method.
2390 *
2391 * <p>This method can be called on the {@link DevicePolicyManager} instance
2392 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2393 * restrictions on the parent profile.
2394 *
2395 * @param admin The name of the admin component to check, or {@code null} to aggregate
2396 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002397 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002398 *
2399 * @hide
2400 */
2401 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2402 return getRequiredStrongAuthTimeout(admin, myUserId());
2403 }
2404
2405 /** @hide per-user version */
2406 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2407 if (mService != null) {
2408 try {
2409 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2410 } catch (RemoteException e) {
2411 throw e.rethrowFromSystemServer();
2412 }
2413 }
2414 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2415 }
2416
2417 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002418 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2419 * this call.
2420 * <p>
2421 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2422 * to be able to call this method; if it has not, a security exception will be thrown.
2423 * <p>
2424 * This method can be called on the {@link DevicePolicyManager} instance returned by
2425 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002426 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002427 * @throws SecurityException if the calling application does not own an active administrator
2428 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002429 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002430 public void lockNow() {
2431 if (mService != null) {
2432 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002433 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002434 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002435 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002436 }
2437 }
2438 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002439
Dianne Hackbornd6847842010-01-12 18:14:19 -08002440 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002441 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002442 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002443 */
2444 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2445
2446 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002447 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2448 * data.
2449 *
Paul Crowley2934b262014-12-02 11:21:13 +00002450 * <p>This flag may only be set by device owner admins; if it is set by
2451 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002452 */
2453 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2454
2455 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002456 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2457 * other users will remain unaffected. Calling from the primary user will cause the device to
2458 * reboot, erasing all device data - including all the secondary users and their data - while
2459 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002460 * <p>
2461 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2462 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002463 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002464 * @param flags Bit mask of additional options: currently supported flags are
2465 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2466 * @throws SecurityException if the calling application does not own an active administrator
2467 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002468 */
2469 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002470 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002471 if (mService != null) {
2472 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002473 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002475 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002476 }
2477 }
2478 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002479
Dianne Hackbornd6847842010-01-12 18:14:19 -08002480 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002481 * Called by an application that is administering the device to set the
2482 * global proxy and exclusion list.
2483 * <p>
2484 * The calling device admin must have requested
2485 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2486 * this method; if it has not, a security exception will be thrown.
2487 * Only the first device admin can set the proxy. If a second admin attempts
2488 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002489 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002490 * be returned.
2491 * The method can be called repeatedly by the device admin alrady setting the
2492 * proxy to update the proxy and exclusion list.
2493 *
Robin Lee25e26452015-06-02 09:56:29 -07002494 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002495 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2496 * Pass Proxy.NO_PROXY to reset the proxy.
2497 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002498 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2499 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002500 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002501 */
Robin Lee25e26452015-06-02 09:56:29 -07002502 public ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002503 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002504 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002505 if (proxySpec == null) {
2506 throw new NullPointerException();
2507 }
2508 if (mService != null) {
2509 try {
2510 String hostSpec;
2511 String exclSpec;
2512 if (proxySpec.equals(Proxy.NO_PROXY)) {
2513 hostSpec = null;
2514 exclSpec = null;
2515 } else {
2516 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2517 throw new IllegalArgumentException();
2518 }
2519 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2520 String hostName = sa.getHostName();
2521 int port = sa.getPort();
2522 StringBuilder hostBuilder = new StringBuilder();
2523 hostSpec = hostBuilder.append(hostName)
2524 .append(":").append(Integer.toString(port)).toString();
2525 if (exclusionList == null) {
2526 exclSpec = "";
2527 } else {
2528 StringBuilder listBuilder = new StringBuilder();
2529 boolean firstDomain = true;
2530 for (String exclDomain : exclusionList) {
2531 if (!firstDomain) {
2532 listBuilder = listBuilder.append(",");
2533 } else {
2534 firstDomain = false;
2535 }
2536 listBuilder = listBuilder.append(exclDomain.trim());
2537 }
2538 exclSpec = listBuilder.toString();
2539 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002540 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2541 != android.net.Proxy.PROXY_VALID)
2542 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002543 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002544 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002545 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002546 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002547 }
2548 }
2549 return null;
2550 }
2551
2552 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002553 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2554 * HTTP proxies - they are generally network dependent. However if you're doing something
2555 * unusual like general internal filtering this may be useful. On a private network where the
2556 * proxy is not accessible, you may break HTTP using this.
2557 * <p>
2558 * This method requires the caller to be the device owner.
2559 * <p>
2560 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002561 *
Jason Monk03bc9912014-05-13 09:44:57 -04002562 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2564 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2565 * {@code null} value will clear the global HTTP proxy.
2566 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002567 */
Robin Lee25e26452015-06-02 09:56:29 -07002568 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2569 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002570 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002571 if (mService != null) {
2572 try {
2573 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2574 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002575 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002576 }
2577 }
2578 }
2579
2580 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002581 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002582 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2583 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002584 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002585 */
2586 public ComponentName getGlobalProxyAdmin() {
2587 if (mService != null) {
2588 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002589 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002590 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002591 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002592 }
2593 }
2594 return null;
2595 }
2596
2597 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002598 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002599 * indicating that encryption is not supported.
2600 */
2601 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2602
2603 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002604 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002605 * indicating that encryption is supported, but is not currently active.
2606 */
2607 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2608
2609 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002610 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002611 * indicating that encryption is not currently active, but is currently
2612 * being activated. This is only reported by devices that support
2613 * encryption of data and only when the storage is currently
2614 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2615 * to become encrypted will never return this value.
2616 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002617 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002618
2619 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002620 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002621 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002622 * <p>
2623 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002624 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002625 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002626
2627 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002628 * Result code for {@link #getStorageEncryptionStatus}:
2629 * indicating that encryption is active, but an encryption key has not
2630 * been set by the user.
2631 */
2632 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2633
2634 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002635 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002636 * indicating that encryption is active and the encryption key is tied to the user or profile.
2637 * <p>
2638 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2639 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2640 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002641 */
2642 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2643
2644 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002645 * Activity action: begin the process of encrypting data on the device. This activity should
2646 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2647 * After resuming from this activity, use {@link #getStorageEncryption}
2648 * to check encryption status. However, on some devices this activity may never return, as
2649 * it may trigger a reboot and in some cases a complete data wipe of the device.
2650 */
2651 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2652 public static final String ACTION_START_ENCRYPTION
2653 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002654 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002655 * Widgets are enabled in keyguard
2656 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002657 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002658
2659 /**
Jim Miller50e62182014-04-23 17:25:00 -07002660 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002661 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002662 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2663
2664 /**
2665 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2666 */
2667 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2668
2669 /**
Jim Miller50e62182014-04-23 17:25:00 -07002670 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2671 */
2672 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2673
2674 /**
2675 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2676 */
2677 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2678
2679 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002680 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002681 * (e.g. PIN/Pattern/Password).
2682 */
2683 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2684
2685 /**
Jim Miller06e34502014-07-17 14:46:05 -07002686 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2687 */
2688 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2689
2690 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002691 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2692 */
2693 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2694
2695 /**
Jim Miller35207742012-11-02 15:33:20 -07002696 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002697 */
2698 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002699
2700 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002701 * Called by an application that is administering the device to request that the storage system
2702 * be encrypted.
2703 * <p>
2704 * When multiple device administrators attempt to control device encryption, the most secure,
2705 * supported setting will always be used. If any device administrator requests device
2706 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2707 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002708 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002709 * <p>
2710 * This policy controls encryption of the secure (application data) storage area. Data written
2711 * to other storage areas may or may not be encrypted, and this policy does not require or
2712 * control the encryption of any other storage areas. There is one exception: If
2713 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2714 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2715 * written to disk within the encrypted storage area.
2716 * <p>
2717 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2718 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2719 * encryption key may not be fully secured. For maximum security, the administrator should also
2720 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002721 *
2722 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2723 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002724 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002725 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2726 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2727 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2728 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2729 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002730 */
Robin Lee25e26452015-06-02 09:56:29 -07002731 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002732 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002733 if (mService != null) {
2734 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002735 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002736 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002737 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002738 }
2739 }
2740 return ENCRYPTION_STATUS_UNSUPPORTED;
2741 }
2742
2743 /**
2744 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002745 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002746 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002747 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2748 * this will return the requested encryption setting as an aggregate of all active
2749 * administrators.
2750 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002751 */
Robin Lee25e26452015-06-02 09:56:29 -07002752 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002753 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002754 if (mService != null) {
2755 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002756 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002757 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002758 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002759 }
2760 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002761 return false;
2762 }
2763
2764 /**
2765 * Called by an application that is administering the device to
2766 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07002767 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08002768 * Depending on the returned status code, the caller may proceed in different
2769 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2770 * storage system does not support encryption. If the
2771 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2772 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002773 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2774 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07002775 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
2776 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
2777 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002778 *
Robin Lee7e678712014-07-24 16:41:31 +01002779 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08002780 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00002781 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07002782 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08002783 */
2784 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002785 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002786 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002787 }
2788
2789 /** @hide per-user version */
2790 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08002791 if (mService != null) {
2792 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08002793 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08002794 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002795 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08002796 }
2797 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002798 return ENCRYPTION_STATUS_UNSUPPORTED;
2799 }
2800
2801 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00002802 * Mark a CA certificate as approved by the device user. This means that they have been notified
2803 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
2804 * keep the certificate on the device.
2805 *
2806 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
2807 * this certificate.
2808 *
2809 * @hide
2810 */
2811 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
2812 if (mService != null) {
2813 try {
2814 return mService.approveCaCert(alias, userHandle, approval);
2815 } catch (RemoteException e) {
2816 throw e.rethrowFromSystemServer();
2817 }
2818 }
2819 return false;
2820 }
2821
2822 /**
2823 * Check whether a CA certificate has been approved by the device user.
2824 *
2825 * @hide
2826 */
2827 public boolean isCaCertApproved(String alias, int userHandle) {
2828 if (mService != null) {
2829 try {
2830 return mService.isCaCertApproved(alias, userHandle);
2831 } catch (RemoteException e) {
2832 throw e.rethrowFromSystemServer();
2833 }
2834 }
2835 return false;
2836 }
2837
2838 /**
Robin Lee7e678712014-07-24 16:41:31 +01002839 * Installs the given certificate as a user CA.
2840 *
Robin Lee25e26452015-06-02 09:56:29 -07002841 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2842 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002843 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04002844 *
2845 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01002846 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002847 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2848 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002849 */
Robin Lee25e26452015-06-02 09:56:29 -07002850 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002851 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002852 if (mService != null) {
2853 try {
Robin Lee7e678712014-07-24 16:41:31 +01002854 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04002855 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002856 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002857 }
2858 }
2859 return false;
2860 }
2861
2862 /**
Robin Lee7e678712014-07-24 16:41:31 +01002863 * Uninstalls the given certificate from trusted user CAs, if present.
2864 *
Robin Lee25e26452015-06-02 09:56:29 -07002865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2866 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002867 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002868 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2869 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002870 */
Robin Lee25e26452015-06-02 09:56:29 -07002871 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002872 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04002873 if (mService != null) {
2874 try {
Robin Lee306fe082014-06-19 14:04:24 +00002875 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07002876 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00002877 } catch (CertificateException e) {
2878 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04002879 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002880 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04002881 }
2882 }
2883 }
2884
2885 /**
Robin Lee7e678712014-07-24 16:41:31 +01002886 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
2887 * If a user has installed any certificates by other means than device policy these will be
2888 * included too.
2889 *
Robin Lee25e26452015-06-02 09:56:29 -07002890 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2891 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002892 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002893 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2894 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002895 */
Robin Lee25e26452015-06-02 09:56:29 -07002896 public List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
Robin Lee7e678712014-07-24 16:41:31 +01002897 List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01002898 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002899 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01002900 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002901 mService.enforceCanManageCaCerts(admin);
2902 final TrustedCertificateStore certStore = new TrustedCertificateStore();
2903 for (String alias : certStore.userAliases()) {
2904 try {
2905 certs.add(certStore.getCertificate(alias).getEncoded());
2906 } catch (CertificateException ce) {
2907 Log.w(TAG, "Could not encode certificate: " + alias, ce);
2908 }
2909 }
2910 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002911 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002912 }
2913 }
2914 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04002915 }
2916
2917 /**
Robin Lee7e678712014-07-24 16:41:31 +01002918 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
2919 * means other than device policy will also be removed, except for system CA certificates.
2920 *
Robin Lee25e26452015-06-02 09:56:29 -07002921 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2922 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002923 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2924 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01002925 */
Robin Lee25e26452015-06-02 09:56:29 -07002926 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002927 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01002928 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07002929 try {
2930 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
2931 .toArray(new String[0]));
2932 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002933 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01002934 }
2935 }
2936 }
2937
2938 /**
2939 * Returns whether this certificate is installed as a trusted CA.
2940 *
Robin Lee25e26452015-06-02 09:56:29 -07002941 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2942 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01002943 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002944 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2945 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04002946 */
Robin Lee25e26452015-06-02 09:56:29 -07002947 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002948 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002949 if (mService != null) {
2950 try {
2951 mService.enforceCanManageCaCerts(admin);
2952 return getCaCertAlias(certBuffer) != null;
2953 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002954 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01002955 } catch (CertificateException ce) {
2956 Log.w(TAG, "Could not parse certificate", ce);
2957 }
Maggie Benthallda51e682013-08-08 22:35:44 -04002958 }
2959 return false;
2960 }
2961
2962 /**
Robin Leece3399f2016-02-24 12:08:32 +00002963 * Called by a device or profile owner, or delegated certificate installer, to install a
2964 * certificate and corresponding private key. All apps within the profile will be able to access
2965 * the certificate and use the private key, given direct user approval.
2966 *
2967 * <p>Access to the installed credentials will not be granted to the caller of this API without
2968 * direct user approval. This is for security - should a certificate installer become
2969 * compromised, certificates it had already installed will be protected.
2970 *
2971 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00002972 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002973 *
Robin Lee25e26452015-06-02 09:56:29 -07002974 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
2975 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002976 * @param privKey The private key to install.
2977 * @param cert The certificate to install.
2978 * @param alias The private key alias under which to install the certificate. If a certificate
2979 * with that alias already exists, it will be overwritten.
2980 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002981 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
2982 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01002983 */
Robin Leefbc65642015-08-03 16:21:22 +01002984 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
2985 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00002986 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00002987 }
2988
2989 /**
2990 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00002991 * certificate chain and corresponding private key for the leaf certificate. All apps within the
2992 * profile will be able to access the certificate chain and use the private key, given direct
2993 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00002994 *
Robin Leea1b290e2016-03-09 14:38:36 +00002995 * <p>The caller of this API may grant itself access to the certificate and private key
2996 * immediately, without user approval. It is a best practice not to request this unless strictly
2997 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00002998 *
2999 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003000 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003001 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003002 * @param certs The certificate chain to install. The chain should start with the leaf
3003 * certificate and include the chain of trust in order. This will be returned by
3004 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003005 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003006 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003007 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003008 * credentials immediately. Otherwise, access to the credentials will be gated by user
3009 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003010 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003011 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3012 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003013 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003014 */
3015 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003016 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003017 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003018 try {
Rubin Xub4365912016-03-23 12:13:22 +00003019 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3020 byte[] pemChain = null;
3021 if (certs.length > 1) {
3022 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3023 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003024 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3025 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003026 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3027 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003028 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003029 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003030 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3031 Log.w(TAG, "Failed to obtain private key material", e);
3032 } catch (CertificateException | IOException e) {
3033 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003034 }
3035 return false;
3036 }
3037
3038 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003039 * Called by a device or profile owner, or delegated certificate installer, to remove a
3040 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003041 *
3042 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003043 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003044 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003045 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003046 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3047 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003048 */
3049 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003050 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003051 try {
3052 return mService.removeKeyPair(admin, alias);
3053 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003054 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003055 }
Robin Leefbc65642015-08-03 16:21:22 +01003056 }
3057
3058 /**
Robin Lee25e26452015-06-02 09:56:29 -07003059 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003060 * doesn't exist.
3061 */
3062 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3063 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3064 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3065 new ByteArrayInputStream(certBuffer));
3066 return new TrustedCertificateStore().getCertificateAlias(cert);
3067 }
3068
3069 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003070 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003071 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003072 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003073 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003074 * <p>
3075 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3076 * it is later cleared by calling this method with a null value or uninstallling the certificate
3077 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003078 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003079 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3080 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003081 * supplied certificate installer package must be installed when calling this API, otherwise an
3082 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003083 *
Robin Lee25e26452015-06-02 09:56:29 -07003084 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003085 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003086 * access. If {@code null} is given the current package will be cleared.
3087 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003088 */
Robin Lee25e26452015-06-02 09:56:29 -07003089 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3090 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003091 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003092 if (mService != null) {
3093 try {
Robin Lee25e26452015-06-02 09:56:29 -07003094 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003095 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003096 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003097 }
3098 }
3099 }
3100
3101 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003102 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3103 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003104 *
Robin Lee25e26452015-06-02 09:56:29 -07003105 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003106 * @return The package name of the current delegated certificate installer, or {@code null} if
3107 * none is set.
3108 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003109 */
Robin Lee25e26452015-06-02 09:56:29 -07003110 public String getCertInstallerPackage(@NonNull ComponentName admin) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003111 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003112 if (mService != null) {
3113 try {
Robin Lee25e26452015-06-02 09:56:29 -07003114 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003115 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003116 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003117 }
3118 }
3119 return null;
3120 }
3121
3122 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003123 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003124 * specific application for the current user.
3125 *
3126 * @deprecated this version only exists for compability with previous developer preview builds.
3127 * TODO: delete once there are no longer any live references.
3128 * @hide
3129 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003130 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003131 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3132 throws NameNotFoundException, UnsupportedOperationException {
3133 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3134 }
3135
3136 /**
3137 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003138 * specific application for the current user. This connection is automatically granted and
3139 * persisted after a reboot.
3140 * <p>
3141 * The designated package should declare a {@link android.net.VpnService} in its manifest
3142 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3143 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003144 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003145 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003146 * remove an existing always-on VPN configuration.
3147 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3148 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3149 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003150 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003151 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3152 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3153 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003154 */
Robin Leedc679712016-05-03 13:23:03 +01003155 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3156 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003157 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003158 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003159 if (mService != null) {
3160 try {
Robin Leedc679712016-05-03 13:23:03 +01003161 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003162 throw new NameNotFoundException(vpnPackage);
3163 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003165 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003166 }
3167 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003168 }
3169
3170 /**
3171 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003172 * always-on VPN connection for the current user. If there is no such package, or the always-on
3173 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003174 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003175 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3176 * is set.
3177 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003178 */
3179 public String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003180 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003181 if (mService != null) {
3182 try {
3183 return mService.getAlwaysOnVpnPackage(admin);
3184 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003185 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003186 }
3187 }
3188 return null;
3189 }
3190
3191 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003192 * Called by an application that is administering the device to disable all cameras on the
3193 * device, for this user. After setting this, no applications running as this user will be able
3194 * to access any cameras on the device.
3195 * <p>
3196 * If the caller is device owner, then the restriction will be applied to all users.
3197 * <p>
3198 * The calling device admin must have requested
3199 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3200 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003201 *
3202 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3203 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003204 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3205 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003206 */
Robin Lee25e26452015-06-02 09:56:29 -07003207 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003208 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003209 if (mService != null) {
3210 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003211 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003212 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003213 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003214 }
3215 }
3216 }
3217
3218 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003219 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003220 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003221 * @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 -07003222 * have disabled the camera
3223 */
Robin Lee25e26452015-06-02 09:56:29 -07003224 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003225 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003226 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003227 }
3228
3229 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003230 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003231 if (mService != null) {
3232 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003233 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003234 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003235 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003236 }
3237 }
3238 return false;
3239 }
3240
3241 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003242 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003243 * <p>
3244 * There must be only one user on the device, managed by the device owner. Otherwise a
3245 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003246 *
3247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003248 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3249 * wasn't triggered because a previous bugreport operation is still active (either the
3250 * bugreport is still running or waiting for the user to share or decline)
3251 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3252 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003253 */
3254 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003255 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003256 if (mService != null) {
3257 try {
3258 return mService.requestBugreport(admin);
3259 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003260 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003261 }
3262 }
3263 return false;
3264 }
3265
3266 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003267 * Determine whether or not creating a guest user has been disabled for the device
3268 *
3269 * @hide
3270 */
3271 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3272 // Currently guest users can always be created if multi-user is enabled
3273 // TODO introduce a policy for guest user creation
3274 return false;
3275 }
3276
3277 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003278 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3279 * screen capture also prevents the content from being shown on display devices that do not have
3280 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3281 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003282 * <p>
3283 * The calling device admin must be a device or profile owner. If it is not, a security
3284 * exception will be thrown.
3285 * <p>
3286 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3287 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003288 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003289 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003290 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003291 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003292 */
Robin Lee25e26452015-06-02 09:56:29 -07003293 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003294 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003295 if (mService != null) {
3296 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003297 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003298 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003299 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003300 }
3301 }
3302 }
3303
3304 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003305 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003306 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003307 * @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 +01003308 * have disabled screen capture.
3309 */
Robin Lee25e26452015-06-02 09:56:29 -07003310 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003311 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003312 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003313 }
3314
3315 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003316 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003317 if (mService != null) {
3318 try {
3319 return mService.getScreenCaptureDisabled(admin, userHandle);
3320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003321 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003322 }
3323 }
3324 return false;
3325 }
3326
3327 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003328 * Called by a device owner to set whether auto time is required. If auto time is required the
3329 * user cannot set the date and time, but has to use network date and time.
3330 * <p>
3331 * Note: if auto time is required the user can still manually set the time zone.
3332 * <p>
3333 * The calling device admin must be a device owner. If it is not, a security exception will be
3334 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003335 *
3336 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3337 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003338 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003339 */
Robin Lee25e26452015-06-02 09:56:29 -07003340 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003341 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003342 if (mService != null) {
3343 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003344 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003345 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003346 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003347 }
3348 }
3349 }
3350
3351 /**
3352 * @return true if auto time is required.
3353 */
3354 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003355 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003356 if (mService != null) {
3357 try {
3358 return mService.getAutoTimeRequired();
3359 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003360 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003361 }
3362 }
3363 return false;
3364 }
3365
3366 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003367 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003368 * <p>
3369 * The system user is exempt from this policy - it is never ephemeral.
3370 * <p>
3371 * The calling device admin must be the device owner. If it is not, a security exception will be
3372 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003373 *
3374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3375 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003376 * subsequently created users will be ephemeral.
3377 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003378 * @hide
3379 */
3380 public void setForceEphemeralUsers(
3381 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003382 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003383 if (mService != null) {
3384 try {
3385 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3386 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003387 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003388 }
3389 }
3390 }
3391
3392 /**
3393 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003394 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003395 * @hide
3396 */
3397 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003398 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003399 if (mService != null) {
3400 try {
3401 return mService.getForceEphemeralUsers(admin);
3402 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003403 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003404 }
3405 }
3406 return false;
3407 }
3408
3409 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003410 * Called by an application that is administering the device to disable keyguard customizations,
3411 * such as widgets. After setting this, keyguard features will be disabled according to the
3412 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003413 * <p>
3414 * The calling device admin must have requested
3415 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3416 * if it has not, a security exception will be thrown.
3417 * <p>
3418 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3419 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3420 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003421 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003422 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003423 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003424 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003425 * there is one, or the parent user otherwise.
3426 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3427 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003428 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003429 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3430 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003431 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3432 * profile.
3433 * <p>
3434 * Requests to disable other features on a managed profile will be ignored.
3435 * <p>
3436 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003437 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003438 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003439 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003440 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003441 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3442 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3443 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3444 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3445 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3446 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3447 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003448 */
Robin Lee25e26452015-06-02 09:56:29 -07003449 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003450 if (mService != null) {
3451 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003452 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003453 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003454 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003455 }
3456 }
3457 }
3458
3459 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003460 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003461 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003462 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3463 *
3464 * <p>This method can be called on the {@link DevicePolicyManager} instance
3465 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3466 * restrictions on the parent profile.
3467 *
Esteban Talavera62399912016-01-11 15:37:55 +00003468 * @param admin The name of the admin component to check, or {@code null} to check whether any
3469 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003470 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3471 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003472 */
Robin Lee25e26452015-06-02 09:56:29 -07003473 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003474 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003475 }
3476
3477 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003478 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003479 if (mService != null) {
3480 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003481 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003482 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003483 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003484 }
3485 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003486 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003487 }
3488
3489 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003490 * @hide
3491 */
Robin Lee25e26452015-06-02 09:56:29 -07003492 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3493 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003494 if (mService != null) {
3495 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003496 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003497 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003498 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003499 }
3500 }
3501 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003502
Dianne Hackbornd6847842010-01-12 18:14:19 -08003503 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003504 * @hide
3505 */
Robin Lee25e26452015-06-02 09:56:29 -07003506 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003507 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003508 }
3509
3510 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003511 * @hide
3512 */
Robin Lee25e26452015-06-02 09:56:29 -07003513 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003514 if (mService != null) {
3515 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003516 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003517 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003518 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003519 }
3520 }
3521 }
3522
3523 /**
3524 * @hide
3525 */
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003526 public void setActivePasswordState(int quality, int length, int letters, int uppercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003527 int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003528 if (mService != null) {
3529 try {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07003530 mService.setActivePasswordState(quality, length, letters, uppercase, lowercase,
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003531 numbers, symbols, nonletter, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003532 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003533 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003534 }
3535 }
3536 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003537
Dianne Hackbornd6847842010-01-12 18:14:19 -08003538 /**
3539 * @hide
3540 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003541 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003542 if (mService != null) {
3543 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003544 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003545 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003546 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003547 }
3548 }
3549 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003550
Dianne Hackbornd6847842010-01-12 18:14:19 -08003551 /**
3552 * @hide
3553 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003554 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003555 if (mService != null) {
3556 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003557 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003558 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003559 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003560 }
3561 }
3562 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003563
3564 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003565 * @hide
3566 */
3567 public void reportFailedFingerprintAttempt(int userHandle) {
3568 if (mService != null) {
3569 try {
3570 mService.reportFailedFingerprintAttempt(userHandle);
3571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003572 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003573 }
3574 }
3575 }
3576
3577 /**
3578 * @hide
3579 */
3580 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3581 if (mService != null) {
3582 try {
3583 mService.reportSuccessfulFingerprintAttempt(userHandle);
3584 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003585 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003586 }
3587 }
3588 }
3589
3590 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003591 * Should be called when keyguard has been dismissed.
3592 * @hide
3593 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003594 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003595 if (mService != null) {
3596 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003597 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003598 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003599 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003600 }
3601 }
3602 }
3603
3604 /**
3605 * Should be called when keyguard view has been shown to the user.
3606 * @hide
3607 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003608 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003609 if (mService != null) {
3610 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003611 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003613 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003614 }
3615 }
3616 }
3617
3618 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003619 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003620 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003621 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3622 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003623 * @return whether the package was successfully registered as the device owner.
3624 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003625 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003626 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003627 public boolean setDeviceOwner(ComponentName who) {
3628 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003629 }
3630
3631 /**
3632 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003633 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003634 public boolean setDeviceOwner(ComponentName who, int userId) {
3635 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003636 }
3637
3638 /**
3639 * @hide
3640 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003641 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3642 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003643 }
3644
3645 /**
3646 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003647 * Sets the given package as the device owner. The package must already be installed. There
3648 * must not already be a device owner.
3649 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3650 * this method.
3651 * Calling this after the setup phase of the primary user has completed is allowed only if
3652 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003653 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003654 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003655 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003656 * @return whether the package was successfully registered as the device owner.
3657 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003658 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003659 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003660 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003661 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003662 if (mService != null) {
3663 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003664 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003665 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003666 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003667 }
3668 }
3669 return false;
3670 }
3671
3672 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003673 * Used to determine if a particular package has been registered as a Device Owner app.
3674 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003675 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003676 * package is currently registered as the device owner app, pass in the package name from
3677 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003678 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003679 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3680 * the setup process.
3681 * @param packageName the package name of the app, to compare with the registered device owner
3682 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003683 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003684 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003685 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003686 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003687 return isDeviceOwnerAppOnCallingUser(packageName);
3688 }
3689
3690 /**
3691 * @return true if a package is registered as device owner, only when it's running on the
3692 * calling user.
3693 *
3694 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3695 * @hide
3696 */
3697 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3698 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3699 }
3700
3701 /**
3702 * @return true if a package is registered as device owner, even if it's running on a different
3703 * user.
3704 *
3705 * <p>Requires the MANAGE_USERS permission.
3706 *
3707 * @hide
3708 */
3709 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3710 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3711 }
3712
3713 /**
3714 * @return device owner component name, only when it's running on the calling user.
3715 *
3716 * @hide
3717 */
3718 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3719 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3720 }
3721
3722 /**
3723 * @return device owner component name, even if it's running on a different user.
3724 *
3725 * <p>Requires the MANAGE_USERS permission.
3726 *
3727 * @hide
3728 */
3729 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3730 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3731 }
3732
3733 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003734 if (packageName == null) {
3735 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003736 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003737 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003738 if (deviceOwner == null) {
3739 return false;
3740 }
3741 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003742 }
3743
Makoto Onukic8a5a552015-11-19 14:29:12 -08003744 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3745 if (mService != null) {
3746 try {
3747 return mService.getDeviceOwnerComponent(callingUserOnly);
3748 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003749 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003750 }
3751 }
3752 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003753 }
3754
Jason Monkb0dced82014-06-06 14:36:20 -04003755 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003756 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3757 * no device owner.
3758 *
3759 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003760 *
3761 * @hide
3762 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003763 public int getDeviceOwnerUserId() {
3764 if (mService != null) {
3765 try {
3766 return mService.getDeviceOwnerUserId();
3767 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003768 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003769 }
3770 }
3771 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003772 }
3773
3774 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003775 * Clears the current device owner. The caller must be the device owner. This function should be
3776 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
3777 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04003778 *
3779 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003780 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
3781 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04003782 */
Jason Monk94d2cf92014-06-18 09:53:34 -04003783 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003784 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04003785 if (mService != null) {
3786 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04003787 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04003788 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003789 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04003790 }
3791 }
3792 }
3793
Makoto Onukia52562c2015-10-01 16:12:31 -07003794 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003795 * Returns the device owner package name, only if it's running on the calling user.
3796 *
3797 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07003798 *
3799 * @hide
3800 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01003801 @SystemApi
Amith Yamasani71e6c692013-03-24 17:39:28 -07003802 public String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003803 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003804 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
3805 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07003806 }
3807
3808 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003809 * @return true if the device is managed by any device owner.
3810 *
3811 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003812 *
3813 * @hide
3814 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003815 public boolean isDeviceManaged() {
3816 return getDeviceOwnerComponentOnAnyUser() != null;
3817 }
3818
3819 /**
3820 * Returns the device owner name. Note this method *will* return the device owner
3821 * name when it's running on a different user.
3822 *
3823 * <p>Requires the MANAGE_USERS permission.
3824 *
3825 * @hide
3826 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08003827 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003828 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003829 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07003830 if (mService != null) {
3831 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003832 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003833 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003834 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003835 }
3836 }
3837 return null;
3838 }
Adam Connors776c5552014-01-09 10:42:56 +00003839
3840 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04003841 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003842 * @deprecated Do not use
3843 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05003844 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003845 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05003846 @SystemApi
3847 public String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05003848 return null;
3849 }
3850
3851 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003852 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003853 * @deprecated Do not use
3854 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003855 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04003856 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003857 @SystemApi
3858 public ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04003859 return null;
3860 }
3861
Julia Reynolds20118f12015-02-11 12:34:08 -05003862 /**
Adam Connors776c5552014-01-09 10:42:56 +00003863 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003864 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303865 * Sets the given component as an active admin and registers the package as the profile
3866 * owner for this user. The package must already be installed and there shouldn't be
3867 * an existing profile owner registered for this user. Also, this method must be called
3868 * before the user setup has been completed.
3869 * <p>
3870 * This method can only be called by system apps that hold MANAGE_USERS permission and
3871 * MANAGE_DEVICE_ADMINS permission.
3872 * @param admin The component to register as an active admin and profile owner.
3873 * @param ownerName The user-visible name of the entity that is managing this user.
3874 * @return whether the admin was successfully registered as the profile owner.
3875 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
3876 * the user has already been set up.
3877 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003878 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05003879 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07003880 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303881 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003882 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303883 if (mService != null) {
3884 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003885 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303886 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003887 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303888 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003889 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05303890 }
3891 }
3892 return false;
3893 }
3894
3895 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003896 * Clears the active profile owner and removes all user restrictions. The caller must be from
3897 * the same package as the active profile owner for this user, otherwise a SecurityException
3898 * will be thrown.
3899 * <p>
3900 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08003901 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003902 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003903 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003904 */
Robin Lee25e26452015-06-02 09:56:29 -07003905 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003906 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003907 if (mService != null) {
3908 try {
3909 mService.clearProfileOwner(admin);
3910 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003911 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003912 }
3913 }
3914 }
3915
3916 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05003917 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07003918 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003919 */
3920 public boolean hasUserSetupCompleted() {
3921 if (mService != null) {
3922 try {
3923 return mService.hasUserSetupCompleted();
3924 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003925 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003926 }
3927 }
3928 return true;
3929 }
3930
3931 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003932 * @hide
3933 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00003934 * already be installed. There must not already be a profile owner for this user.
3935 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3936 * this method.
3937 * Calling this after the setup phase of the specified user has completed is allowed only if:
3938 * - the caller is SYSTEM_UID.
3939 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003940 * @param admin the component name to be registered as profile owner.
3941 * @param ownerName the human readable name of the organisation associated with this DPM.
3942 * @param userHandle the userId to set the profile owner for.
3943 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00003944 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
3945 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003946 */
Robin Lee25e26452015-06-02 09:56:29 -07003947 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01003948 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00003949 if (mService != null) {
3950 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07003951 if (ownerName == null) {
3952 ownerName = "";
3953 }
3954 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00003955 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003956 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00003957 }
3958 }
3959 return false;
3960 }
3961
3962 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003963 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003964 * <p>
3965 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003966 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003967 * <p>
3968 * If the device owner information contains only whitespaces then the message on the lock screen
3969 * will be blank and the user will not be allowed to change it.
3970 * <p>
3971 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00003972 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
3973 * and set a new version of this string accordingly.
3974 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003975 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003976 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003977 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003978 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003979 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003980 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003981 if (mService != null) {
3982 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003983 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003984 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003985 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003986 }
3987 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003988 }
3989
3990 /**
3991 * @return The device owner information. If it is not set returns {@code null}.
3992 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00003993 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003994 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00003995 if (mService != null) {
3996 try {
3997 return mService.getDeviceOwnerLockScreenInfo();
3998 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003999 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004000 }
4001 }
4002 return null;
4003 }
4004
4005 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004006 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004007 * <p>
4008 * A suspended package will not be able to start activities. Its notifications will be hidden,
4009 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4010 * device.
4011 * <p>
4012 * The package must already be installed. If the package is uninstalled while suspended the
4013 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004014 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004015 *
4016 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004017 * @param packageNames The package names to suspend or unsuspend.
4018 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004019 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004020 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004021 * this method.
4022 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004023 */
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004024 public String[] setPackagesSuspended(@NonNull ComponentName admin, String[] packageNames,
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004025 boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004026 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004027 if (mService != null) {
4028 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004029 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004030 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004031 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004032 }
4033 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004034 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004035 }
4036
4037 /**
4038 * Called by device or profile owners to determine if a package is suspended.
4039 *
4040 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4041 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004042 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004043 * suspended, could not be found or an error occurred.
4044 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004045 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004046 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004047 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4048 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004049 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004050 if (mService != null) {
4051 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004052 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004053 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004054 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004055 } catch (IllegalArgumentException ex) {
4056 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004057 }
4058 }
4059 return false;
4060 }
4061
4062 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004063 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4064 * be used. Only the profile owner can call this.
4065 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004066 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004067 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004068 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004069 */
Robin Lee25e26452015-06-02 09:56:29 -07004070 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004071 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004072 if (mService != null) {
4073 try {
4074 mService.setProfileEnabled(admin);
4075 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004076 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004077 }
4078 }
4079 }
4080
4081 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004082 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4083 * is called from. Only a profile owner or device owner can call this. If this is never called
4084 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004085 *
4086 * @see #isProfileOwnerApp
4087 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004088 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004089 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004090 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004091 */
Robin Lee25e26452015-06-02 09:56:29 -07004092 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004093 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004094 if (mService != null) {
4095 try {
Robin Lee25e26452015-06-02 09:56:29 -07004096 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004098 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004099 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004100 }
4101 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004102
4103 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004104 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004105 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004106 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004107 *
4108 * @param packageName The package name of the app to compare with the registered profile owner.
4109 * @return Whether or not the package is registered as the profile owner.
4110 */
4111 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004112 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004113 if (mService != null) {
4114 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004115 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004116 return profileOwner != null
4117 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004118 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004119 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004120 }
4121 }
4122 return false;
4123 }
4124
4125 /**
4126 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004127 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004128 * owner has been set for that user.
4129 * @throws IllegalArgumentException if the userId is invalid.
4130 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004131 @SystemApi
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004132 public ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004133 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004134 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4135 }
4136
4137 /**
4138 * @see #getProfileOwner()
4139 * @hide
4140 */
4141 public ComponentName getProfileOwnerAsUser(final int userId) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004142 if (mService != null) {
4143 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004144 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004145 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004146 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004147 }
4148 }
4149 return null;
4150 }
4151
4152 /**
4153 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004154 * @return the human readable name of the organisation associated with this DPM or {@code null}
4155 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004156 * @throws IllegalArgumentException if the userId is invalid.
4157 */
4158 public String getProfileOwnerName() throws IllegalArgumentException {
4159 if (mService != null) {
4160 try {
4161 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4162 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004163 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004164 }
4165 }
4166 return null;
4167 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004168
4169 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004170 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004171 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004172 * @return the human readable name of the organisation associated with this profile owner or
4173 * null if one is not set.
4174 * @throws IllegalArgumentException if the userId is invalid.
4175 */
4176 @SystemApi
Selim Cinek24ac55e2014-08-27 12:51:45 +02004177 public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004178 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004179 if (mService != null) {
4180 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004181 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004182 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004183 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004184 }
4185 }
4186 return null;
4187 }
4188
4189 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004190 * Called by a profile owner or device owner to add a default intent handler activity for
4191 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004192 * handler even if the set of potential event handlers for the intent filter changes and if the
4193 * intent preferences are reset.
4194 * <p>
4195 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4196 * When the activity is (re)installed, it is automatically reset as default intent handler for
4197 * the filter.
4198 * <p>
4199 * The calling device admin must be a profile owner or device owner. If it is not, a security
4200 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004201 *
4202 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4203 * @param filter The IntentFilter for which a default handler is added.
4204 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004205 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004206 */
Robin Lee25e26452015-06-02 09:56:29 -07004207 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4208 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004209 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004210 if (mService != null) {
4211 try {
4212 mService.addPersistentPreferredActivity(admin, filter, activity);
4213 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004214 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004215 }
4216 }
4217 }
4218
4219 /**
4220 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004221 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004222 * <p>
4223 * The calling device admin must be a profile owner. If it is not, a security exception will be
4224 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004225 *
4226 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4227 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004228 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004229 */
Robin Lee25e26452015-06-02 09:56:29 -07004230 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004231 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004232 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004233 if (mService != null) {
4234 try {
4235 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4236 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004237 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004238 }
4239 }
4240 }
Robin Lee66e5d962014-04-09 16:44:21 +01004241
4242 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004243 * Called by a profile owner or device owner to grant permission to a package to manage
4244 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4245 * {@link #getApplicationRestrictions}.
4246 * <p>
4247 * This permission is persistent until it is later cleared by calling this method with a
4248 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004249 * <p>
4250 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004251 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004252 *
4253 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4254 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004255 * APIs. If {@code null} is given the current package will be cleared.
4256 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004257 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004258 */
4259 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004260 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004261 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004262 if (mService != null) {
4263 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004264 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4265 throw new NameNotFoundException(packageName);
4266 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004267 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004268 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004269 }
4270 }
4271 }
4272
4273 /**
4274 * Called by a profile owner or device owner to retrieve the application restrictions managing
4275 * package for the current user, or {@code null} if none is set.
4276 *
4277 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4278 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004279 * {@code null} if none is set.
4280 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004281 */
4282 public String getApplicationRestrictionsManagingPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004283 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004284 if (mService != null) {
4285 try {
4286 return mService.getApplicationRestrictionsManagingPackage(admin);
4287 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004288 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004289 }
4290 }
4291 return null;
4292 }
4293
4294 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004295 * Called by any application to find out whether it has been granted permission via
4296 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4297 * for the calling user.
4298 *
4299 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4300 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004301 */
4302 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004303 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004304 if (mService != null) {
4305 try {
4306 return mService.isCallerApplicationRestrictionsManagingPackage();
4307 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004308 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004309 }
4310 }
4311 return false;
4312 }
4313
4314 /**
4315 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004316 * <p>
4317 * The caller must be a profile or device owner on that user, or the package allowed to manage
4318 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4319 * security exception will be thrown.
4320 * <p>
4321 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004322 * <ul>
4323 * <li>{@code boolean}
4324 * <li>{@code int}
4325 * <li>{@code String} or {@code String[]}
4326 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4327 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004328 * <p>
4329 * If the restrictions are not available yet, but may be applied in the near future, the caller
4330 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004331 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004332 * <p>
4333 * The application restrictions are only made visible to the target application via
4334 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4335 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004336 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004337 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004338 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4339 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004340 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004341 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004342 * @param packageName The name of the package to update restricted settings for.
4343 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004344 * set of active restrictions.
4345 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004346 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004347 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004348 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004349 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004350 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004351 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004352 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004353 if (mService != null) {
4354 try {
4355 mService.setApplicationRestrictions(admin, packageName, settings);
4356 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004357 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004358 }
4359 }
4360 }
4361
4362 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004363 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4364 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4365 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004366 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004367 * <p>
4368 * The calling device admin must have requested
4369 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4370 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004371 * <p>
4372 * This method can be called on the {@link DevicePolicyManager} instance returned by
4373 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4374 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004375 *
4376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004377 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004378 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4379 * strictly disabled according to the state of the
4380 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4381 * <p>
4382 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4383 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4384 * device admins.
4385 * <p>
4386 * Consult documentation for the specific TrustAgent to determine legal options
4387 * parameters.
4388 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4389 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004390 */
Robin Lee25e26452015-06-02 09:56:29 -07004391 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4392 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004393 if (mService != null) {
4394 try {
Tony Mak089d8402016-04-05 17:42:55 +01004395 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004396 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004397 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004398 }
4399 }
4400 }
4401
4402 /**
Jim Millere303bf42014-08-26 17:12:29 -07004403 * Gets configuration for the given trust agent based on aggregating all calls to
4404 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4405 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004406 * <p>
4407 * This method can be called on the {@link DevicePolicyManager} instance returned by
4408 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4409 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004410 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004411 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4412 * this function returns a list of configurations for all admins that declare
4413 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4414 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4415 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4416 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004417 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004418 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004419 */
Robin Lee25e26452015-06-02 09:56:29 -07004420 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4421 @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004422 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004423 }
4424
4425 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07004426 public List<PersistableBundle> getTrustAgentConfiguration(@Nullable ComponentName admin,
4427 @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004428 if (mService != null) {
4429 try {
Tony Mak089d8402016-04-05 17:42:55 +01004430 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4431 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004432 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004433 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004434 }
4435 }
Jim Millere303bf42014-08-26 17:12:29 -07004436 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004437 }
4438
4439 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004440 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4441 * managed profile will be shown in the parent profile, for incoming calls.
4442 * <p>
4443 * The calling device admin must be a profile owner. If it is not, a security exception will be
4444 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004445 *
Robin Lee25e26452015-06-02 09:56:29 -07004446 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004447 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004448 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004449 */
Robin Lee25e26452015-06-02 09:56:29 -07004450 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004451 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004452 if (mService != null) {
4453 try {
Robin Lee25e26452015-06-02 09:56:29 -07004454 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004455 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004456 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004457 }
4458 }
4459 }
4460
4461 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004462 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4463 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004464 * <p>
4465 * The calling device admin must be a profile owner. If it is not, a security exception will be
4466 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004467 *
Robin Lee25e26452015-06-02 09:56:29 -07004468 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004469 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004470 */
Robin Lee25e26452015-06-02 09:56:29 -07004471 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004472 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004473 if (mService != null) {
4474 try {
Robin Lee25e26452015-06-02 09:56:29 -07004475 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004477 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004478 }
4479 }
4480 return false;
4481 }
4482
4483 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004484 * Determine whether or not caller-Id information has been disabled.
4485 *
4486 * @param userHandle The user for whom to check the caller-id permission
4487 * @hide
4488 */
4489 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4490 if (mService != null) {
4491 try {
4492 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4493 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004494 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004495 }
4496 }
4497 return false;
4498 }
4499
4500 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004501 * Called by a profile owner of a managed profile to set whether contacts search from the
4502 * managed profile will be shown in the parent profile, for incoming calls.
4503 * <p>
4504 * The calling device admin must be a profile owner. If it is not, a security exception will be
4505 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004506 *
4507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4508 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004509 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004510 */
4511 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4512 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004513 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004514 if (mService != null) {
4515 try {
4516 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4517 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004518 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004519 }
4520 }
4521 }
4522
4523 /**
4524 * Called by a profile owner of a managed profile to determine whether or not contacts search
4525 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004526 * <p>
4527 * The calling device admin must be a profile owner. If it is not, a security exception will be
4528 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004529 *
4530 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004531 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004532 */
4533 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004534 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004535 if (mService != null) {
4536 try {
4537 return mService.getCrossProfileContactsSearchDisabled(admin);
4538 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004539 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004540 }
4541 }
4542 return false;
4543 }
4544
4545
4546 /**
4547 * Determine whether or not contacts search has been disabled.
4548 *
4549 * @param userHandle The user for whom to check the contacts search permission
4550 * @hide
4551 */
4552 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4553 if (mService != null) {
4554 try {
4555 return mService
4556 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4557 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004558 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004559 }
4560 }
4561 return false;
4562 }
4563
4564 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004565 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004566 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004567 * @hide
4568 */
4569 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004570 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004571 if (mService != null) {
4572 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004573 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4574 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004575 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004576 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004577 }
4578 }
4579 }
4580
4581 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004582 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004583 * @hide
4584 */
4585 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4586 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004587 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004588 originalIntent);
4589 }
4590
4591 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004592 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4593 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004594 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004595 * The calling device admin must be a profile owner. If it is not, a security exception will be
4596 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004597 * <p>
4598 * This API works on managed profile only.
4599 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4601 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4602 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004603 */
Robin Lee25e26452015-06-02 09:56:29 -07004604 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004605 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004606 if (mService != null) {
4607 try {
Robin Lee25e26452015-06-02 09:56:29 -07004608 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004609 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004610 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004611 }
4612 }
4613 }
4614
4615 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004616 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4617 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004618 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004619 * The calling device admin must be a profile owner. If it is not, a security exception will be
4620 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004621 * <p>
4622 * This API works on managed profile only.
4623 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4625 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004626 */
Robin Lee25e26452015-06-02 09:56:29 -07004627 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004628 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004629 if (mService != null) {
4630 try {
Robin Lee25e26452015-06-02 09:56:29 -07004631 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004632 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004633 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004634 }
4635 }
4636 return true;
4637 }
4638
4639 /**
4640 * Determine whether or not Bluetooth devices cannot access contacts.
4641 * <p>
4642 * This API works on managed profile UserHandle only.
4643 *
4644 * @param userHandle The user for whom to check the caller-id permission
4645 * @hide
4646 */
4647 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4648 if (mService != null) {
4649 try {
4650 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4651 .getIdentifier());
4652 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004653 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004654 }
4655 }
4656 return true;
4657 }
4658
4659 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004660 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004661 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4662 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004663 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004665 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004666 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004667 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004668 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4669 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004670 */
Robin Lee25e26452015-06-02 09:56:29 -07004671 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004672 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004673 if (mService != null) {
4674 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004675 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004676 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004677 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004678 }
4679 }
4680 }
4681
4682 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004683 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4684 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004685 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004686 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004687 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004688 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004689 */
Robin Lee25e26452015-06-02 09:56:29 -07004690 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004691 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004692 if (mService != null) {
4693 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004694 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004695 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004696 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004697 }
4698 }
4699 }
4700
4701 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004702 * Called by a profile or device owner to set the permitted accessibility services. When set by
4703 * a device owner or profile owner the restriction applies to all profiles of the user the
4704 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4705 * service. When zero or more packages have been added, accessiblity services that are not in
4706 * the list and not part of the system can not be enabled by the user.
4707 * <p>
4708 * Calling with a null value for the list disables the restriction so that all services can be
4709 * used, calling with an empty list only allows the builtin system's services.
4710 * <p>
4711 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004712 *
4713 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4714 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004715 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4716 * accessibility services enabled, that are not in the list.
4717 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004718 */
Robin Lee25e26452015-06-02 09:56:29 -07004719 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004720 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004721 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004722 if (mService != null) {
4723 try {
4724 return mService.setPermittedAccessibilityServices(admin, packageNames);
4725 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004726 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004727 }
4728 }
4729 return false;
4730 }
4731
4732 /**
4733 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004734 * <p>
4735 * An empty list means no accessibility services except system services are allowed. Null means
4736 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004737 *
4738 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4739 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004740 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004741 */
Robin Lee25e26452015-06-02 09:56:29 -07004742 public List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004743 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004744 if (mService != null) {
4745 try {
4746 return mService.getPermittedAccessibilityServices(admin);
4747 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004748 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004749 }
4750 }
4751 return null;
4752 }
4753
4754 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004755 * Called by the system to check if a specific accessibility service is disabled by admin.
4756 *
4757 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4758 * @param packageName Accessibility service package name that needs to be checked.
4759 * @param userHandle user id the admin is running as.
4760 * @return true if the accessibility service is permitted, otherwise false.
4761 *
4762 * @hide
4763 */
4764 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
4765 @NonNull String packageName, int userHandle) {
4766 if (mService != null) {
4767 try {
4768 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
4769 userHandle);
4770 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004771 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004772 }
4773 }
4774 return false;
4775 }
4776
4777 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004778 * Returns the list of accessibility services permitted by the device or profiles
4779 * owners of this user.
4780 *
4781 * <p>Null means all accessibility services are allowed, if a non-null list is returned
4782 * it will contain the intersection of the permitted lists for any device or profile
4783 * owners that apply to this user. It will also include any system accessibility services.
4784 *
4785 * @param userId which user to check for.
4786 * @return List of accessiblity service package names.
4787 * @hide
4788 */
4789 @SystemApi
4790 public List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004791 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004792 if (mService != null) {
4793 try {
4794 return mService.getPermittedAccessibilityServicesForUser(userId);
4795 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004796 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004797 }
4798 }
4799 return null;
4800 }
4801
4802 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004803 * Called by a profile or device owner to set the permitted input methods services. When set by
4804 * a device owner or profile owner the restriction applies to all profiles of the user the
4805 * device owner or profile owner is an admin for. By default the user can use any input method.
4806 * When zero or more packages have been added, input method that are not in the list and not
4807 * part of the system can not be enabled by the user. This method will fail if it is called for
4808 * a admin that is not for the foreground user or a profile of the foreground user.
4809 * <p>
4810 * Calling with a null value for the list disables the restriction so that all input methods can
4811 * be used, calling with an empty list disables all but the system's own input methods.
4812 * <p>
4813 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004814 *
4815 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4816 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004817 * @return true if setting the restriction succeeded. It will fail if there are one or more
4818 * non-system input methods currently enabled that are not in the packageNames list.
4819 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004820 */
Robin Lee25e26452015-06-02 09:56:29 -07004821 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004822 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004823 if (mService != null) {
4824 try {
4825 return mService.setPermittedInputMethods(admin, packageNames);
4826 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004827 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004828 }
4829 }
4830 return false;
4831 }
4832
4833
4834 /**
4835 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004836 * <p>
4837 * An empty list means no input methods except system input methods are allowed. Null means all
4838 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004839 *
4840 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4841 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004842 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004843 */
Robin Lee25e26452015-06-02 09:56:29 -07004844 public List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004845 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004846 if (mService != null) {
4847 try {
4848 return mService.getPermittedInputMethods(admin);
4849 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004850 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004851 }
4852 }
4853 return null;
4854 }
4855
4856 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004857 * Called by the system to check if a specific input method is disabled by admin.
4858 *
4859 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4860 * @param packageName Input method package name that needs to be checked.
4861 * @param userHandle user id the admin is running as.
4862 * @return true if the input method is permitted, otherwise false.
4863 *
4864 * @hide
4865 */
4866 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
4867 @NonNull String packageName, int userHandle) {
4868 if (mService != null) {
4869 try {
4870 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
4871 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004872 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00004873 }
4874 }
4875 return false;
4876 }
4877
4878 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004879 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08004880 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004881 *
4882 * <p>Null means all input methods are allowed, if a non-null list is returned
4883 * it will contain the intersection of the permitted lists for any device or profile
4884 * owners that apply to this user. It will also include any system input methods.
4885 *
4886 * @return List of input method package names.
4887 * @hide
4888 */
4889 @SystemApi
4890 public List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004891 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004892 if (mService != null) {
4893 try {
4894 return mService.getPermittedInputMethodsForCurrentUser();
4895 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004896 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004897 }
4898 }
4899 return null;
4900 }
4901
4902 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004903 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
4904 * currently installed it.
4905 *
4906 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4907 *
4908 * @return List of package names to keep cached.
4909 * @hide
4910 */
4911 public List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004912 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004913 if (mService != null) {
4914 try {
4915 return mService.getKeepUninstalledPackages(admin);
4916 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004917 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004918 }
4919 }
4920 return null;
4921 }
4922
4923 /**
4924 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
4925 * currently installed it.
4926 *
4927 * <p>Please note that setting this policy does not imply that specified apps will be
4928 * automatically pre-cached.</p>
4929 *
4930 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4931 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004932 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004933 * @hide
4934 */
4935 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
4936 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004937 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004938 if (mService != null) {
4939 try {
4940 mService.setKeepUninstalledPackages(admin, packageNames);
4941 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004942 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08004943 }
4944 }
4945 }
4946
4947 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04004948 * Called by a device owner to create a user with the specified name. The UserHandle returned
4949 * by this method should not be persisted as user handles are recycled as users are removed and
4950 * created. If you need to persist an identifier for this user, use
4951 * {@link UserManager#getSerialNumberForUser}.
4952 *
4953 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4954 * @param name the user's name
4955 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004956 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4957 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004958 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004959 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004960 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04004961 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004962 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004963 public UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04004964 return null;
4965 }
4966
4967 /**
Jason Monk03978a42014-06-10 15:05:30 -04004968 * Called by a device owner to create a user with the specified name. The UserHandle returned
4969 * by this method should not be persisted as user handles are recycled as users are removed and
4970 * created. If you need to persist an identifier for this user, use
4971 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
4972 * immediately.
4973 *
4974 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
4975 * as registered as an active admin on the new user. The profile owner package will be
4976 * installed on the new user if it already is installed on the device.
4977 *
4978 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
4979 * profileOwnerComponent when onEnable is called.
4980 *
4981 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4982 * @param name the user's name
4983 * @param ownerName the human readable name of the organisation associated with this DPM.
4984 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
4985 * the user.
4986 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
4987 * on the new user.
4988 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07004989 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
4990 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01004991 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07004992 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01004993 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04004994 */
Kenny Guy14f48e52015-06-29 15:12:36 +01004995 @Deprecated
Robin Lee25e26452015-06-02 09:56:29 -07004996 public UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
4997 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04004998 return null;
4999 }
5000
5001 /**
phweissa92e1212016-01-25 17:14:10 +01005002 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005003 */
5004 public static final int SKIP_SETUP_WIZARD = 0x0001;
5005
5006 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005007 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5008 * ephemeral.
5009 * @hide
5010 */
5011 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5012
5013 /**
phweissa92e1212016-01-25 17:14:10 +01005014 * Called by a device owner to create a user with the specified name and a given component of
5015 * the calling package as profile owner. The UserHandle returned by this method should not be
5016 * persisted as user handles are recycled as users are removed and created. If you need to
5017 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5018 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005019 * <p>
5020 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5021 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5022 * be registered as an active admin on the new user. The profile owner package will be installed
5023 * on the new user.
5024 * <p>
5025 * If the adminExtras are not null, they will be stored on the device until the user is started
5026 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005027 *
5028 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5029 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005030 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005031 * same package as admin, otherwise no user is created and an
5032 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005033 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005034 * user.
phweissa92e1212016-01-25 17:14:10 +01005035 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005036 * @see UserHandle
5037 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5038 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005039 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005040 */
5041 public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005042 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5043 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005044 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005045 try {
phweissa92e1212016-01-25 17:14:10 +01005046 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005047 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005048 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005049 }
phweiss343fb332016-01-25 14:48:59 +01005050 }
5051
5052 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005053 * Called by a device owner to remove a user and all associated data. The primary user can not
5054 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005055 *
5056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5057 * @param userHandle the user to remove.
5058 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005059 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005060 */
Robin Lee25e26452015-06-02 09:56:29 -07005061 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005062 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005063 try {
5064 return mService.removeUser(admin, userHandle);
5065 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005066 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005067 }
5068 }
5069
5070 /**
Jason Monk582d9112014-07-09 19:57:08 -04005071 * Called by a device owner to switch the specified user to the foreground.
5072 *
5073 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5074 * @param userHandle the user to switch to; null will switch to primary.
5075 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005076 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005077 * @see Intent#ACTION_USER_FOREGROUND
5078 */
Robin Lee25e26452015-06-02 09:56:29 -07005079 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005080 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005081 try {
5082 return mService.switchUser(admin, userHandle);
5083 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005084 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005085 }
5086 }
5087
5088 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005089 * Retrieves the application restrictions for a given target application running in the calling
5090 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005091 * <p>
5092 * The caller must be a profile or device owner on that user, or the package allowed to manage
5093 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5094 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005095 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005096 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5097 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005099 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005100 * @param packageName The name of the package to fetch restricted settings of.
5101 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005102 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5103 * {@link Bundle} if no restrictions have been set.
5104 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005105 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005106 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005107 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00005108 public Bundle getApplicationRestrictions(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005109 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005110 if (mService != null) {
5111 try {
5112 return mService.getApplicationRestrictions(admin, packageName);
5113 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005114 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005115 }
5116 }
5117 return null;
5118 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005119
5120 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005121 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005122 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005123 * The calling device admin must be a profile or device owner; if it is not, a security
5124 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005125 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005126 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5127 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5128 * for the list of keys.
5129 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005130 */
Robin Lee25e26452015-06-02 09:56:29 -07005131 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005132 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005133 if (mService != null) {
5134 try {
5135 mService.setUserRestriction(admin, key, true);
5136 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005137 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005138 }
5139 }
5140 }
5141
5142 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005143 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005144 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005145 * The calling device admin must be a profile or device owner; if it is not, a security
5146 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005147 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005148 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5149 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5150 * for the list of keys.
5151 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005152 */
Robin Lee25e26452015-06-02 09:56:29 -07005153 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005154 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005155 if (mService != null) {
5156 try {
5157 mService.setUserRestriction(admin, key, false);
5158 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005159 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005160 }
5161 }
5162 }
Adam Connors010cfd42014-04-16 12:48:13 +01005163
5164 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005165 * Called by a profile or device owner to get user restrictions set with
5166 * {@link #addUserRestriction(ComponentName, String)}.
5167 * <p>
5168 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005169 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005170 * {@link UserManager#getUserRestrictions()}.
5171 *
5172 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005173 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005174 */
5175 public Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005176 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005177 Bundle ret = null;
5178 if (mService != null) {
5179 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005180 ret = mService.getUserRestrictions(admin);
5181 } catch (RemoteException e) {
5182 throw e.rethrowFromSystemServer();
5183 }
5184 }
5185 return ret == null ? new Bundle() : ret;
5186 }
5187
5188 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005189 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5190 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005191 *
5192 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005193 * @param packageName The name of the package to hide or unhide.
5194 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005195 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005196 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005197 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005198 */
Robin Lee25e26452015-06-02 09:56:29 -07005199 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005200 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005201 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005202 if (mService != null) {
5203 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005204 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005205 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005206 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005207 }
5208 }
5209 return false;
5210 }
5211
5212 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005213 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005214 *
5215 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005216 * @param packageName The name of the package to retrieve the hidden status of.
5217 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005218 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005219 */
Robin Lee25e26452015-06-02 09:56:29 -07005220 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005221 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005222 if (mService != null) {
5223 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005224 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005225 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005226 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005227 }
5228 }
5229 return false;
5230 }
5231
5232 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005233 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005234 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005235 *
5236 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005237 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005238 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005239 */
Robin Lee25e26452015-06-02 09:56:29 -07005240 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005241 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005242 if (mService != null) {
5243 try {
5244 mService.enableSystemApp(admin, packageName);
5245 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005246 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005247 }
5248 }
5249 }
5250
5251 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005252 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5253 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005254 *
5255 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5256 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005257 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005258 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005259 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005260 */
Robin Lee25e26452015-06-02 09:56:29 -07005261 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005262 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005263 if (mService != null) {
5264 try {
5265 return mService.enableSystemAppWithIntent(admin, intent);
5266 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005267 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005268 }
5269 }
5270 return 0;
5271 }
5272
5273 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005274 * Called by a device owner or profile owner to disable account management for a specific type
5275 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005276 * <p>
5277 * The calling device admin must be a device owner or profile owner. If it is not, a security
5278 * exception will be thrown.
5279 * <p>
5280 * When account management is disabled for an account type, adding or removing an account of
5281 * that type will not be possible.
5282 * <p>
5283 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005284 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5285 * management for a specific type is disabled.
5286 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005287 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5288 * @param accountType For which account management is disabled or enabled.
5289 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005290 * enabled (false).
5291 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005292 */
Robin Lee25e26452015-06-02 09:56:29 -07005293 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005294 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005295 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005296 if (mService != null) {
5297 try {
5298 mService.setAccountManagementDisabled(admin, accountType, disabled);
5299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005300 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005301 }
5302 }
5303 }
5304
5305 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005306 * Gets the array of accounts for which account management is disabled by the profile owner.
5307 *
5308 * <p> Account management can be disabled/enabled by calling
5309 * {@link #setAccountManagementDisabled}.
5310 *
5311 * @return a list of account types for which account management has been disabled.
5312 *
5313 * @see #setAccountManagementDisabled
5314 */
5315 public String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005316 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005317 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005318 }
5319
5320 /**
5321 * @see #getAccountTypesWithManagementDisabled()
5322 * @hide
5323 */
5324 public String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005325 if (mService != null) {
5326 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005327 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005328 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005329 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005330 }
5331 }
5332
5333 return null;
5334 }
justinzhang511e0d82014-03-24 16:09:24 -04005335
5336 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005337 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005338 * <p>
5339 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5340 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5341 * package list results in locked tasks belonging to those packages to be finished. This
5342 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005343 *
Jason Monkd7b86212014-06-16 13:15:38 -04005344 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005345 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005346 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005347 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005348 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5349 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005350 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005351 */
Robin Lee25e26452015-06-02 09:56:29 -07005352 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005353 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005354 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005355 if (mService != null) {
5356 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005357 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005358 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005359 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005360 }
5361 }
5362 }
5363
5364 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005365 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005366 *
5367 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005368 * @hide
5369 */
Robin Lee25e26452015-06-02 09:56:29 -07005370 public String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005371 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005372 if (mService != null) {
5373 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005374 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005375 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005376 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005377 }
5378 }
5379 return null;
5380 }
5381
5382 /**
5383 * This function lets the caller know whether the given component is allowed to start the
5384 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005385 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005386 */
Jason Monkd7b86212014-06-16 13:15:38 -04005387 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005388 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005389 if (mService != null) {
5390 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005391 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005392 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005393 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005394 }
5395 }
5396 return false;
5397 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005398
5399 /**
5400 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5401 * 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 -07005402 * <p>
5403 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005404 * <ul>
5405 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5406 * <li>{@link Settings.Global#AUTO_TIME}</li>
5407 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005408 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005409 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005410 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005411 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5412 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5413 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5414 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5415 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005416 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005417 * <p>
5418 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005419 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005420 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5421 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5422 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005423 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005424 * <li>{@link Settings.Global#MODE_RINGER}. Use
5425 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005426 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005427 * <li>{@link Settings.Global#WIFI_ON}. Use
5428 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005429 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005430 *
5431 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5432 * @param setting The name of the setting to update.
5433 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005434 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005435 */
Robin Lee25e26452015-06-02 09:56:29 -07005436 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005437 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005438 if (mService != null) {
5439 try {
5440 mService.setGlobalSetting(admin, setting, value);
5441 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005442 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005443 }
5444 }
5445 }
5446
5447 /**
5448 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5449 * that the value of the setting is in the correct form for the setting type should be performed
5450 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005451 * <p>
5452 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005453 * <ul>
5454 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005455 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005456 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5457 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005458 * <p>
5459 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005460 * <ul>
5461 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5462 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005463 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005464 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5465 * @param setting The name of the setting to update.
5466 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005467 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005468 */
Robin Lee25e26452015-06-02 09:56:29 -07005469 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005470 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005471 if (mService != null) {
5472 try {
5473 mService.setSecureSetting(admin, setting, value);
5474 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005475 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005476 }
5477 }
5478 }
5479
Amith Yamasanif20d6402014-05-24 15:34:37 -07005480 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005481 * Designates a specific service component as the provider for making permission requests of a
5482 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005483 * <p/>
5484 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005485 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005487 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005488 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5489 * provider previously assigned.
5490 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005491 */
Robin Lee25e26452015-06-02 09:56:29 -07005492 public void setRestrictionsProvider(@NonNull ComponentName admin,
5493 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005494 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005495 if (mService != null) {
5496 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005497 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005499 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005500 }
5501 }
5502 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005503
5504 /**
5505 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005506 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005507 *
5508 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5509 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005510 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005511 */
Robin Lee25e26452015-06-02 09:56:29 -07005512 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005513 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005514 if (mService != null) {
5515 try {
5516 mService.setMasterVolumeMuted(admin, on);
5517 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005518 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005519 }
5520 }
5521 }
5522
5523 /**
5524 * Called by profile or device owners to check whether the master volume mute is on or off.
5525 *
5526 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5527 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005528 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005529 */
Robin Lee25e26452015-06-02 09:56:29 -07005530 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005531 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005532 if (mService != null) {
5533 try {
5534 return mService.isMasterVolumeMuted(admin);
5535 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005536 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005537 }
5538 }
5539 return false;
5540 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005541
5542 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005543 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005544 *
5545 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5546 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005547 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005548 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005549 */
Robin Lee25e26452015-06-02 09:56:29 -07005550 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005551 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005552 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005553 if (mService != null) {
5554 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005555 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005556 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005557 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005558 }
5559 }
5560 }
5561
5562 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005563 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005564 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005565 * <p>
5566 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005567 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5568 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5569 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005570 *
Robin Lee25e26452015-06-02 09:56:29 -07005571 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005572 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005573 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005574 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005575 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005576 */
Robin Lee25e26452015-06-02 09:56:29 -07005577 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005578 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005579 if (mService != null) {
5580 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005581 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005582 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005583 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005584 }
5585 }
5586 return false;
5587 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005588
5589 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005590 * Called by the profile owner of a managed profile to enable widget providers from a given
5591 * package to be available in the parent profile. As a result the user will be able to add
5592 * widgets from the white-listed package running under the profile to a widget host which runs
5593 * under the parent profile, for example the home screen. Note that a package may have zero or
5594 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005595 * <p>
5596 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005597 *
5598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5599 * @param packageName The package from which widget providers are white-listed.
5600 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005601 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005602 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5603 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5604 */
Robin Lee25e26452015-06-02 09:56:29 -07005605 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005606 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005607 if (mService != null) {
5608 try {
5609 return mService.addCrossProfileWidgetProvider(admin, packageName);
5610 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005611 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005612 }
5613 }
5614 return false;
5615 }
5616
5617 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005618 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005619 * package to be available in the parent profile. For this method to take effect the package
5620 * should have been added via
5621 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005622 * <p>
5623 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005624 *
5625 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005626 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005627 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005628 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005629 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5630 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5631 */
Esteban Talavera62399912016-01-11 15:37:55 +00005632 public boolean removeCrossProfileWidgetProvider(
5633 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005634 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005635 if (mService != null) {
5636 try {
5637 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5638 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005639 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005640 }
5641 }
5642 return false;
5643 }
5644
5645 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005646 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005647 * available in the parent profile.
5648 *
5649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5650 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005651 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5652 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005653 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005654 */
Robin Lee25e26452015-06-02 09:56:29 -07005655 public List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005656 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005657 if (mService != null) {
5658 try {
5659 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5660 if (providers != null) {
5661 return providers;
5662 }
5663 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005664 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005665 }
5666 }
5667 return Collections.emptyList();
5668 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005669
5670 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005671 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005672 *
5673 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5674 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005675 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005676 */
Robin Lee25e26452015-06-02 09:56:29 -07005677 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005678 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005679 try {
5680 mService.setUserIcon(admin, icon);
5681 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005682 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005683 }
5684 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005685
5686 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005687 * Called by device owners to set a local system update policy. When a new policy is set,
5688 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005689 *
Robin Lee25e26452015-06-02 09:56:29 -07005690 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005691 * components in the device owner package can set system update policies and the most
5692 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005693 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005694 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005695 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005696 */
Robin Lee25e26452015-06-02 09:56:29 -07005697 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005698 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005699 if (mService != null) {
5700 try {
Robin Lee25e26452015-06-02 09:56:29 -07005701 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005702 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005703 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005704 }
5705 }
5706 }
5707
5708 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005709 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005710 *
Robin Lee25e26452015-06-02 09:56:29 -07005711 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005712 */
Rubin Xu5faad8e2015-04-20 17:43:48 +01005713 public SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005714 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005715 if (mService != null) {
5716 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005717 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005718 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005719 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005720 }
5721 }
5722 return null;
5723 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005724
5725 /**
5726 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005727 * <p>
5728 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5729 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5730 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5731 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005732 *
5733 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005734 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005735 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005736 * place. {@code true} otherwise.
5737 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005738 */
Robin Lee25e26452015-06-02 09:56:29 -07005739 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005740 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005741 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005742 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005743 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005744 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005745 }
5746 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005747
5748 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005749 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005750 * notifications, quick settings and other screen overlays that allow escaping from a single use
5751 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005752 *
5753 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005754 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005755 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5756 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005757 */
Robin Lee25e26452015-06-02 09:56:29 -07005758 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005759 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005760 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005761 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005762 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005763 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00005764 }
5765 }
Rubin Xudc105cc2015-04-14 23:38:01 +01005766
5767 /**
5768 * Callable by the system update service to notify device owners about pending updates.
5769 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
5770 * permission.
5771 *
5772 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
5773 * when the current pending update was first available. -1 if no update is available.
5774 * @hide
5775 */
5776 @SystemApi
5777 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005778 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01005779 if (mService != null) {
5780 try {
5781 mService.notifyPendingSystemUpdate(updateReceivedTime);
5782 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005783 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01005784 }
5785 }
5786 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04005787
5788 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07005789 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005790 * requests by applications. The policy can allow for normal operation which prompts the user to
5791 * grant a permission, or can allow automatic granting or denying of runtime permission requests
5792 * by an application. This also applies to new permissions declared by app updates. When a
5793 * permission is denied or granted this way, the effect is equivalent to setting the permission
5794 * grant state via {@link #setPermissionGrantState}.
5795 * <p/>
5796 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005797 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005798 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005799 * @param admin Which profile or device owner this request is associated with.
5800 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005801 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
5802 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01005803 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07005804 */
Robin Lee25e26452015-06-02 09:56:29 -07005805 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005806 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005807 try {
5808 mService.setPermissionPolicy(admin, policy);
5809 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005810 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005811 }
5812 }
5813
5814 /**
5815 * Returns the current runtime permission policy set by the device or profile owner. The
5816 * default is {@link #PERMISSION_POLICY_PROMPT}.
5817 * @param admin Which profile or device owner this request is associated with.
5818 * @return the current policy for future permission requests.
5819 */
Esteban Talavera28b95702015-06-24 15:23:42 +01005820 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005821 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005822 try {
5823 return mService.getPermissionPolicy(admin);
5824 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005825 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005826 }
5827 }
5828
5829 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005830 * Sets the grant state of a runtime permission for a specific application. The state can be
5831 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
5832 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
5833 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
5834 * the permission is granted and the user cannot manage it through the UI. This might affect all
5835 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005836 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005837 * <p/>
5838 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
5839 * the permission. It retains the previous grant, if any.
5840 * <p/>
5841 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005842 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07005843 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07005844 * @param admin Which profile or device owner this request is associated with.
5845 * @param packageName The application to grant or revoke a permission to.
5846 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005847 * @param grantState The permission grant state which is one of
5848 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
5849 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005850 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005851 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005852 * @see #PERMISSION_GRANT_STATE_DENIED
5853 * @see #PERMISSION_GRANT_STATE_DEFAULT
5854 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07005855 */
Robin Lee25e26452015-06-02 09:56:29 -07005856 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005857 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005858 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07005859 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07005860 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07005861 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005862 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07005863 }
5864 }
Amith Yamasani184b3752015-05-22 13:00:51 -07005865
5866 /**
5867 * Returns the current grant state of a runtime permission for a specific application.
5868 *
5869 * @param admin Which profile or device owner this request is associated with.
5870 * @param packageName The application to check the grant state for.
5871 * @param permission The permission to check for.
5872 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005873 * has not set a grant state, the return value is
5874 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
5875 * permission is currently granted for the package.
5876 * <p/>
5877 * If a grant state was set by the profile or device owner, then the return value will
5878 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
5879 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
5880 * currently denied or granted.
5881 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07005882 * @see #setPermissionGrantState(ComponentName, String, String, int)
5883 * @see PackageManager#checkPermission(String, String)
5884 */
Robin Lee25e26452015-06-02 09:56:29 -07005885 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07005886 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005887 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07005888 try {
5889 return mService.getPermissionGrantState(admin, packageName, permission);
5890 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005891 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07005892 }
5893 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005894
5895 /**
5896 * Returns if provisioning a managed profile or device is possible or not.
5897 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
5898 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005899 * @return if provisioning a managed profile or device is possible or not.
5900 * @throws IllegalArgumentException if the supplied action is not valid.
5901 */
5902 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005903 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005904 try {
5905 return mService.isProvisioningAllowed(action);
5906 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005907 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00005908 }
5909 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005910
5911 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005912 * Return if this user is a managed profile of another user. An admin can become the profile
5913 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01005914 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005915 * @param admin Which profile owner this request is associated with.
5916 * @return if this user is a managed profile of another user.
5917 */
5918 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005919 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005920 try {
5921 return mService.isManagedProfile(admin);
5922 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005923 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005924 }
5925 }
5926
5927 /**
5928 * @hide
5929 * Return if this user is a system-only user. An admin can manage a device from a system only
5930 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
5931 * @param admin Which device owner this request is associated with.
5932 * @return if this user is a system-only user.
5933 */
5934 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
5935 try {
5936 return mService.isSystemOnlyUser(admin);
5937 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005938 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00005939 }
5940 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005941
5942 /**
5943 * Called by device owner to get the MAC address of the Wi-Fi device.
5944 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005945 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005946 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
5947 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
5948 * <p>
5949 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
5950 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005951 */
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005952 public String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005953 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005954 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08005955 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005956 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005957 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08005958 }
5959 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005960
5961 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005962 * Called by device owner to reboot the device. If there is an ongoing call on the device,
5963 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005964 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005965 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005966 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00005967 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005968 */
5969 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005970 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005971 try {
5972 mService.reboot(admin);
5973 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005974 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00005975 }
5976 }
Kenny Guy06de4e72015-12-22 12:07:39 +00005977
5978 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005979 * Called by a device admin to set the short support message. This will be displayed to the user
5980 * in settings screens where funtionality has been disabled by the admin. The message should be
5981 * limited to a short statement such as "This setting is disabled by your administrator. Contact
5982 * someone@example.com for support." If the message is longer than 200 characters it may be
5983 * truncated.
5984 * <p>
5985 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00005986 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
5987 * and set a new version of this string accordingly.
5988 *
Kenny Guy06de4e72015-12-22 12:07:39 +00005989 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00005990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005991 * @param message Short message to be displayed to the user in settings or null to clear the
5992 * existing message.
5993 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00005994 */
5995 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07005996 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005997 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00005998 if (mService != null) {
5999 try {
6000 mService.setShortSupportMessage(admin, message);
6001 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006002 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006003 }
6004 }
6005 }
6006
6007 /**
6008 * Called by a device admin to get the short support message.
6009 *
6010 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006011 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6012 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006013 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006014 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006015 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006016 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006017 if (mService != null) {
6018 try {
6019 return mService.getShortSupportMessage(admin);
6020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006021 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006022 }
6023 }
6024 return null;
6025 }
6026
6027 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006028 * Called by a device admin to set the long support message. This will be displayed to the user
6029 * in the device administators settings screen.
6030 * <p>
6031 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006032 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6033 * and set a new version of this string accordingly.
6034 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006035 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006036 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006037 * @param message Long message to be displayed to the user in settings or null to clear the
6038 * existing message.
6039 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006040 */
6041 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006042 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006043 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006044 if (mService != null) {
6045 try {
6046 mService.setLongSupportMessage(admin, message);
6047 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006048 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006049 }
6050 }
6051 }
6052
6053 /**
6054 * Called by a device admin to get the long support message.
6055 *
6056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006057 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6058 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006059 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006060 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006061 public CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006062 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006063 if (mService != null) {
6064 try {
6065 return mService.getLongSupportMessage(admin);
6066 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006067 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006068 }
6069 }
6070 return null;
6071 }
6072
6073 /**
6074 * Called by the system to get the short support message.
6075 *
6076 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6077 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006078 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006079 *
6080 * @hide
6081 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006082 public CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
6083 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006084 if (mService != null) {
6085 try {
6086 return mService.getShortSupportMessageForUser(admin, userHandle);
6087 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006088 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006089 }
6090 }
6091 return null;
6092 }
6093
6094
6095 /**
6096 * Called by the system to get the long support message.
6097 *
6098 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6099 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006100 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006101 *
6102 * @hide
6103 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006104 public CharSequence getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006105 if (mService != null) {
6106 try {
6107 return mService.getLongSupportMessageForUser(admin, userHandle);
6108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006109 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006110 }
6111 }
6112 return null;
6113 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006114
6115 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006116 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6117 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006118 *
6119 * <p>The following methods are supported for the parent instance, all other methods will
6120 * throw a SecurityException when called on the parent instance:
6121 * <ul>
6122 * <li>{@link #getPasswordQuality}</li>
6123 * <li>{@link #setPasswordQuality}</li>
6124 * <li>{@link #getPasswordMinimumLength}</li>
6125 * <li>{@link #setPasswordMinimumLength}</li>
6126 * <li>{@link #getPasswordMinimumUpperCase}</li>
6127 * <li>{@link #setPasswordMinimumUpperCase}</li>
6128 * <li>{@link #getPasswordMinimumLowerCase}</li>
6129 * <li>{@link #setPasswordMinimumLowerCase}</li>
6130 * <li>{@link #getPasswordMinimumLetters}</li>
6131 * <li>{@link #setPasswordMinimumLetters}</li>
6132 * <li>{@link #getPasswordMinimumNumeric}</li>
6133 * <li>{@link #setPasswordMinimumNumeric}</li>
6134 * <li>{@link #getPasswordMinimumSymbols}</li>
6135 * <li>{@link #setPasswordMinimumSymbols}</li>
6136 * <li>{@link #getPasswordMinimumNonLetter}</li>
6137 * <li>{@link #setPasswordMinimumNonLetter}</li>
6138 * <li>{@link #getPasswordHistoryLength}</li>
6139 * <li>{@link #setPasswordHistoryLength}</li>
6140 * <li>{@link #getPasswordExpirationTimeout}</li>
6141 * <li>{@link #setPasswordExpirationTimeout}</li>
6142 * <li>{@link #getPasswordExpiration}</li>
6143 * <li>{@link #isActivePasswordSufficient}</li>
6144 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6145 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6146 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6147 * <li>{@link #getMaximumTimeToLock}</li>
6148 * <li>{@link #setMaximumTimeToLock}</li>
6149 * <li>{@link #lockNow}</li>
6150 * <li>{@link #getKeyguardDisabledFeatures}</li>
6151 * <li>{@link #setKeyguardDisabledFeatures}</li>
6152 * <li>{@link #getTrustAgentConfiguration}</li>
6153 * <li>{@link #setTrustAgentConfiguration}</li>
6154 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006155 *
6156 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006157 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006158 */
6159 public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006160 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006161 try {
6162 if (!mService.isManagedProfile(admin)) {
6163 throw new SecurityException("The current user does not have a parent profile.");
6164 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006165 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006166 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006167 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006168 }
6169 }
6170
6171 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006172 * Called by device owner to control the security logging feature. Logging can only be
6173 * enabled on single user devices where the sole user is managed by the device owner.
6174 *
6175 * <p> Security logs contain various information intended for security auditing purposes.
6176 * See {@link SecurityEvent} for details.
6177 *
6178 * <p>There must be only one user on the device, managed by the device owner.
6179 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006180 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006181 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006182 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006183 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006184 * @see #retrieveSecurityLogs
6185 */
6186 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006187 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006188 try {
6189 mService.setSecurityLoggingEnabled(admin, enabled);
6190 } catch (RemoteException re) {
6191 throw re.rethrowFromSystemServer();
6192 }
6193 }
6194
6195 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006196 * Return whether security logging is enabled or not by the device owner.
6197 *
6198 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6199 * thrown.
6200 *
6201 * @param admin Which device owner this request is associated with.
6202 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6203 * @throws SecurityException if {@code admin} is not a device owner.
6204 */
6205 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006206 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006207 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006208 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006209 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006210 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006211 }
6212 }
6213
6214 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006215 * Called by device owner to retrieve all new security logging entries since the last call to
6216 * this API after device boots.
6217 *
6218 * <p> Access to the logs is rate limited and it will only return new logs after the device
6219 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6220 *
6221 * <p>There must be only one user on the device, managed by the device owner.
6222 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006223 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006224 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006225 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6226 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006227 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006228 */
Michal Karpinski6235a942016-03-15 12:07:23 +00006229 public List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006230 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006231 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006232 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006233 if (list != null) {
6234 return list.getList();
6235 } else {
6236 // Rate limit exceeded.
6237 return null;
6238 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006239 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006240 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006241 }
6242 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006243
6244 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006245 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6246 * profile.
6247 *
6248 * @hide
6249 */
6250 public DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
6251 mContext.checkSelfPermission(
6252 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6253 if (!uInfo.isManagedProfile()) {
6254 throw new SecurityException("The user " + uInfo.id
6255 + " does not have a parent profile.");
6256 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006257 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006258 }
6259
6260 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006261 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006262 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006263 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6264 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6265 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6266 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006267 * <p>
6268 * There must be only one user on the device, managed by the device owner. Otherwise a
6269 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006270 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006271 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006272 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6273 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006274 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006275 */
Michal Karpinski6235a942016-03-15 12:07:23 +00006276 public List<SecurityEvent> retrievePreRebootSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006277 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006278 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006279 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006280 if (list != null) {
6281 return list.getList();
6282 } else {
6283 return null;
6284 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006285 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006286 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006287 }
6288 }
6289
6290 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006291 * Called by a profile owner of a managed profile to set the color used for customization. This
6292 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006293 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006294 * <p>
6295 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006296 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6297 *
6298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006299 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006300 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006301 */
6302 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006303 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006304 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006305 // always enforce alpha channel to have 100% opacity
6306 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006307 mService.setOrganizationColor(admin, color);
6308 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006309 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006310 }
6311 }
6312
6313 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006314 * @hide
6315 *
6316 * Sets the color used for customization.
6317 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006318 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006319 * @param userId which user to set the color to.
6320 * @RequiresPermission(allOf = {
6321 * Manifest.permission.MANAGE_USERS,
6322 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6323 */
6324 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6325 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006326 // always enforce alpha channel to have 100% opacity
6327 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006328 mService.setOrganizationColorForUser(color, userId);
6329 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006330 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006331 }
6332 }
6333
6334 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006335 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6336 * This color is used as background color of the confirm credentials screen for that user.
6337 *
6338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006339 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006340 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006341 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006342 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006343 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006344 try {
6345 return mService.getOrganizationColor(admin);
6346 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006347 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006348 }
6349 }
6350
6351 /**
6352 * @hide
6353 * Retrieve the customization color for a given user.
6354 *
6355 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006356 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006357 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006358 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006359 try {
6360 return mService.getOrganizationColorForUser(userHandle);
6361 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006362 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006363 }
6364 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006365
6366 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006367 * Called by a profile owner of a managed profile to set the name of the organization under
6368 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006369 * <p>
6370 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006371 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6372 * and set a new version of this string accordingly.
6373 *
6374 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6375 * @param title The organization name or {@code null} to clear a previously set name.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006376 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006377 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006378 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006379 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006380 try {
6381 mService.setOrganizationName(admin, title);
6382 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006383 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006384 }
6385 }
6386
6387 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006388 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6389 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006390 *
6391 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6392 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006393 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006394 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006395 public CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006396 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006397 try {
6398 return mService.getOrganizationName(admin);
6399 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006400 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006401 }
6402 }
6403
6404 /**
6405 * Retrieve the default title message used in the confirm credentials screen for a given user.
6406 *
6407 * @param userHandle The user id of the user we're interested in.
6408 * @return The organization name or {@code null} if none is set.
6409 *
6410 * @hide
6411 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006412 public CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006413 try {
6414 return mService.getOrganizationNameForUser(userHandle);
6415 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006416 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006417 }
6418 }
6419
6420 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006421 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6422 * return {@link #STATE_USER_UNMANAGED}
6423 * @hide
6424 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006425 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006426 @UserProvisioningState
6427 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006428 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006429 if (mService != null) {
6430 try {
6431 return mService.getUserProvisioningState();
6432 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006433 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006434 }
6435 }
6436 return STATE_USER_UNMANAGED;
6437 }
6438
6439 /**
6440 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6441 *
6442 * @param state to store
6443 * @param userHandle for user
6444 * @hide
6445 */
6446 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6447 if (mService != null) {
6448 try {
6449 mService.setUserProvisioningState(state, userHandle);
6450 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006451 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006452 }
6453 }
6454 }
6455
6456 /**
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006457 * @hide
6458 * Indicates the entity that controls the device or profile owner. A user/profile is considered
6459 * affiliated if it is managed by the same entity as the device.
6460 *
6461 * <p> By definition, the user that the device owner runs on is always affiliated. Any other
6462 * user/profile is considered affiliated if the following conditions are both met:
6463 * <ul>
6464 * <li>The device owner and the user's/profile's profile owner have called this method,
6465 * specifying a set of opaque affiliation ids each. If the sets specified by the device owner
6466 * and a profile owner intersect, they must have come from the same source, which means that
6467 * the device owner and profile owner are controlled by the same entity.</li>
6468 * <li>The device owner's and profile owner's package names are the same.</li>
6469 * </ul>
6470 *
6471 * @param admin Which profile or device owner this request is associated with.
6472 * @param ids A set of opaque affiliation ids.
6473 */
6474 public void setAffiliationIds(@NonNull ComponentName admin, Set<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006475 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006476 try {
6477 mService.setAffiliationIds(admin, new ArrayList<String>(ids));
6478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006479 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006480 }
6481 }
6482
6483 /**
6484 * @hide
6485 * Returns whether this user/profile is affiliated with the device. See
6486 * {@link #setAffiliationIds} for the definition of affiliation.
6487 *
6488 * @return whether this user/profile is affiliated with the device.
6489 */
6490 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006491 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006492 try {
6493 return mService != null && mService.isAffiliatedUser();
6494 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006495 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006496 }
6497 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006498
6499 /**
6500 * @hide
6501 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6502 * to be started
6503 * @param packageName the package to check for
6504 * @return whether the uninstall intent for {@code packageName} is pending
6505 */
6506 public boolean isUninstallInQueue(String packageName) {
6507 try {
6508 return mService.isUninstallInQueue(packageName);
6509 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006510 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006511 }
6512 }
6513
6514 /**
6515 * @hide
6516 * @param packageName the package containing active DAs to be uninstalled
6517 */
6518 public void uninstallPackageWithActiveAdmins(String packageName) {
6519 try {
6520 mService.uninstallPackageWithActiveAdmins(packageName);
6521 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006522 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006523 }
6524 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006525
Kenny Guy38dcca52016-04-19 13:09:18 +01006526 /**
6527 * @hide
6528 * Remove a test admin synchronously without sending it a broadcast about being removed.
6529 * If the admin is a profile owner or device owner it will still be removed.
6530 *
6531 * @param userHandle user id to remove the admin for.
6532 * @param admin The administration compononent to remove.
6533 * @throws SecurityException if the caller is not shell / root or the admin package
6534 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6535 */
6536 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6537 try {
6538 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6539 } catch (RemoteException re) {
6540 throw re.rethrowFromSystemServer();
6541 }
6542 }
6543
Mahaver Chopra790d1982016-07-07 16:06:49 +01006544 /**
6545 * @hide
6546 * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set
6547 * to 1.
6548 */
6549 public boolean isDeviceProvisioned() {
6550 try {
6551 return mService.isDeviceProvisioned();
6552 } catch (RemoteException re) {
6553 throw re.rethrowFromSystemServer();
6554 }
6555 }
6556
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006557 /**
6558 * @hide
6559 * Writes that the provisioning configuration has been applied.
6560 */
6561 public void setDeviceProvisioningConfigApplied() {
6562 try {
6563 mService.setDeviceProvisioningConfigApplied();
6564 } catch (RemoteException re) {
6565 throw re.rethrowFromSystemServer();
6566 }
6567 }
6568
6569 /**
6570 * @hide
6571 * @return whether the provisioning configuration has been applied.
6572 */
6573 public boolean isDeviceProvisioningConfigApplied() {
6574 try {
6575 return mService.isDeviceProvisioningConfigApplied();
6576 } catch (RemoteException re) {
6577 throw re.rethrowFromSystemServer();
6578 }
6579 }
6580
Victor Chang9bfc65f2016-08-15 12:27:09 +01006581 /**
6582 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006583 * Force update user setup completed status. This API has no effect on user build.
6584 * @throws {@link SecurityException} if the caller has no
6585 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6586 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006587 */
6588 public void forceUpdateUserSetupComplete() {
6589 try {
6590 mService.forceUpdateUserSetupComplete();
6591 } catch (RemoteException re) {
6592 throw re.rethrowFromSystemServer();
6593 }
6594 }
6595
Benjamin Franzbc33c822016-04-15 08:57:52 +01006596 private void throwIfParentInstance(String functionName) {
6597 if (mParentInstance) {
6598 throw new SecurityException(functionName + " cannot be called on the parent instance");
6599 }
6600 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006601
6602 /**
6603 * @hide
6604 * Enable backup service.
6605 * <p>This includes all backup and restore mechanisms.
6606 * Setting this to {@code false} will make backup service no-op or return empty results.
6607 *
6608 * <p>There must be only one user on the device, managed by the device owner.
6609 * Otherwise a {@link SecurityException} will be thrown.
6610 *
6611 * <p>Backup service is off by default when device owner is present.
6612 */
6613 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6614 try {
6615 mService.setBackupServiceEnabled(admin, enabled);
6616 } catch (RemoteException re) {
6617 throw re.rethrowFromSystemServer();
6618 }
6619 }
6620
6621 /**
6622 * @hide
6623 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6624 */
6625 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6626 try {
6627 return mService.isBackupServiceEnabled(admin);
6628 } catch (RemoteException re) {
6629 throw re.rethrowFromSystemServer();
6630 }
6631 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08006632}