blob: 0da89eb2bd985e7d49406663daf6eb1c5c9ea2dd [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;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010026import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000027import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070028import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040029import android.app.Activity;
Tony Mak46aabe52016-11-14 12:53:06 +000030import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000031import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080032import android.content.ComponentName;
33import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010034import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000035import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000036import android.content.ServiceConnection;
Dianne Hackbornd6847842010-01-12 18:14:19 -080037import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000038import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000039import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000040import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050041import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040042import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000043import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010044import android.os.Bundle;
Victor Changc10f6692016-12-09 15:24:00 +000045import android.os.Parcelable;
Jim Millere303bf42014-08-26 17:12:29 -070046import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000047import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080048import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080049import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070050import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040051import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000052import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000053import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010054import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070055import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000056import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080057import android.util.Log;
58
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070059import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040060import com.android.org.conscrypt.TrustedCertificateStore;
61
62import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080063import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070066import java.net.InetSocketAddress;
67import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010068import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000069import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010070import java.security.PrivateKey;
71import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040072import java.security.cert.CertificateException;
73import java.security.cert.CertificateFactory;
74import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010075import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000076import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070077import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000078import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070079import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080080import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080081
82/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000083 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070084 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
85 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
86 * device owner. A given method is accessible to all device administrators unless the documentation
87 * for that method specifies that it is restricted to either device or profile owners. Any
88 * application calling an api may only pass as an argument a device administrator component it
89 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080090 * <div class="special reference">
91 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070092 * <p>
93 * For more information about managing policies for device administration, read the <a href=
94 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
95 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080096 */
97public class DevicePolicyManager {
98 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -080099
100 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800101 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000102 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700103
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600104 /** @hide */
105 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
106 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800107 }
108
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800109 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700110 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600111 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
112 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700113 mContext = context;
114 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000115 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700116 }
117
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700118 /** @hide test will override it. */
119 @VisibleForTesting
120 protected int myUserId() {
121 return UserHandle.myUserId();
122 }
123
Dianne Hackbornd6847842010-01-12 18:14:19 -0800124 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000125 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100127 * <p>A managed profile allows data separation for example for the usage of a
128 * device as a personal and corporate device. The user which provisioning is started from and
129 * the managed profile share a launcher.
130 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800131 * <p>This intent will typically be sent by a mobile device management application (MDM).
132 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
133 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100134 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000135 * <p>It is possible to check if provisioning is allowed or not by querying the method
136 * {@link #isProvisioningAllowed(String)}.
137 *
138 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000139 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700140 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000141 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
142 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000143 *
Benjamin Franzea956242016-03-21 15:45:56 +0000144 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000145 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000146 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
147 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
148 * {@link android.os.Build.VERSION_CODES#N}</li>
149 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
150 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000152 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000153 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000154 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000155 * </ul>
Jessica Hummelf72078b2014-03-06 16:13:12 +0000156 *
Benjamin Franzea956242016-03-21 15:45:56 +0000157 * <p>When managed provisioning has completed, broadcasts are sent to the application specified
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000158 * in the provisioning intent. The
159 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast is sent in the
160 * managed profile and the {@link #ACTION_MANAGED_PROFILE_PROVISIONED} broadcast is sent in
161 * the primary profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100162 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000163 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when managed provisioning has
164 * completed, along with the above broadcast, activity intent
165 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the application specified in
166 * the provisioning intent.
167 *
Benjamin Franzea956242016-03-21 15:45:56 +0000168 * <p>If provisioning fails, the managedProfile is removed so the device returns to its
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100169 * previous state.
Alan Treadway4582f812015-07-28 11:49:35 +0100170 *
171 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
172 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
173 * the provisioning flow was successful, although this doesn't guarantee the full flow will
174 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
175 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000176 */
177 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
178 public static final String ACTION_PROVISION_MANAGED_PROFILE
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100179 = "android.app.action.PROVISION_MANAGED_PROFILE";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000180
181 /**
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000182 * Activity action: Starts the provisioning flow which sets up a managed user.
183 *
184 * <p>This intent will typically be sent by a mobile device management application (MDM).
Makoto Onuki32b30572015-12-11 14:29:51 -0800185 * Provisioning configures the user as managed user and sets the MDM as the profile
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000186 * owner who has full control over the user. Provisioning can only happen before user setup has
187 * been completed. Use {@link #isProvisioningAllowed(String)} to check if provisioning is
188 * allowed.
189 *
Benjamin Franzea956242016-03-21 15:45:56 +0000190 * <p>The intent contains the following extras:
191 * <ul>
192 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
193 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
194 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
195 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
196 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
197 * </ul>
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000198 *
Benjamin Franzea956242016-03-21 15:45:56 +0000199 * <p>If provisioning fails, the device returns to its previous state.
Mahaver Chopra7830daa2015-11-10 18:12:43 +0000200 *
201 * <p>If launched with {@link android.app.Activity#startActivityForResult(Intent, int)} a
202 * result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part of
203 * the provisioning flow was successful, although this doesn't guarantee the full flow will
204 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
205 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Benjamin Franzea956242016-03-21 15:45:56 +0000206 *
207 * @hide
Mahaver Chopra5e732562015-11-05 11:55:12 +0000208 */
209 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
210 public static final String ACTION_PROVISION_MANAGED_USER
211 = "android.app.action.PROVISION_MANAGED_USER";
212
213 /**
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100214 * Activity action: Starts the provisioning flow which sets up a managed device.
215 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
216 *
217 * <p> During device owner provisioning a device admin app is set as the owner of the device.
218 * A device owner has full control over the device. The device owner can not be modified by the
219 * user.
220 *
221 * <p> A typical use case would be a device that is owned by a company, but used by either an
222 * employee or client.
223 *
224 * <p> An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000225 * It is possible to check if provisioning is allowed or not by querying the method
226 * {@link #isProvisioningAllowed(String)}.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100227 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000228 * <p>The intent contains the following extras:
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100229 * <ul>
230 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
231 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
232 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
Rubin Xua4f9dc12015-06-12 13:27:59 +0100233 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000234 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000235 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Changc10f6692016-12-09 15:24:00 +0000236 * <li>{@link #EXTRA_PROVISIONING_DISCLAIMERS}, optional</li>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100237 * </ul>
238 *
Benjamin Franzea956242016-03-21 15:45:56 +0000239 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100240 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
241 * device owner.
242 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000243 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
244 * completed, along with the above broadcast, activity intent
245 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
246 *
Benjamin Franzea956242016-03-21 15:45:56 +0000247 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100248 *
Alan Treadway4582f812015-07-28 11:49:35 +0100249 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
250 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
251 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
252 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100253 */
254 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
255 public static final String ACTION_PROVISION_MANAGED_DEVICE
256 = "android.app.action.PROVISION_MANAGED_DEVICE";
257
258 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000259 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000260 *
261 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
262 * the device. A device owner has full control over the device. The device owner can not be
263 * modified by the user and the only way of resetting the device is via factory reset.
264 *
265 * <p>A typical use case would be a device that is owned by a company, but used by either an
266 * employee or client.
267 *
268 * <p>The provisioning message should be sent to an unprovisioned device.
269 *
270 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
271 * by a privileged app with the permission
272 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
273 *
274 * <p>The provisioning intent contains the following properties:
275 * <ul>
276 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
277 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000280 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000282 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
291 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
292 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
Victor Chang38cfd9c2017-01-04 17:41:11 +0000293 * <li>{@link #EXTRA_PROVISIONING_SUPPORT_URL}, optional</li>
294 * <li>{@link #EXTRA_PROVISIONING_ORGANIZATION_NAME}, optional</li>
Steven Ng980a1b62016-02-02 17:43:18 +0000295 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
296 *
297 * @hide
298 */
299 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
300 @SystemApi
301 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
302 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
303
304 /**
305 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000306 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
307 *
308 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
309 * management state that is distinct from that reached by
310 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
311 * user, and only has control over device-wide policies, not individual users and their data.
312 * The primary benefit is that multiple non-system users are supported when provisioning using
313 * this form of device management.
314 *
Benjamin Franzea956242016-03-21 15:45:56 +0000315 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000316 * A device owner has full control over the device. The device owner can not be modified by the
317 * user.
318 *
Benjamin Franzea956242016-03-21 15:45:56 +0000319 * <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 +0000320 * employee or client.
321 *
Benjamin Franzea956242016-03-21 15:45:56 +0000322 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000323 * It is possible to check if provisioning is allowed or not by querying the method
324 * {@link #isProvisioningAllowed(String)}.
325 *
326 * <p>The intent contains the following extras:
327 * <ul>
328 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
329 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
330 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
331 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000332 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
333 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000334 * </ul>
335 *
Benjamin Franzea956242016-03-21 15:45:56 +0000336 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000337 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
338 * device owner.
339 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000340 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
341 * completed, along with the above broadcast, activity intent
342 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
343 *
Benjamin Franzea956242016-03-21 15:45:56 +0000344 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000345 *
346 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
347 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
348 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
349 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
350 *
351 * @hide
352 */
353 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
354 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
355 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
356
357 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000358 * Activity action: Finalizes management provisioning, should be used after user-setup
359 * has been completed and {@link #getUserProvisioningState()} returns one of:
360 * <ul>
361 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
362 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
363 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
364 * </ul>
365 *
366 * @hide
367 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000368 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000369 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
370 public static final String ACTION_PROVISION_FINALIZATION
371 = "android.app.action.PROVISION_FINALIZATION";
372
373 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000374 * Action: Bugreport sharing with device owner has been accepted by the user.
375 *
376 * @hide
377 */
378 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
379 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
380
381 /**
382 * Action: Bugreport sharing with device owner has been declined by the user.
383 *
384 * @hide
385 */
386 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
387 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
388
389 /**
Esteban Talavera01576862016-12-15 11:16:44 +0000390 * Action: Bugreport has been collected and is dispatched to {@code DevicePolicyManagerService}.
Michal Karpinskiba244092016-02-25 17:28:24 +0000391 *
392 * @hide
393 */
394 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
395 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
396
397 /**
398 * Extra for shared bugreport's SHA-256 hash.
399 *
400 * @hide
401 */
402 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
403 "android.intent.extra.REMOTE_BUGREPORT_HASH";
404
405 /**
406 * Extra for remote bugreport notification shown type.
407 *
408 * @hide
409 */
410 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
411 "android.app.extra.bugreport_notification_type";
412
413 /**
414 * Notification type for a started remote bugreport flow.
415 *
416 * @hide
417 */
418 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
419
420 /**
421 * Notification type for a bugreport that has already been accepted to be shared, but is still
422 * being taken.
423 *
424 * @hide
425 */
426 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
427
428 /**
429 * Notification type for a bugreport that has been taken and can be shared or declined.
430 *
431 * @hide
432 */
433 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
434
435 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100436 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
437 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
438 *
439 * @hide
440 */
441 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
442
443 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100444 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100445 * allows a mobile device management application or NFC programmer application which starts
446 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100447 * <p>
448 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
449 * sends the intent to pass data to itself on the newly created profile.
450 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
451 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100452 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
453 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
454 * message should contain a stringified {@link java.util.Properties} instance, whose string
455 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
456 * management application after provisioning.
457 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100458 * <p>
459 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700460 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
461 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100462 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100463 */
464 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100465 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100466
467 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100468 * A String extra holding the package name of the mobile device management application that
469 * will be set as the profile owner or device owner.
470 *
471 * <p>If an application starts provisioning directly via an intent with action
472 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
473 * application that started provisioning. The package will be set as profile owner in that case.
474 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000475 * <p>This package is set as device owner when device owner provisioning is started by an NFC
476 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000477 *
478 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700479 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000480 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000481 * @see DeviceAdminReceiver
482 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100483 * supported, but only if there is only one device admin receiver in the package that requires
484 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000485 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000486 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000487 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100488 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000489
490 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000491 * A ComponentName extra indicating the device admin receiver of the mobile device management
492 * application that will be set as the profile owner or device owner and active admin.
493 *
494 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100495 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
496 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
497 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000498 *
499 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100500 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
501 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000502 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000503 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000504 *
505 * @see DeviceAdminReceiver
506 */
507 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
508 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
509
510 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000511 * An {@link android.accounts.Account} extra holding the account to migrate during managed
512 * profile provisioning. If the account supplied is present in the primary user, it will be
513 * copied, along with its credentials to the managed profile and removed from the primary user.
514 *
515 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
516 */
517
518 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
519 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
520
521 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000522 * Boolean extra to indicate that the migrated account should be kept. This is used in
523 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
524 * the account will not be removed from the primary user after it is migrated to the newly
525 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000526 *
527 * <p> Defaults to {@code false}
528 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000529 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
530 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000531 */
532 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
533 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
534
535 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100536 * A String extra that, holds the email address of the account which a managed profile is
537 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
538 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100539 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100540 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
541 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100542 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
543 * contains this extra, it is forwarded in the
544 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
545 * device management application that was set as the profile owner during provisioning.
546 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100547 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100548 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
549 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100550
551 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000552 * A integer extra indicating the predominant color to show during the provisioning.
553 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000554 *
555 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
556 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
557 */
558 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
559 "android.app.extra.PROVISIONING_MAIN_COLOR";
560
561 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000562 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700563 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000564 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100565 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
566 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000567 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000568 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
569 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000570
571 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
573 * will be set to.
574 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000575 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
576 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100577 */
578 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100579 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100580
581 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100582 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
583 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100584 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000585 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
586 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100587 */
588 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100589 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100590
591 /**
592 * A String extra holding the {@link java.util.Locale} that the device will be set to.
593 * Format: xx_yy, where xx is the language code, and yy the country code.
594 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000595 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
596 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100597 */
598 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100599 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100600
601 /**
602 * A String extra holding the ssid of the wifi network that should be used during nfc device
603 * owner provisioning for downloading the mobile device management application.
604 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000605 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
606 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100607 */
608 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100609 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100610
611 /**
612 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
613 * is hidden or not.
614 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000615 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
616 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100617 */
618 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100619 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620
621 /**
622 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100623 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
624 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100625 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000626 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
627 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100628 */
629 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100630 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100631
632 /**
633 * A String extra holding the password of the wifi network in
634 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
635 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000636 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
637 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100638 */
639 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100640 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100641
642 /**
643 * A String extra holding the proxy host for the wifi network in
644 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
645 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000646 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
647 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100648 */
649 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100650 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100651
652 /**
653 * An int extra holding the proxy port for the wifi network in
654 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
655 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000656 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
657 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100658 */
659 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100660 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100661
662 /**
663 * A String extra holding the proxy bypass for the wifi network in
664 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
665 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000666 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
667 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100668 */
669 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100670 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100671
672 /**
673 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
674 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
675 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000676 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
677 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100678 */
679 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100680 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100681
682 /**
683 * A String extra holding a url that specifies the download location of the device admin
684 * package. When not provided it is assumed that the device admin package is already installed.
685 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000686 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
687 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100688 */
689 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100690 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100691
692 /**
Victor Chang38cfd9c2017-01-04 17:41:11 +0000693 * A String extra holding the localized name of the organization under management.
694 *
695 * The name is displayed only during provisioning.
696 *
697 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
698 *
699 * @hide
700 */
701 @SystemApi
702 public static final String EXTRA_PROVISIONING_ORGANIZATION_NAME =
703 "android.app.extra.PROVISIONING_ORGANIZATION_NAME";
704
705 /**
706 * A String extra holding a url to the website of the device's provider. The website can be
707 * opened in a browser during provisioning.
708 *
709 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
710 *
711 * @hide
712 */
713 @SystemApi
714 public static final String EXTRA_PROVISIONING_SUPPORT_URL =
715 "android.app.extra.PROVISIONING_SUPPORT_URL";
716
717 /**
718 * A String extra holding the localized name of the device admin package. It should be the same
719 * as the app label of the package.
720 *
721 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
722 *
723 * @hide
724 */
725 @SystemApi
726 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL =
727 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL";
728
729 /**
730 * A {@link Uri} extra pointing to the app icon of device admin package. This image will be
731 * shown during the provisioning.
732 * <h5>The following URI schemes are accepted:</h5>
733 * <ul>
734 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
735 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
736 * </ul>
737 *
738 * <p> It is the responsibility of the caller to provide an image with a reasonable
739 * pixel density for the device.
740 *
741 * <p> If a content: URI is passed, the intent should have the flag
742 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
743 * {@link android.content.ClipData} of the intent too.
744 *
745 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
746 *
747 * @hide
748 */
749 @SystemApi
750 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI =
751 "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI";
752
753 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400754 * An int extra holding a minimum required version code for the device admin package. If the
755 * device admin is already installed on the device, it will only be re-downloaded from
756 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
757 * installed package is less than this version code.
758 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400759 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400760 * provisioning via an NFC bump.
761 */
762 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
763 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
764
765 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100766 * A String extra holding a http cookie header which should be used in the http request to the
767 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
768 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000769 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
770 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100771 */
772 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100773 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100774
775 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100776 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
777 * the file at download location specified in
778 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100779 *
Benjamin Franzea956242016-03-21 15:45:56 +0000780 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
781 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100782 * location. If the checksum doesn't match an error will be shown to the user and the user will
783 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100784 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000785 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
786 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100787 *
788 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
789 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700790 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100791 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100792 */
793 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100794 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100795
796 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100797 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100798 * android package archive at the download location specified in {@link
799 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
800 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100801 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100802 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
803 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
804 *
Benjamin Franzea956242016-03-21 15:45:56 +0000805 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
806 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100807 * the download location. If the checksum does not match an error will be shown to the user and
808 * the user will be asked to factory reset the device.
809 *
810 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
811 * provisioning via an NFC bump.
812 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100813 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
814 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100815
816 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000817 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
818 * has completed successfully.
819 *
820 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700821 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000822 *
Mahaver7074caf2016-11-29 20:52:18 +0000823 * <p>This intent will contain the following extras
824 * <ul>
825 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
826 * profile.</li>
827 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
828 * be migrated at provisioning time, if any.</li>
829 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000830 */
831 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
832 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
833 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
834
835 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000836 * Activity action: This activity action is sent to indicate that provisioning of a managed
837 * profile or managed device has completed successfully. It'll be sent at the same time as
838 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
839 * delivered faster as it's an activity intent.
840 *
841 * <p>The intent is only sent to the application on the profile that requested provisioning. In
842 * the device owner case the profile is the primary user.
843 *
844 * @see #ACTION_PROVISION_MANAGED_PROFILE
845 * @see #ACTION_PROVISION_MANAGED_DEVICE
846 */
847 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
848 public static final String ACTION_PROVISIONING_SUCCESSFUL =
849 "android.app.action.PROVISIONING_SUCCESSFUL";
850
851 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000852 * A boolean extra indicating whether device encryption can be skipped as part of device owner
853 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500854 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400855 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100856 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000857 *
858 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
859 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500860 */
861 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
862 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
863
864 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000865 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
866 * provisioning. If this extra is not passed, a default image will be shown.
867 * <h5>The following URI schemes are accepted:</h5>
868 * <ul>
869 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
870 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
871 * </ul>
872 *
Victor Changc10f6692016-12-09 15:24:00 +0000873 * <p> It is the responsibility of the caller to provide an image with a reasonable
Victor Chang38cfd9c2017-01-04 17:41:11 +0000874 * pixel density for the device.
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000875 *
876 * <p> If a content: URI is passed, the intent should have the flag
877 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
878 * {@link android.content.ClipData} of the intent too.
879 *
880 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
881 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
882 */
883 public static final String EXTRA_PROVISIONING_LOGO_URI =
884 "android.app.extra.PROVISIONING_LOGO_URI";
885
886 /**
Victor Changc10f6692016-12-09 15:24:00 +0000887 * A {@link Bundle}[] extra consisting of list of disclaimer headers and disclaimer contents.
888 * Each {@link Bundle} must have both {@link #EXTRA_PROVISIONING_DISCLAIMER_HEADER}
889 * as disclaimer header, and {@link #EXTRA_PROVISIONING_DISCLAIMER_CONTENT} as disclaimer
890 * content.
891 *
892 * <p> The extra typically contains one disclaimer from the company of mobile device
893 * management application (MDM), and one disclaimer from the organization.
894 *
895 * <p> Call {@link Bundle#putParcelableArray(String, Parcelable[])} to put the {@link Bundle}[]
896 *
897 * <p> Maximum 3 key-value pairs can be specified. The rest will be ignored.
898 *
899 * <p> Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
900 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
901 */
902 public static final String EXTRA_PROVISIONING_DISCLAIMERS =
903 "android.app.extra.PROVISIONING_DISCLAIMERS";
904
905 /**
906 * A String extra of localized disclaimer header.
907 *
908 * <p> The extra is typically the company name of mobile device management application (MDM)
909 * or the organization name.
910 *
911 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
912 */
913 public static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER =
914 "android.app.extra.PROVISIONING_DISCLAIMER_HEADER";
915
916 /**
917 * A {@link Uri} extra pointing to disclaimer content.
918 *
919 * <h5>The following URI schemes are accepted:</h5>
920 * <ul>
921 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
922 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
923 * </ul>
924 *
925 * <p> Styled text is supported in the disclaimer content. The content is parsed by
926 * {@link android.text.Html#fromHtml(String)} and displayed in a
927 * {@link android.widget.TextView}.
928 *
929 * <p> If a <code>content:</code> URI is passed, URI is passed, the intent should have the flag
930 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
931 * {@link android.content.ClipData} of the intent too.
932 *
933 * <p> Use in Bundle {@link #EXTRA_PROVISIONING_DISCLAIMERS}
934 */
935 public static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT =
936 "android.app.extra.PROVISIONING_DISCLAIMER_CONTENT";
937
938 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000939 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
940 * during setup-wizard.
941 *
942 * <p>If unspecified, defaults to {@code true} to match the behavior in
943 * {@link android.os.Build.VERSION_CODES#M} and earlier.
944 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000945 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
946 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000947 *
948 * @hide
949 */
950 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
951 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
952
953 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000954 * A boolean extra indicating if the user consent steps from the provisioning flow should be
955 * skipped. If unspecified, defaults to {@code false}.
956 *
957 * It can only be used by an existing device owner trying to create a managed profile via
958 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
959 */
960 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
961 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
962
963 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000964 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100965 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400966 * <p>During device owner provisioning a device admin app is set as the owner of the device.
967 * A device owner has full control over the device. The device owner can not be modified by the
968 * user and the only way of resetting the device is if the device owner app calls a factory
969 * reset.
970 *
971 * <p> A typical use case would be a device that is owned by a company, but used by either an
972 * employee or client.
973 *
Benjamin Franzea956242016-03-21 15:45:56 +0000974 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100975 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000976 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100977 * contains the following properties:
978 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400979 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
980 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100981 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400982 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100983 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
984 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
985 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
986 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
987 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
988 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
989 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
990 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
991 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
992 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100993 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
994 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
995 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100996 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000997 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700998 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400999 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
1000 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
1001 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -04001002 */
1003 public static final String MIME_TYPE_PROVISIONING_NFC
1004 = "application/com.android.managedprovisioning";
1005
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +01001006 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001007 * Activity action: ask the user to add a new device administrator to the system.
1008 * The desired policy is the ComponentName of the policy in the
1009 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
1010 * bring the user through adding the device administrator to the system (or
1011 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001012 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001013 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1014 * field to provide the user with additional explanation (in addition
1015 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001016 *
1017 * <p>If your administrator is already active, this will ordinarily return immediately (without
1018 * user intervention). However, if your administrator has been updated and is requesting
1019 * additional uses-policy flags, the user will be presented with the new list. New policies
1020 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001021 */
1022 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1023 public static final String ACTION_ADD_DEVICE_ADMIN
1024 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001025
Dianne Hackbornd6847842010-01-12 18:14:19 -08001026 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001027 * @hide
1028 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -07001029 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001030 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001031 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
1032 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001033 * to remotely control restrictions on the user.
1034 *
Makoto Onukic8a5a552015-11-19 14:29:12 -08001035 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001036 * result of whether or not the user approved the action. If approved, the result will
1037 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
1038 * as a profile owner.
1039 *
1040 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
1041 * field to provide the user with additional explanation (in addition
1042 * to your component's description) about what is being added.
1043 *
Amith Yamasani814e9872015-03-23 14:04:53 -07001044 * <p>If there is already a profile owner active or the caller is not a system app, the
1045 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001046 */
1047 @SystemApi
1048 public static final String ACTION_SET_PROFILE_OWNER
1049 = "android.app.action.SET_PROFILE_OWNER";
1050
1051 /**
1052 * @hide
1053 * Name of the profile owner admin that controls the user.
1054 */
1055 @SystemApi
1056 public static final String EXTRA_PROFILE_OWNER_NAME
1057 = "android.app.extra.PROFILE_OWNER_NAME";
1058
1059 /**
Nicolas Prevot00799002015-07-27 18:15:20 +01001060 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -07001061 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001062 *
Jim Miller284b62e2010-06-08 14:27:42 -07001063 * @hide
1064 */
1065 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
1066 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
1067
1068 /**
Tony Mak1970f972016-08-30 17:41:48 +01001069 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +01001070 *
1071 * This broadcast is sent only to the primary user.
1072 * @see #ACTION_PROVISION_MANAGED_DEVICE
1073 */
1074 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1075 public static final String ACTION_DEVICE_OWNER_CHANGED
1076 = "android.app.action.DEVICE_OWNER_CHANGED";
1077
1078 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001079 * The ComponentName of the administrator component.
1080 *
1081 * @see #ACTION_ADD_DEVICE_ADMIN
1082 */
1083 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001084
Dianne Hackbornd6847842010-01-12 18:14:19 -08001085 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001086 * An optional CharSequence providing additional explanation for why the
1087 * admin is being added.
1088 *
1089 * @see #ACTION_ADD_DEVICE_ADMIN
1090 */
1091 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001092
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08001093 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001094 * Activity action: have the user enter a new password. This activity should
1095 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
1096 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
1097 * enter a new password that meets the current requirements. You can use
1098 * {@link #isActivePasswordSufficient()} to determine whether you need to
1099 * have the user select a new password in order to meet the current
1100 * constraints. Upon being resumed from this activity, you can check the new
1101 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +00001102 *
1103 * If the intent is launched from within a managed profile with a profile
1104 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
1105 * this will trigger entering a new password for the parent of the profile.
1106 * For all other cases it will trigger entering a new password for the user
1107 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001108 *
1109 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -08001110 */
1111 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1112 public static final String ACTION_SET_NEW_PASSWORD
1113 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -07001114
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001115 /**
Benjamin Franzc9921092016-01-08 17:17:44 +00001116 * Activity action: have the user enter a new password for the parent profile.
1117 * If the intent is launched from within a managed profile, this will trigger
1118 * entering a new password for the parent of the profile. In all other cases
1119 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1120 */
1121 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1122 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1123 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1124
1125 /**
phweissa0cb2512016-12-14 21:37:48 +01001126 * Broadcast action: Tell the status bar to open the device monitoring dialog, e.g. when
1127 * Network logging was enabled and the user tapped the notification.
1128 * <p class="note">This is a protected intent that can only be sent by the system.</p>
1129 * @hide
1130 */
1131 public static final String ACTION_SHOW_DEVICE_MONITORING_DIALOG
1132 = "android.app.action.SHOW_DEVICE_MONITORING_DIALOG";
1133
1134 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001135 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1136 * the parent profile to access intents sent from the managed profile.
1137 * That is, when an app in the managed profile calls
1138 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1139 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001140 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001141 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001142
1143 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001144 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1145 * the managed profile to access intents sent from the parent profile.
1146 * That is, when an app in the parent profile calls
1147 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1148 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001149 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001150 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001151
Dianne Hackbornd6847842010-01-12 18:14:19 -08001152 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001153 * Broadcast action: notify that a new local system update policy has been set by the device
1154 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001155 */
1156 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001157 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1158 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001159
Amith Yamasanid49489b2015-04-28 14:00:26 -07001160 /**
1161 * Permission policy to prompt user for new permission requests for runtime permissions.
1162 * Already granted or denied permissions are not affected by this.
1163 */
1164 public static final int PERMISSION_POLICY_PROMPT = 0;
1165
1166 /**
1167 * Permission policy to always grant new permission requests for runtime permissions.
1168 * Already granted or denied permissions are not affected by this.
1169 */
1170 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1171
1172 /**
1173 * Permission policy to always deny new permission requests for runtime permissions.
1174 * Already granted or denied permissions are not affected by this.
1175 */
1176 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1177
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001178 /**
1179 * Runtime permission state: The user can manage the permission
1180 * through the UI.
1181 */
1182 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1183
1184 /**
1185 * Runtime permission state: The permission is granted to the app
1186 * and the user cannot manage the permission through the UI.
1187 */
1188 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1189
1190 /**
1191 * Runtime permission state: The permission is denied to the app
1192 * and the user cannot manage the permission through the UI.
1193 */
1194 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001195
1196 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001197 * No management for current user in-effect. This is the default.
1198 * @hide
1199 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001200 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001201 public static final int STATE_USER_UNMANAGED = 0;
1202
1203 /**
1204 * Management partially setup, user setup needs to be completed.
1205 * @hide
1206 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001207 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001208 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1209
1210 /**
1211 * Management partially setup, user setup completed.
1212 * @hide
1213 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001214 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001215 public static final int STATE_USER_SETUP_COMPLETE = 2;
1216
1217 /**
1218 * Management setup and active on current user.
1219 * @hide
1220 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001221 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001222 public static final int STATE_USER_SETUP_FINALIZED = 3;
1223
1224 /**
1225 * Management partially setup on a managed profile.
1226 * @hide
1227 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001228 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001229 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1230
1231 /**
1232 * @hide
1233 */
1234 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1235 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1236 @Retention(RetentionPolicy.SOURCE)
1237 public @interface UserProvisioningState {}
1238
1239 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001240 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001241 *
1242 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1243 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1244 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1245 *
1246 * @hide
1247 */
1248 public static final int CODE_OK = 0;
1249
1250 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001251 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001252 *
1253 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1254 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1255 * owner.
1256 *
1257 * @hide
1258 */
1259 public static final int CODE_HAS_DEVICE_OWNER = 1;
1260
1261 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001262 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001263 *
1264 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1265 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1266 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1267 *
1268 * @hide
1269 */
1270 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1271
1272 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001273 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001274 *
1275 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1276 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1277 *
1278 * @hide
1279 */
1280 public static final int CODE_USER_NOT_RUNNING = 3;
1281
1282 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001283 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001284 *
1285 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1286 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1287 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1288 *
1289 * @hide
1290 */
1291 public static final int CODE_USER_SETUP_COMPLETED = 4;
1292
1293 /**
1294 * Code used to indicate that the device also has a user other than the system user.
1295 *
1296 * @hide
1297 */
1298 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1299
1300 /**
1301 * Code used to indicate that device has an account that prevents provisioning.
1302 *
1303 * @hide
1304 */
1305 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1306
1307 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001308 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001309 *
1310 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1311 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1312 *
1313 * @hide
1314 */
1315 public static final int CODE_NOT_SYSTEM_USER = 7;
1316
1317 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001318 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001319 *
1320 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1321 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1322 * when the device is a watch and is already paired.
1323 *
1324 * @hide
1325 */
1326 public static final int CODE_HAS_PAIRED = 8;
1327
1328 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001329 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001330 *
1331 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1332 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1333 *
1334 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1335 * @hide
1336 */
1337 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1338
1339 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001340 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001341 *
1342 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1343 *
1344 * @hide
1345 */
1346 public static final int CODE_SYSTEM_USER = 10;
1347
1348 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001349 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001350 *
1351 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1352 * managed profiles.
1353 *
1354 * @hide
1355 */
1356 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1357
1358 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001359 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001360 *
1361 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1362 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1363 * user.
1364 *
1365 * @hide
1366 */
1367 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1368
1369 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001370 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001371 *
1372 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1373 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1374 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1375 * admins.
1376 *
1377 * @hide
1378 */
1379 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1380
1381 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001382 * Result code for {@link #checkProvisioningPreCondition}.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001383 *
Esteban Talavera6c9116a2016-11-24 16:12:44 +00001384 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device the user is a
1385 * system user on a split system user device.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001386 *
1387 * @hide
1388 */
1389 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1390
1391 /**
Esteban Talavera01576862016-12-15 11:16:44 +00001392 * Result code for {@link #checkProvisioningPreCondition}.
1393 *
1394 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when adding a managed profile is
1395 * disallowed by {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
1396 *
1397 * @hide
1398 */
1399 public static final int CODE_ADD_MANAGED_PROFILE_DISALLOWED = 15;
1400
1401 /**
1402 * Result codes for {@link #checkProvisioningPreCondition} indicating all the provisioning pre
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001403 * conditions.
1404 *
1405 * @hide
1406 */
1407 @Retention(RetentionPolicy.SOURCE)
1408 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1409 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1410 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1411 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
Esteban Talavera01576862016-12-15 11:16:44 +00001412 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER, CODE_ADD_MANAGED_PROFILE_DISALLOWED})
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001413 public @interface ProvisioningPreCondition {}
1414
1415 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001416 * Return true if the given administrator component is currently active (enabled) in the system.
1417 *
1418 * @param admin The administrator component to check for.
1419 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1420 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001421 */
Robin Lee25e26452015-06-02 09:56:29 -07001422 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001423 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001424 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001425 }
1426
1427 /**
1428 * @see #isAdminActive(ComponentName)
1429 * @hide
1430 */
Robin Lee25e26452015-06-02 09:56:29 -07001431 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001432 if (mService != null) {
1433 try {
Robin Lee25e26452015-06-02 09:56:29 -07001434 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001435 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001436 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001437 }
1438 }
1439 return false;
1440 }
Charles Hedea0c3b2017-01-13 10:04:12 +00001441
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001442 /**
1443 * Return true if the given administrator component is currently being removed
1444 * for the user.
1445 * @hide
1446 */
Robin Lee25e26452015-06-02 09:56:29 -07001447 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001448 if (mService != null) {
1449 try {
Robin Lee25e26452015-06-02 09:56:29 -07001450 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001451 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001452 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001453 }
1454 }
1455 return false;
1456 }
1457
Dianne Hackbornd6847842010-01-12 18:14:19 -08001458 /**
Robin Lee25e26452015-06-02 09:56:29 -07001459 * Return a list of all currently active device administrators' component
1460 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001461 * returned.
1462 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001463 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001464 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001465 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001466 }
1467
1468 /**
1469 * @see #getActiveAdmins()
1470 * @hide
1471 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001472 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001473 if (mService != null) {
1474 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001475 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001476 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001477 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001478 }
1479 }
1480 return null;
1481 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001482
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001483 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001484 * Used by package administration code to determine if a package can be stopped
1485 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001486 * @hide
1487 */
David Ouyang3a83a332017-01-11 16:36:40 -08001488 @SystemApi
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001489 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001490 return packageHasActiveAdmins(packageName, myUserId());
1491 }
1492
1493 /**
1494 * Used by package administration code to determine if a package can be stopped
1495 * or uninstalled.
1496 * @hide
1497 */
1498 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001499 if (mService != null) {
1500 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001501 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001502 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001503 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001504 }
1505 }
1506 return false;
1507 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001508
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001509 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001510 * Remove a current administration component. This can only be called
1511 * by the application that owns the administration component; if you
1512 * try to remove someone else's component, a security exception will be
1513 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001514 *
1515 * <p>Note that the operation is not synchronous and the admin might still be active (as
1516 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001517 *
1518 * @param admin The administration compononent to remove.
1519 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001520 */
Robin Lee25e26452015-06-02 09:56:29 -07001521 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001522 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001523 if (mService != null) {
1524 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001525 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001526 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001527 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001528 }
1529 }
1530 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001531
Dianne Hackbornd6847842010-01-12 18:14:19 -08001532 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001533 * Returns true if an administrator has been granted a particular device policy. This can be
1534 * used to check whether the administrator was activated under an earlier set of policies, but
1535 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001536 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1538 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001539 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001540 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001541 */
Robin Lee25e26452015-06-02 09:56:29 -07001542 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001543 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001544 if (mService != null) {
1545 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001546 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001548 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001549 }
1550 }
1551 return false;
1552 }
1553
1554 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001555 * Returns true if the Profile Challenge is available to use for the given profile user.
1556 *
1557 * @hide
1558 */
1559 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1560 if (mService != null) {
1561 try {
1562 return mService.isSeparateProfileChallengeAllowed(userHandle);
1563 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001564 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001565 }
1566 }
1567 return false;
1568 }
1569
1570 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001571 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1572 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001573 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001574 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001575 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001576
Dianne Hackbornd6847842010-01-12 18:14:19 -08001577 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001578 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1579 * recognition technology. This implies technologies that can recognize the identity of
1580 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1581 * Note that quality constants are ordered so that higher values are more restrictive.
1582 */
1583 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1584
1585 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001586 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001587 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001588 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001589 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001590 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001591
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001592 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001593 * Constant for {@link #setPasswordQuality}: the user must have entered a
1594 * password containing at least numeric characters. Note that quality
1595 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001596 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001597 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001598
Dianne Hackbornd6847842010-01-12 18:14:19 -08001599 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001600 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001601 * password containing at least numeric characters with no repeating (4444)
1602 * or ordered (1234, 4321, 2468) sequences. Note that quality
1603 * constants are ordered so that higher values are more restrictive.
1604 */
1605 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1606
1607 /**
1608 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001609 * password containing at least alphabetic (or other symbol) characters.
1610 * Note that quality constants are ordered so that higher values are more
1611 * restrictive.
1612 */
1613 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001614
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001615 /**
1616 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001617 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001618 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001619 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001620 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001621 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001622
Dianne Hackbornd6847842010-01-12 18:14:19 -08001623 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001624 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001625 * password containing at least a letter, a numerical digit and a special
1626 * symbol, by default. With this password quality, passwords can be
1627 * restricted to contain various sets of characters, like at least an
1628 * uppercase letter, etc. These are specified using various methods,
1629 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1630 * that quality constants are ordered so that higher values are more
1631 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001632 */
1633 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1634
1635 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001636 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1637 * modify password. In case this password quality is set, the password is
1638 * managed by a profile owner. The profile owner can set any password,
1639 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1640 * that quality constants are ordered so that higher values are more
1641 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1642 * the highest.
1643 * @hide
1644 */
1645 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1646
1647 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001648 * @hide
1649 *
1650 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1651 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1652 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1653 * used by authenticator to exempt their accounts from this:
1654 *
1655 * <ul>
1656 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1657 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1658 * &lt;application&gt; tag in the manifest.
1659 *
1660 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1661 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1662 * Some authenticators claim to have any features, so to detect it, we also check
1663 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1664 * if any of the accounts have it.
1665 * </ul>
1666 */
1667 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1668 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1669
1670 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1671 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1672 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1673
1674 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001675 * Called by an application that is administering the device to set the password restrictions it
1676 * is imposing. After setting this, the user will not be able to enter a new password that is
1677 * not at least as restrictive as what has been set. Note that the current password will remain
1678 * until the user has set a new one, so the change does not take place immediately. To prompt
1679 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001680 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001681 * <p>
1682 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1683 * requested quality constant (between the policy set here, the user's preference, and any other
1684 * considerations) is the one that is in effect.
1685 * <p>
1686 * The calling device admin must have requested
1687 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1688 * not, a security exception will be thrown.
1689 * <p>
1690 * This method can be called on the {@link DevicePolicyManager} instance returned by
1691 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1692 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001693 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001695 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1696 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1697 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1698 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1699 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1700 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001701 */
Robin Lee25e26452015-06-02 09:56:29 -07001702 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001703 if (mService != null) {
1704 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001705 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001706 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001707 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001708 }
1709 }
1710 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001711
Dianne Hackbornd6847842010-01-12 18:14:19 -08001712 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001713 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001714 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001715 * a separate challenge are not taken into account.
1716 *
1717 * <p>This method can be called on the {@link DevicePolicyManager} instance
1718 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1719 * restrictions on the parent profile.
1720 *
Robin Lee25e26452015-06-02 09:56:29 -07001721 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001722 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001723 */
Robin Lee25e26452015-06-02 09:56:29 -07001724 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001725 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001726 }
1727
1728 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001729 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001730 if (mService != null) {
1731 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001732 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001733 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001734 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001735 }
1736 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001737 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001738 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001739
Dianne Hackbornd6847842010-01-12 18:14:19 -08001740 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001741 * Called by an application that is administering the device to set the minimum allowed password
1742 * length. After setting this, the user will not be able to enter a new password that is not at
1743 * least as restrictive as what has been set. Note that the current password will remain until
1744 * the user has set a new one, so the change does not take place immediately. To prompt the user
1745 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1746 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1747 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1748 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1749 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1750 * {@link #setPasswordQuality}.
1751 * <p>
1752 * The calling device admin must have requested
1753 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1754 * not, a security exception will be thrown.
1755 * <p>
1756 * This method can be called on the {@link DevicePolicyManager} instance returned by
1757 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1758 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001759 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001760 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001761 * @param length The new desired minimum password length. A value of 0 means there is no
1762 * restriction.
1763 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1764 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001765 */
Robin Lee25e26452015-06-02 09:56:29 -07001766 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001767 if (mService != null) {
1768 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001769 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001770 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001771 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001772 }
1773 }
1774 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001775
Dianne Hackbornd6847842010-01-12 18:14:19 -08001776 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001777 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001778 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001779 * a separate challenge are not taken into account.
1780 *
1781 * <p>This method can be called on the {@link DevicePolicyManager} instance
1782 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1783 * restrictions on the parent profile.
1784 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001785 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001786 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001787 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001788 */
Robin Lee25e26452015-06-02 09:56:29 -07001789 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001790 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001791 }
1792
1793 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001794 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001795 if (mService != null) {
1796 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001797 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001798 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001799 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001800 }
1801 }
1802 return 0;
1803 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001804
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001805 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001806 * Called by an application that is administering the device to set the minimum number of upper
1807 * case letters required in the password. After setting this, the user will not be able to enter
1808 * a new password that is not at least as restrictive as what has been set. Note that the
1809 * current password will remain until the user has set a new one, so the change does not take
1810 * place immediately. To prompt the user for a new password, use
1811 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1812 * setting this value. This constraint is only imposed if the administrator has also requested
1813 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001814 * <p>
1815 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001816 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1817 * not, a security exception will be thrown.
1818 * <p>
1819 * This method can be called on the {@link DevicePolicyManager} instance returned by
1820 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1821 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001822 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001823 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1824 * @param length The new desired minimum number of upper case letters required in the password.
1825 * A value of 0 means there is no restriction.
1826 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1827 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001828 */
Robin Lee25e26452015-06-02 09:56:29 -07001829 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001830 if (mService != null) {
1831 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001832 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001833 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001834 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001835 }
1836 }
1837 }
1838
1839 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001840 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001841 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001842 * its participating profiles. Restrictions on profiles that have a separate challenge
1843 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001844 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001845 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001846 * and only applies when the password quality is
1847 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001848 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001849 * <p>This method can be called on the {@link DevicePolicyManager} instance
1850 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1851 * restrictions on the parent profile.
1852 *
Robin Lee25e26452015-06-02 09:56:29 -07001853 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001854 * aggregate all admins.
1855 * @return The minimum number of upper case letters required in the
1856 * password.
1857 */
Robin Lee25e26452015-06-02 09:56:29 -07001858 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001859 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001860 }
1861
1862 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001863 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001864 if (mService != null) {
1865 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001866 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001867 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001868 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001869 }
1870 }
1871 return 0;
1872 }
1873
1874 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001875 * Called by an application that is administering the device to set the minimum number of lower
1876 * case letters required in the password. After setting this, the user will not be able to enter
1877 * a new password that is not at least as restrictive as what has been set. Note that the
1878 * current password will remain until the user has set a new one, so the change does not take
1879 * place immediately. To prompt the user for a new password, use
1880 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1881 * setting this value. This constraint is only imposed if the administrator has also requested
1882 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001883 * <p>
1884 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001885 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1886 * not, a security exception will be thrown.
1887 * <p>
1888 * This method can be called on the {@link DevicePolicyManager} instance returned by
1889 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1890 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001891 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001892 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1893 * @param length The new desired minimum number of lower case letters required in the password.
1894 * A value of 0 means there is no restriction.
1895 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1896 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001897 */
Robin Lee25e26452015-06-02 09:56:29 -07001898 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001899 if (mService != null) {
1900 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001901 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001902 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001903 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001904 }
1905 }
1906 }
1907
1908 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001909 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001910 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001911 * and its participating profiles. Restrictions on profiles that have
1912 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001913 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001914 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001915 * and only applies when the password quality is
1916 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001917 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001918 * <p>This method can be called on the {@link DevicePolicyManager} instance
1919 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1920 * restrictions on the parent profile.
1921 *
Robin Lee25e26452015-06-02 09:56:29 -07001922 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001923 * aggregate all admins.
1924 * @return The minimum number of lower case letters required in the
1925 * password.
1926 */
Robin Lee25e26452015-06-02 09:56:29 -07001927 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001928 return getPasswordMinimumLowerCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001929 }
1930
1931 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001932 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001933 if (mService != null) {
1934 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001935 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001936 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001937 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001938 }
1939 }
1940 return 0;
1941 }
1942
1943 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001944 * Called by an application that is administering the device to set the minimum number of
1945 * letters required in the password. After setting this, the user will not be able to enter a
1946 * new password that is not at least as restrictive as what has been set. Note that the current
1947 * password will remain until the user has set a new one, so the change does not take place
1948 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1949 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1950 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1951 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001952 * <p>
1953 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001954 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1955 * not, a security exception will be thrown.
1956 * <p>
1957 * This method can be called on the {@link DevicePolicyManager} instance returned by
1958 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1959 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001960 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1962 * @param length The new desired minimum number of letters required in the password. A value of
1963 * 0 means there is no restriction.
1964 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1965 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001966 */
Robin Lee25e26452015-06-02 09:56:29 -07001967 public void setPasswordMinimumLetters(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001968 if (mService != null) {
1969 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001970 mService.setPasswordMinimumLetters(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001972 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001973 }
1974 }
1975 }
1976
1977 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001978 * Retrieve the current number of letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001979 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001980 * and its participating profiles. Restrictions on profiles that have
1981 * a separate challenge are not taken into account.
1982 * This is the same value as set by
1983 * {@link #setPasswordMinimumLetters(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001984 * and only applies when the password quality is
1985 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001986 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001987 * <p>This method can be called on the {@link DevicePolicyManager} instance
1988 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1989 * restrictions on the parent profile.
1990 *
Robin Lee25e26452015-06-02 09:56:29 -07001991 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001992 * aggregate all admins.
1993 * @return The minimum number of letters required in the password.
1994 */
Robin Lee25e26452015-06-02 09:56:29 -07001995 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001996 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001997 }
1998
1999 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002000 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002001 if (mService != null) {
2002 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002003 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002004 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002005 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002006 }
2007 }
2008 return 0;
2009 }
2010
2011 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002012 * Called by an application that is administering the device to set the minimum number of
2013 * numerical digits required in the password. After setting this, the user will not be able to
2014 * enter a new password that is not at least as restrictive as what has been set. Note that the
2015 * current password will remain until the user has set a new one, so the change does not take
2016 * place immediately. To prompt the user for a new password, use
2017 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2018 * setting this value. This constraint is only imposed if the administrator has also requested
2019 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002020 * <p>
2021 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002022 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2023 * not, a security exception will be thrown.
2024 * <p>
2025 * This method can be called on the {@link DevicePolicyManager} instance returned by
2026 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2027 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002028 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002029 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2030 * @param length The new desired minimum number of numerical digits required in the password. A
2031 * value of 0 means there is no restriction.
2032 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2033 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002034 */
Robin Lee25e26452015-06-02 09:56:29 -07002035 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002036 if (mService != null) {
2037 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002038 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002039 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002040 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002041 }
2042 }
2043 }
2044
2045 /**
2046 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002047 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002048 * and its participating profiles. Restrictions on profiles that have
2049 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002050 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002051 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002052 * and only applies when the password quality is
2053 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002054 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002055 * <p>This method can be called on the {@link DevicePolicyManager} instance
2056 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2057 * restrictions on the parent profile.
2058 *
Robin Lee25e26452015-06-02 09:56:29 -07002059 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002060 * aggregate all admins.
2061 * @return The minimum number of numerical digits required in the password.
2062 */
Robin Lee25e26452015-06-02 09:56:29 -07002063 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002064 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002065 }
2066
2067 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002068 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002069 if (mService != null) {
2070 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002071 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002072 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002073 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002074 }
2075 }
2076 return 0;
2077 }
2078
2079 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002080 * Called by an application that is administering the device to set the minimum number of
2081 * symbols required in the password. After setting this, the user will not be able to enter a
2082 * new password that is not at least as restrictive as what has been set. Note that the current
2083 * password will remain until the user has set a new one, so the change does not take place
2084 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2085 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2086 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
2087 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002088 * <p>
2089 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002090 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2091 * not, a security exception will be thrown.
2092 * <p>
2093 * This method can be called on the {@link DevicePolicyManager} instance returned by
2094 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2095 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002096 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002097 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2098 * @param length The new desired minimum number of symbols required in the password. A value of
2099 * 0 means there is no restriction.
2100 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2101 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002102 */
Robin Lee25e26452015-06-02 09:56:29 -07002103 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002104 if (mService != null) {
2105 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002106 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002107 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002108 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002109 }
2110 }
2111 }
2112
2113 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002114 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002115 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002116 * and its participating profiles. Restrictions on profiles that have
2117 * a separate challenge are not taken into account. This is the same value as
2118 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002119 * and only applies when the password quality is
2120 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002121 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002122 * <p>This method can be called on the {@link DevicePolicyManager} instance
2123 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2124 * restrictions on the parent profile.
2125 *
Robin Lee25e26452015-06-02 09:56:29 -07002126 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002127 * aggregate all admins.
2128 * @return The minimum number of symbols required in the password.
2129 */
Robin Lee25e26452015-06-02 09:56:29 -07002130 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002131 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002132 }
2133
2134 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002135 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002136 if (mService != null) {
2137 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002138 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002139 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002140 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002141 }
2142 }
2143 return 0;
2144 }
2145
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002146 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002147 * Called by an application that is administering the device to set the minimum number of
2148 * non-letter characters (numerical digits or symbols) required in the password. After setting
2149 * this, the user will not be able to enter a new password that is not at least as restrictive
2150 * as what has been set. Note that the current password will remain until the user has set a new
2151 * one, so the change does not take place immediately. To prompt the user for a new password,
2152 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2153 * setting this value. This constraint is only imposed if the administrator has also requested
2154 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002155 * <p>
2156 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002157 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2158 * not, a security exception will be thrown.
2159 * <p>
2160 * This method can be called on the {@link DevicePolicyManager} instance returned by
2161 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2162 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002163 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002164 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2165 * @param length The new desired minimum number of letters required in the password. A value of
2166 * 0 means there is no restriction.
2167 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2168 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002169 */
Robin Lee25e26452015-06-02 09:56:29 -07002170 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002171 if (mService != null) {
2172 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002173 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002174 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002175 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002176 }
2177 }
2178 }
2179
2180 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002181 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002182 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002183 * and its participating profiles. Restrictions on profiles that have
2184 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002185 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002186 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002187 * and only applies when the password quality is
2188 * {@link #PASSWORD_QUALITY_COMPLEX}.
2189 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002190 * <p>This method can be called on the {@link DevicePolicyManager} instance
2191 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2192 * restrictions on the parent profile.
2193 *
Robin Lee25e26452015-06-02 09:56:29 -07002194 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002195 * aggregate all admins.
2196 * @return The minimum number of letters required in the password.
2197 */
Robin Lee25e26452015-06-02 09:56:29 -07002198 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002199 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002200 }
2201
2202 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002203 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002204 if (mService != null) {
2205 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002206 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002207 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002208 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002209 }
2210 }
2211 return 0;
2212 }
2213
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002214 /**
2215 * Called by an application that is administering the device to set the length of the password
2216 * history. After setting this, the user will not be able to enter a new password that is the
2217 * same as any password in the history. Note that the current password will remain until the
2218 * user has set a new one, so the change does not take place immediately. To prompt the user for
2219 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2220 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2221 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2222 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2223 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2224 * <p>
2225 * The calling device admin must have requested
2226 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2227 * not, a security exception will be thrown.
2228 * <p>
2229 * This method can be called on the {@link DevicePolicyManager} instance returned by
2230 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2231 * profile.
2232 *
2233 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2234 * @param length The new desired length of password history. A value of 0 means there is no
2235 * restriction.
2236 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2237 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2238 */
Robin Lee25e26452015-06-02 09:56:29 -07002239 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002240 if (mService != null) {
2241 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002242 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002243 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002244 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002245 }
2246 }
2247 }
2248
2249 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002250 * Called by a device admin to set the password expiration timeout. Calling this method will
2251 * restart the countdown for password expiration for the given admin, as will changing the
2252 * device password (for all admins).
2253 * <p>
2254 * The provided timeout is the time delta in ms and will be added to the current time. For
2255 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2256 * 432000000 ms for timeout.
2257 * <p>
2258 * To disable password expiration, a value of 0 may be used for timeout.
2259 * <p>
2260 * The calling device admin must have requested
2261 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2262 * not, a security exception will be thrown.
2263 * <p>
2264 * Note that setting the password will automatically reset the expiration time for all active
2265 * admins. Active admins do not need to explicitly call this method in that case.
2266 * <p>
2267 * This method can be called on the {@link DevicePolicyManager} instance returned by
2268 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2269 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002270 *
Jim Millera4e28d12010-11-08 16:15:47 -08002271 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002272 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2273 * there is no restriction (unlimited).
2274 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2275 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002276 */
Robin Lee25e26452015-06-02 09:56:29 -07002277 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002278 if (mService != null) {
2279 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002280 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002281 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002282 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002283 }
2284 }
2285 }
2286
2287 /**
Jim Miller6b857682011-02-16 16:27:41 -08002288 * Get the password expiration timeout for the given admin. The expiration timeout is the
2289 * recurring expiration timeout provided in the call to
2290 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002291 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2292 * have set restrictions on profiles that have a separate challenge are not taken into account.
2293 *
2294 * <p>This method can be called on the {@link DevicePolicyManager} instance
2295 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2296 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002297 *
Robin Lee25e26452015-06-02 09:56:29 -07002298 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002299 * @return The timeout for the given admin or the minimum of all timeouts
2300 */
Robin Lee25e26452015-06-02 09:56:29 -07002301 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002302 if (mService != null) {
2303 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002304 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002305 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002306 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002307 }
2308 }
2309 return 0;
2310 }
2311
2312 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002313 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002314 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002315 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2316 * of all expiration times is returned - which will be the minimum of all of them.
2317 *
2318 * <p>This method can be called on the {@link DevicePolicyManager} instance
2319 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2320 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002321 *
Robin Lee25e26452015-06-02 09:56:29 -07002322 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002323 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002324 */
Robin Lee25e26452015-06-02 09:56:29 -07002325 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002326 if (mService != null) {
2327 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002328 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002329 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002330 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002331 }
2332 }
2333 return 0;
2334 }
2335
2336 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002337 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002338 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002339 * have a separate challenge are not taken into account.
2340 *
2341 * <p>This method can be called on the {@link DevicePolicyManager} instance
2342 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2343 * restrictions on the parent profile.
2344 *
Robin Lee25e26452015-06-02 09:56:29 -07002345 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002346 * all admins.
2347 * @return The length of the password history
2348 */
Robin Lee25e26452015-06-02 09:56:29 -07002349 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002350 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002351 }
2352
2353 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002354 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002355 if (mService != null) {
2356 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002357 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002358 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002359 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002360 }
2361 }
2362 return 0;
2363 }
2364
Dianne Hackbornd6847842010-01-12 18:14:19 -08002365 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002366 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002367 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002368 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002369 * @return Returns the maximum length that the user can enter.
2370 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002371 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002372 // Kind-of arbitrary.
2373 return 16;
2374 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002375
Dianne Hackborn254cb442010-01-27 19:23:59 -08002376 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002377 * Determine whether the current password the user has set is sufficient to meet the policy
2378 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2379 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002380 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002381 * <p>
2382 * The calling device admin must have requested
2383 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2384 * not, a security exception will be thrown.
2385 * <p>
2386 * This method can be called on the {@link DevicePolicyManager} instance returned by
2387 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2388 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002389 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002390 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002391 * @throws SecurityException if the calling application does not own an active administrator
2392 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002393 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002394 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002395 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002396 if (mService != null) {
2397 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002398 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002399 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002400 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002401 }
2402 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002403 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002404 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002405
Dianne Hackbornd6847842010-01-12 18:14:19 -08002406 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002407 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002408 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002409 * requested by the admins of the parent user and its profiles.
2410 *
2411 * @param userHandle the userId of the profile to check the password for.
2412 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002413 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002414 * @hide
2415 */
2416 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2417 if (mService != null) {
2418 try {
2419 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2420 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002421 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002422 }
2423 }
2424 return false;
2425 }
2426
2427 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002428 * Retrieve the number of times the user has failed at entering a password since that last
2429 * successful password entry.
2430 * <p>
2431 * This method can be called on the {@link DevicePolicyManager} instance returned by
2432 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2433 * password attemts for the parent user.
2434 * <p>
2435 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2436 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002437 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002438 * @return The number of times user has entered an incorrect password since the last correct
2439 * password entry.
2440 * @throws SecurityException if the calling application does not own an active administrator
2441 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002442 */
2443 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002444 return getCurrentFailedPasswordAttempts(myUserId());
2445 }
2446
2447 /**
2448 * Retrieve the number of times the given user has failed at entering a
2449 * password since that last successful password entry.
2450 *
2451 * <p>The calling device admin must have requested
2452 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2453 * not and it is not the system uid, a security exception will be thrown.
2454 *
2455 * @hide
2456 */
2457 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002458 if (mService != null) {
2459 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002460 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002461 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002462 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002463 }
2464 }
2465 return -1;
2466 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002467
2468 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002469 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002470 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002471 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002472 * @hide
2473 */
2474 public boolean getDoNotAskCredentialsOnBoot() {
2475 if (mService != null) {
2476 try {
2477 return mService.getDoNotAskCredentialsOnBoot();
2478 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002479 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002480 }
2481 }
2482 return false;
2483 }
2484
2485 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002486 * Setting this to a value greater than zero enables a built-in policy that will perform a
2487 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2488 * This built-in policy combines watching for failed passwords and wiping the device, and
2489 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002490 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002491 * <p>
2492 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2493 * revoking credentials, or reporting the failure to a server), you should implement
2494 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2495 * use this API, because if the maximum count is reached, the device or profile will be wiped
2496 * immediately, and your callback will not be invoked.
2497 * <p>
2498 * This method can be called on the {@link DevicePolicyManager} instance returned by
2499 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2500 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002501 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002502 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002503 * @param num The number of failed password attempts at which point the device or profile will
2504 * be wiped.
2505 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2506 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2507 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002508 */
Robin Lee25e26452015-06-02 09:56:29 -07002509 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002510 if (mService != null) {
2511 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002512 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002513 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002514 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002515 }
2516 }
2517 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002518
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002519 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002520 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002521 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002522 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2523 * not taken into account.
2524 *
2525 * <p>This method can be called on the {@link DevicePolicyManager} instance
2526 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2527 * the value for the parent profile.
2528 *
Robin Lee25e26452015-06-02 09:56:29 -07002529 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002530 * all admins.
2531 */
Robin Lee25e26452015-06-02 09:56:29 -07002532 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002533 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002534 }
2535
2536 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002537 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002538 if (mService != null) {
2539 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002540 return mService.getMaximumFailedPasswordsForWipe(
2541 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002542 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002543 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002544 }
2545 }
2546 return 0;
2547 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002548
Dianne Hackborn254cb442010-01-27 19:23:59 -08002549 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002550 * Returns the profile with the smallest maximum failed passwords for wipe,
2551 * for the given user. So for primary user, it might return the primary or
2552 * a managed profile. For a secondary user, it would be the same as the
2553 * user passed in.
2554 * @hide Used only by Keyguard
2555 */
2556 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2557 if (mService != null) {
2558 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002559 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2560 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002561 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002562 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002563 }
2564 }
2565 return UserHandle.USER_NULL;
2566 }
2567
2568 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002569 * Flag for {@link #resetPassword}: don't allow other admins to change
2570 * the password again until the user has entered it.
2571 */
2572 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002573
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002574 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002575 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2576 * If the flag is set, the device can be booted without asking for user password.
2577 * The absence of this flag does not change the current boot requirements. This flag
2578 * can be set by the device owner only. If the app is not the device owner, the flag
2579 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2580 * device to factory defaults.
2581 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002582 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002583
2584 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002585 * Force a new device unlock password (the password needed to access the entire device, not for
2586 * individual accounts) on the user. This takes effect immediately.
2587 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002588 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002589 * device admins that are not device owner and not profile owner.
2590 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002591 * and profile owner can still do this when user is unlocked and does not have a managed
2592 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002593 * <p>
2594 * The given password must be sufficient for the current password quality and length constraints
2595 * as returned by {@link #getPasswordQuality(ComponentName)} and
2596 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2597 * it will be rejected and false returned. Note that the password may be a stronger quality
2598 * (containing alphanumeric characters when the requested quality is only numeric), in which
2599 * case the currently active quality will be increased to match.
2600 * <p>
2601 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002602 * current password constraints allow it. <em>Note: This will not work in
2603 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2604 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2605 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002606 * <p>
2607 * The calling device admin must have requested
2608 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2609 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002610 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002611 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002612 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002613 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2614 * @return Returns true if the password was applied, or false if it is not acceptable for the
2615 * current constraints or if the user has not been decrypted yet.
2616 * @throws SecurityException if the calling application does not own an active administrator
2617 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002618 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002619 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002620 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002621 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002622 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002623 if (mService != null) {
2624 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002625 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002626 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002627 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002628 }
2629 }
2630 return false;
2631 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002632
Dianne Hackbornd6847842010-01-12 18:14:19 -08002633 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002634 * Called by an application that is administering the device to set the maximum time for user
2635 * activity until the device will lock. This limits the length that the user can set. It takes
2636 * effect immediately.
2637 * <p>
2638 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2639 * to be able to call this method; if it has not, a security exception will be thrown.
2640 * <p>
2641 * This method can be called on the {@link DevicePolicyManager} instance returned by
2642 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2643 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002644 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002645 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002646 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2647 * is no restriction.
2648 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2649 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002650 */
Robin Lee25e26452015-06-02 09:56:29 -07002651 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002652 if (mService != null) {
2653 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002654 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002655 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002656 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002657 }
2658 }
2659 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002660
Dianne Hackbornd6847842010-01-12 18:14:19 -08002661 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002662 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002663 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002664 * a separate challenge are not taken into account.
2665 *
2666 * <p>This method can be called on the {@link DevicePolicyManager} instance
2667 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2668 * restrictions on the parent profile.
2669 *
Robin Lee25e26452015-06-02 09:56:29 -07002670 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002671 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002672 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002673 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002674 */
Robin Lee25e26452015-06-02 09:56:29 -07002675 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002676 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002677 }
2678
2679 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002680 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002681 if (mService != null) {
2682 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002683 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002684 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002685 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002686 }
2687 }
2688 return 0;
2689 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002690
Dianne Hackbornd6847842010-01-12 18:14:19 -08002691 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002692 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2693 * do not have a separate timeout to lock for work challenge only.
2694 *
2695 * @hide
2696 */
2697 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2698 if (mService != null) {
2699 try {
2700 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2701 } catch (RemoteException e) {
2702 throw e.rethrowFromSystemServer();
2703 }
2704 }
2705 return 0;
2706 }
2707
2708 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002709 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2710 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2711 * authentication method like password, pin or pattern.
2712 *
2713 * <p>This timeout is used internally to reset the timer to require strong auth again after
2714 * specified timeout each time it has been successfully used.
2715 *
2716 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2717 *
2718 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2719 *
2720 * <p>The calling device admin must be a device or profile owner. If it is not,
2721 * a {@link SecurityException} will be thrown.
2722 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002723 * <p>The calling device admin can verify the value it has set by calling
2724 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2725 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002726 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2727 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2728 * profile.
2729 *
2730 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2731 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002732 * authentication method. A value of 0 means the admin is not participating in
2733 * controlling the timeout.
2734 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2735 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2736 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2737 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002738 *
2739 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002740 */
2741 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2742 long timeoutMs) {
2743 if (mService != null) {
2744 try {
2745 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2746 } catch (RemoteException e) {
2747 throw e.rethrowFromSystemServer();
2748 }
2749 }
2750 }
2751
2752 /**
2753 * Determine for how long the user will be able to use secondary, non strong auth for
2754 * authentication, since last strong method authentication (password, pin or pattern) was used.
2755 * After the returned timeout the user is required to use strong authentication method.
2756 *
2757 * <p>This method can be called on the {@link DevicePolicyManager} instance
2758 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2759 * restrictions on the parent profile.
2760 *
2761 * @param admin The name of the admin component to check, or {@code null} to aggregate
2762 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002763 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002764 */
2765 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2766 return getRequiredStrongAuthTimeout(admin, myUserId());
2767 }
2768
2769 /** @hide per-user version */
2770 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2771 if (mService != null) {
2772 try {
2773 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2774 } catch (RemoteException e) {
2775 throw e.rethrowFromSystemServer();
2776 }
2777 }
2778 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2779 }
2780
2781 /**
Andrew Scull85a63bc2016-10-24 13:47:47 +01002782 * Flag for {@link #lockNow(int)}: also evict the user's credential encryption key from the
2783 * keyring. The user's credential will need to be entered again in order to derive the
2784 * credential encryption key that will be stored back in the keyring for future use.
2785 * <p>
2786 * This flag can only be used by a profile owner when locking a managed profile on an FBE
2787 * device.
2788 * <p>
2789 * In order to secure user data, the user will be stopped and restarted so apps should wait
2790 * until they are next run to perform further actions.
2791 */
2792 public static final int FLAG_EVICT_CE_KEY = 1;
2793
2794 /** @hide */
2795 @Retention(RetentionPolicy.SOURCE)
2796 @IntDef(flag=true, value={FLAG_EVICT_CE_KEY})
2797 public @interface LockNowFlag {}
2798
2799 /**
2800 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2801 * this call.
2802 * <p>
2803 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2804 * to be able to call this method; if it has not, a security exception will be thrown.
2805 * <p>
2806 * This method can be called on the {@link DevicePolicyManager} instance returned by
2807 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
2808 * <p>
2809 * Equivalent to calling {@link #lockNow(int)} with no flags.
2810 *
2811 * @throws SecurityException if the calling application does not own an active administrator
2812 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2813 */
2814 public void lockNow() {
2815 lockNow(0);
2816 }
2817
2818 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002819 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2820 * this call.
2821 * <p>
2822 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2823 * to be able to call this method; if it has not, a security exception will be thrown.
2824 * <p>
2825 * This method can be called on the {@link DevicePolicyManager} instance returned by
2826 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002827 *
Andrew Scull85a63bc2016-10-24 13:47:47 +01002828 * @param flags May be 0 or {@link #FLAG_EVICT_CE_KEY}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002829 * @throws SecurityException if the calling application does not own an active administrator
Andrew Scull85a63bc2016-10-24 13:47:47 +01002830 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK} or the
2831 * {@link #FLAG_EVICT_CE_KEY} flag is passed by an application that is not a profile
2832 * owner of a managed profile.
2833 * @throws IllegalArgumentException if the {@link #FLAG_EVICT_CE_KEY} flag is passed when
2834 * locking the parent profile.
2835 * @throws UnsupportedOperationException if the {@link #FLAG_EVICT_CE_KEY} flag is passed on a
2836 * non-FBE device.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002837 */
Andrew Scull85a63bc2016-10-24 13:47:47 +01002838 public void lockNow(@LockNowFlag int flags) {
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002839 if (mService != null) {
2840 try {
Andrew Scull85a63bc2016-10-24 13:47:47 +01002841 mService.lockNow(flags, mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002842 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002843 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002844 }
2845 }
2846 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002847
Dianne Hackbornd6847842010-01-12 18:14:19 -08002848 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002849 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002850 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002851 */
2852 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2853
2854 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002855 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2856 * data.
2857 *
Paul Crowley2934b262014-12-02 11:21:13 +00002858 * <p>This flag may only be set by device owner admins; if it is set by
2859 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002860 */
2861 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2862
2863 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002864 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2865 * other users will remain unaffected. Calling from the primary user will cause the device to
2866 * reboot, erasing all device data - including all the secondary users and their data - while
2867 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002868 * <p>
2869 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2870 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002871 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002872 * @param flags Bit mask of additional options: currently supported flags are
2873 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2874 * @throws SecurityException if the calling application does not own an active administrator
2875 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002876 */
2877 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002878 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002879 if (mService != null) {
2880 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002881 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002882 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002883 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002884 }
2885 }
2886 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002887
Dianne Hackbornd6847842010-01-12 18:14:19 -08002888 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002889 * Called by an application that is administering the device to set the
2890 * global proxy and exclusion list.
2891 * <p>
2892 * The calling device admin must have requested
2893 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2894 * this method; if it has not, a security exception will be thrown.
2895 * Only the first device admin can set the proxy. If a second admin attempts
2896 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002897 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002898 * be returned.
2899 * The method can be called repeatedly by the device admin alrady setting the
2900 * proxy to update the proxy and exclusion list.
2901 *
Robin Lee25e26452015-06-02 09:56:29 -07002902 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002903 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2904 * Pass Proxy.NO_PROXY to reset the proxy.
2905 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002906 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2907 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002908 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002909 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002910 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002911 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002912 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002913 if (proxySpec == null) {
2914 throw new NullPointerException();
2915 }
2916 if (mService != null) {
2917 try {
2918 String hostSpec;
2919 String exclSpec;
2920 if (proxySpec.equals(Proxy.NO_PROXY)) {
2921 hostSpec = null;
2922 exclSpec = null;
2923 } else {
2924 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2925 throw new IllegalArgumentException();
2926 }
2927 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2928 String hostName = sa.getHostName();
2929 int port = sa.getPort();
2930 StringBuilder hostBuilder = new StringBuilder();
2931 hostSpec = hostBuilder.append(hostName)
2932 .append(":").append(Integer.toString(port)).toString();
2933 if (exclusionList == null) {
2934 exclSpec = "";
2935 } else {
2936 StringBuilder listBuilder = new StringBuilder();
2937 boolean firstDomain = true;
2938 for (String exclDomain : exclusionList) {
2939 if (!firstDomain) {
2940 listBuilder = listBuilder.append(",");
2941 } else {
2942 firstDomain = false;
2943 }
2944 listBuilder = listBuilder.append(exclDomain.trim());
2945 }
2946 exclSpec = listBuilder.toString();
2947 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002948 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2949 != android.net.Proxy.PROXY_VALID)
2950 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002951 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002952 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002953 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002954 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002955 }
2956 }
2957 return null;
2958 }
2959
2960 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002961 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2962 * HTTP proxies - they are generally network dependent. However if you're doing something
2963 * unusual like general internal filtering this may be useful. On a private network where the
2964 * proxy is not accessible, you may break HTTP using this.
2965 * <p>
2966 * This method requires the caller to be the device owner.
2967 * <p>
2968 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002969 *
Jason Monk03bc9912014-05-13 09:44:57 -04002970 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002971 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2972 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2973 * {@code null} value will clear the global HTTP proxy.
2974 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002975 */
Robin Lee25e26452015-06-02 09:56:29 -07002976 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2977 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002978 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002979 if (mService != null) {
2980 try {
2981 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2982 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002983 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002984 }
2985 }
2986 }
2987
2988 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002989 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002990 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2991 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002992 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002993 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002994 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002995 if (mService != null) {
2996 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002997 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002998 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002999 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07003000 }
3001 }
3002 return null;
3003 }
3004
3005 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003006 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003007 * indicating that encryption is not supported.
3008 */
3009 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
3010
3011 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003012 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003013 * indicating that encryption is supported, but is not currently active.
3014 */
3015 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
3016
3017 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003018 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003019 * indicating that encryption is not currently active, but is currently
3020 * being activated. This is only reported by devices that support
3021 * encryption of data and only when the storage is currently
3022 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
3023 * to become encrypted will never return this value.
3024 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003025 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003026
3027 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08003028 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003029 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07003030 * <p>
3031 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003032 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08003033 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003034
3035 /**
Robin Lee3795fb02015-02-16 14:17:23 +00003036 * Result code for {@link #getStorageEncryptionStatus}:
3037 * indicating that encryption is active, but an encryption key has not
3038 * been set by the user.
3039 */
3040 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
3041
3042 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08003043 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07003044 * indicating that encryption is active and the encryption key is tied to the user or profile.
3045 * <p>
3046 * This value is only returned to apps targeting API level 24 and above. For apps targeting
3047 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
3048 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08003049 */
3050 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
3051
3052 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003053 * Activity action: begin the process of encrypting data on the device. This activity should
3054 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
3055 * After resuming from this activity, use {@link #getStorageEncryption}
3056 * to check encryption status. However, on some devices this activity may never return, as
3057 * it may trigger a reboot and in some cases a complete data wipe of the device.
3058 */
3059 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
3060 public static final String ACTION_START_ENCRYPTION
3061 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003062 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07003063 * Widgets are enabled in keyguard
3064 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003065 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07003066
3067 /**
Jim Miller50e62182014-04-23 17:25:00 -07003068 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07003069 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07003070 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
3071
3072 /**
3073 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
3074 */
3075 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
3076
3077 /**
Jim Miller50e62182014-04-23 17:25:00 -07003078 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3079 */
3080 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
3081
3082 /**
3083 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
3084 */
3085 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
3086
3087 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02003088 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07003089 * (e.g. PIN/Pattern/Password).
3090 */
3091 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
3092
3093 /**
Jim Miller06e34502014-07-17 14:46:05 -07003094 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
3095 */
3096 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
3097
3098 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08003099 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
3100 */
3101 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
3102
3103 /**
Jim Miller35207742012-11-02 15:33:20 -07003104 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07003105 */
3106 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07003107
3108 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003109 * Called by an application that is administering the device to request that the storage system
3110 * be encrypted.
3111 * <p>
3112 * When multiple device administrators attempt to control device encryption, the most secure,
3113 * supported setting will always be used. If any device administrator requests device
3114 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
3115 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003116 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003117 * <p>
3118 * This policy controls encryption of the secure (application data) storage area. Data written
3119 * to other storage areas may or may not be encrypted, and this policy does not require or
3120 * control the encryption of any other storage areas. There is one exception: If
3121 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
3122 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
3123 * written to disk within the encrypted storage area.
3124 * <p>
3125 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
3126 * to create a device PIN or Password. In this case, the storage is encrypted, but the
3127 * encryption key may not be fully secured. For maximum security, the administrator should also
3128 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003129 *
3130 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3131 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08003132 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003133 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
3134 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
3135 * {@link #getStorageEncryptionStatus()} to query the actual device state.
3136 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3137 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003138 */
Robin Lee25e26452015-06-02 09:56:29 -07003139 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003140 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003141 if (mService != null) {
3142 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003143 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003144 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003145 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003146 }
3147 }
3148 return ENCRYPTION_STATUS_UNSUPPORTED;
3149 }
3150
3151 /**
3152 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08003153 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003154 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08003155 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
3156 * this will return the requested encryption setting as an aggregate of all active
3157 * administrators.
3158 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003159 */
Robin Lee25e26452015-06-02 09:56:29 -07003160 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003161 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003162 if (mService != null) {
3163 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003164 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003165 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003166 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003167 }
3168 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08003169 return false;
3170 }
3171
3172 /**
3173 * Called by an application that is administering the device to
3174 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07003175 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08003176 * Depending on the returned status code, the caller may proceed in different
3177 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
3178 * storage system does not support encryption. If the
3179 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
3180 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00003181 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3182 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003183 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3184 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3185 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003186 *
Robin Lee7e678712014-07-24 16:41:31 +01003187 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003188 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003189 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003190 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003191 */
3192 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003193 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003194 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003195 }
3196
3197 /** @hide per-user version */
3198 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003199 if (mService != null) {
3200 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003201 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003203 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003204 }
3205 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003206 return ENCRYPTION_STATUS_UNSUPPORTED;
3207 }
3208
3209 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003210 * Mark a CA certificate as approved by the device user. This means that they have been notified
3211 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3212 * keep the certificate on the device.
3213 *
3214 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3215 * this certificate.
3216 *
3217 * @hide
3218 */
3219 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3220 if (mService != null) {
3221 try {
3222 return mService.approveCaCert(alias, userHandle, approval);
3223 } catch (RemoteException e) {
3224 throw e.rethrowFromSystemServer();
3225 }
3226 }
3227 return false;
3228 }
3229
3230 /**
3231 * Check whether a CA certificate has been approved by the device user.
3232 *
3233 * @hide
3234 */
3235 public boolean isCaCertApproved(String alias, int userHandle) {
3236 if (mService != null) {
3237 try {
3238 return mService.isCaCertApproved(alias, userHandle);
3239 } catch (RemoteException e) {
3240 throw e.rethrowFromSystemServer();
3241 }
3242 }
3243 return false;
3244 }
3245
3246 /**
Robin Lee7e678712014-07-24 16:41:31 +01003247 * Installs the given certificate as a user CA.
3248 *
Robin Lee25e26452015-06-02 09:56:29 -07003249 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3250 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003251 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003252 *
3253 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003254 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003255 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3256 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003257 */
Robin Lee25e26452015-06-02 09:56:29 -07003258 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003259 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003260 if (mService != null) {
3261 try {
Robin Lee7e678712014-07-24 16:41:31 +01003262 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003263 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003264 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003265 }
3266 }
3267 return false;
3268 }
3269
3270 /**
Robin Lee7e678712014-07-24 16:41:31 +01003271 * Uninstalls the given certificate from trusted user CAs, if present.
3272 *
Robin Lee25e26452015-06-02 09:56:29 -07003273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3274 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003275 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003276 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3277 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003278 */
Robin Lee25e26452015-06-02 09:56:29 -07003279 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003280 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003281 if (mService != null) {
3282 try {
Robin Lee306fe082014-06-19 14:04:24 +00003283 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07003284 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003285 } catch (CertificateException e) {
3286 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003287 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003288 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003289 }
3290 }
3291 }
3292
3293 /**
Robin Lee7e678712014-07-24 16:41:31 +01003294 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3295 * If a user has installed any certificates by other means than device policy these will be
3296 * included too.
3297 *
Robin Lee25e26452015-06-02 09:56:29 -07003298 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3299 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003300 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003301 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3302 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003303 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003304 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3305 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003306 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003307 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003308 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003309 mService.enforceCanManageCaCerts(admin);
3310 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3311 for (String alias : certStore.userAliases()) {
3312 try {
3313 certs.add(certStore.getCertificate(alias).getEncoded());
3314 } catch (CertificateException ce) {
3315 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3316 }
3317 }
3318 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003319 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003320 }
3321 }
3322 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003323 }
3324
3325 /**
Robin Lee7e678712014-07-24 16:41:31 +01003326 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3327 * means other than device policy will also be removed, except for system CA certificates.
3328 *
Robin Lee25e26452015-06-02 09:56:29 -07003329 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3330 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003331 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3332 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003333 */
Robin Lee25e26452015-06-02 09:56:29 -07003334 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003335 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003336 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003337 try {
3338 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
3339 .toArray(new String[0]));
3340 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003341 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003342 }
3343 }
3344 }
3345
3346 /**
3347 * Returns whether this certificate is installed as a trusted CA.
3348 *
Robin Lee25e26452015-06-02 09:56:29 -07003349 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3350 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003351 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003352 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3353 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003354 */
Robin Lee25e26452015-06-02 09:56:29 -07003355 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003356 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003357 if (mService != null) {
3358 try {
3359 mService.enforceCanManageCaCerts(admin);
3360 return getCaCertAlias(certBuffer) != null;
3361 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003362 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003363 } catch (CertificateException ce) {
3364 Log.w(TAG, "Could not parse certificate", ce);
3365 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003366 }
3367 return false;
3368 }
3369
3370 /**
Robin Leece3399f2016-02-24 12:08:32 +00003371 * Called by a device or profile owner, or delegated certificate installer, to install a
3372 * certificate and corresponding private key. All apps within the profile will be able to access
3373 * the certificate and use the private key, given direct user approval.
3374 *
3375 * <p>Access to the installed credentials will not be granted to the caller of this API without
3376 * direct user approval. This is for security - should a certificate installer become
3377 * compromised, certificates it had already installed will be protected.
3378 *
3379 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003380 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003381 *
Robin Lee25e26452015-06-02 09:56:29 -07003382 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3383 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003384 * @param privKey The private key to install.
3385 * @param cert The certificate to install.
3386 * @param alias The private key alias under which to install the certificate. If a certificate
3387 * with that alias already exists, it will be overwritten.
3388 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003389 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3390 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003391 */
Robin Leefbc65642015-08-03 16:21:22 +01003392 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3393 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003394 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003395 }
3396
3397 /**
3398 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003399 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3400 * profile will be able to access the certificate chain and use the private key, given direct
3401 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003402 *
Robin Leea1b290e2016-03-09 14:38:36 +00003403 * <p>The caller of this API may grant itself access to the certificate and private key
3404 * immediately, without user approval. It is a best practice not to request this unless strictly
3405 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003406 *
3407 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003408 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003409 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003410 * @param certs The certificate chain to install. The chain should start with the leaf
3411 * certificate and include the chain of trust in order. This will be returned by
3412 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003413 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003414 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003415 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003416 * credentials immediately. Otherwise, access to the credentials will be gated by user
3417 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003418 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003419 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3420 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003421 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003422 */
3423 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003424 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003425 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003426 try {
Rubin Xub4365912016-03-23 12:13:22 +00003427 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3428 byte[] pemChain = null;
3429 if (certs.length > 1) {
3430 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3431 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003432 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3433 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003434 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3435 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003436 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003437 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003438 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3439 Log.w(TAG, "Failed to obtain private key material", e);
3440 } catch (CertificateException | IOException e) {
3441 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003442 }
3443 return false;
3444 }
3445
3446 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003447 * Called by a device or profile owner, or delegated certificate installer, to remove a
3448 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003449 *
3450 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003451 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003452 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003453 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003454 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3455 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003456 */
3457 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003458 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003459 try {
3460 return mService.removeKeyPair(admin, alias);
3461 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003462 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003463 }
Robin Leefbc65642015-08-03 16:21:22 +01003464 }
3465
3466 /**
Robin Lee25e26452015-06-02 09:56:29 -07003467 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003468 * doesn't exist.
3469 */
3470 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3471 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3472 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3473 new ByteArrayInputStream(certBuffer));
3474 return new TrustedCertificateStore().getCertificateAlias(cert);
3475 }
3476
3477 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003478 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003479 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003480 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003481 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003482 * <p>
3483 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3484 * it is later cleared by calling this method with a null value or uninstallling the certificate
3485 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003486 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003487 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3488 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003489 * supplied certificate installer package must be installed when calling this API, otherwise an
3490 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003491 *
Robin Lee25e26452015-06-02 09:56:29 -07003492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003493 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003494 * access. If {@code null} is given the current package will be cleared.
3495 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003496 */
Robin Lee25e26452015-06-02 09:56:29 -07003497 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3498 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003499 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003500 if (mService != null) {
3501 try {
Robin Lee25e26452015-06-02 09:56:29 -07003502 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003504 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003505 }
3506 }
3507 }
3508
3509 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003510 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3511 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003512 *
Robin Lee25e26452015-06-02 09:56:29 -07003513 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003514 * @return The package name of the current delegated certificate installer, or {@code null} if
3515 * none is set.
3516 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003517 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003518 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3519 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003520 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003521 if (mService != null) {
3522 try {
Robin Lee25e26452015-06-02 09:56:29 -07003523 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003525 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003526 }
3527 }
3528 return null;
3529 }
3530
3531 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003532 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003533 * specific application for the current user.
3534 *
3535 * @deprecated this version only exists for compability with previous developer preview builds.
3536 * TODO: delete once there are no longer any live references.
3537 * @hide
3538 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003539 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003540 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3541 throws NameNotFoundException, UnsupportedOperationException {
3542 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3543 }
3544
3545 /**
3546 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003547 * specific application for the current user. This connection is automatically granted and
3548 * persisted after a reboot.
3549 * <p>
3550 * The designated package should declare a {@link android.net.VpnService} in its manifest
3551 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3552 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003553 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003554 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003555 * remove an existing always-on VPN configuration.
3556 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3557 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3558 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003559 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003560 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3561 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3562 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003563 */
Robin Leedc679712016-05-03 13:23:03 +01003564 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3565 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003566 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003567 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003568 if (mService != null) {
3569 try {
Robin Leedc679712016-05-03 13:23:03 +01003570 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003571 throw new NameNotFoundException(vpnPackage);
3572 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003573 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003574 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003575 }
3576 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003577 }
3578
3579 /**
3580 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003581 * always-on VPN connection for the current user. If there is no such package, or the always-on
3582 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003583 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003584 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3585 * is set.
3586 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003587 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003588 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003589 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003590 if (mService != null) {
3591 try {
3592 return mService.getAlwaysOnVpnPackage(admin);
3593 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003594 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003595 }
3596 }
3597 return null;
3598 }
3599
3600 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003601 * Called by an application that is administering the device to disable all cameras on the
3602 * device, for this user. After setting this, no applications running as this user will be able
3603 * to access any cameras on the device.
3604 * <p>
3605 * If the caller is device owner, then the restriction will be applied to all users.
3606 * <p>
3607 * The calling device admin must have requested
3608 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3609 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003610 *
3611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3612 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003613 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3614 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003615 */
Robin Lee25e26452015-06-02 09:56:29 -07003616 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003617 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003618 if (mService != null) {
3619 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003620 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003621 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003622 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003623 }
3624 }
3625 }
3626
3627 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003628 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003629 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003630 * @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 -07003631 * have disabled the camera
3632 */
Robin Lee25e26452015-06-02 09:56:29 -07003633 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003634 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003635 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003636 }
3637
3638 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003639 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003640 if (mService != null) {
3641 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003642 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003643 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003644 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003645 }
3646 }
3647 return false;
3648 }
3649
3650 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003651 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003652 * <p>
Esteban Talaverad36dd152016-12-15 08:51:45 +00003653 * If the device contains secondary users or profiles, they must be affiliated with the device
3654 * owner user. Otherwise a {@link SecurityException} will be thrown. See
3655 * {@link #setAffiliationIds}.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003656 *
3657 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003658 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3659 * wasn't triggered because a previous bugreport operation is still active (either the
3660 * bugreport is still running or waiting for the user to share or decline)
Esteban Talaverad36dd152016-12-15 08:51:45 +00003661 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
3662 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003663 */
3664 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003665 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003666 if (mService != null) {
3667 try {
3668 return mService.requestBugreport(admin);
3669 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003670 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003671 }
3672 }
3673 return false;
3674 }
3675
3676 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003677 * Determine whether or not creating a guest user has been disabled for the device
3678 *
3679 * @hide
3680 */
3681 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3682 // Currently guest users can always be created if multi-user is enabled
3683 // TODO introduce a policy for guest user creation
3684 return false;
3685 }
3686
3687 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003688 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3689 * screen capture also prevents the content from being shown on display devices that do not have
3690 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3691 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003692 * <p>
3693 * The calling device admin must be a device or profile owner. If it is not, a security
3694 * exception will be thrown.
3695 * <p>
3696 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3697 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003698 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003699 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003700 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003701 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003702 */
Robin Lee25e26452015-06-02 09:56:29 -07003703 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003704 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003705 if (mService != null) {
3706 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003707 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003709 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003710 }
3711 }
3712 }
3713
3714 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003715 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003716 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003717 * @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 +01003718 * have disabled screen capture.
3719 */
Robin Lee25e26452015-06-02 09:56:29 -07003720 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003721 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003722 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003723 }
3724
3725 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003726 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003727 if (mService != null) {
3728 try {
3729 return mService.getScreenCaptureDisabled(admin, userHandle);
3730 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003731 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003732 }
3733 }
3734 return false;
3735 }
3736
3737 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003738 * Called by a device owner to set whether auto time is required. If auto time is required the
3739 * user cannot set the date and time, but has to use network date and time.
3740 * <p>
3741 * Note: if auto time is required the user can still manually set the time zone.
3742 * <p>
3743 * The calling device admin must be a device owner. If it is not, a security exception will be
3744 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003745 *
3746 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3747 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003748 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003749 */
Robin Lee25e26452015-06-02 09:56:29 -07003750 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003751 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003752 if (mService != null) {
3753 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003754 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003755 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003756 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003757 }
3758 }
3759 }
3760
3761 /**
3762 * @return true if auto time is required.
3763 */
3764 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003765 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003766 if (mService != null) {
3767 try {
3768 return mService.getAutoTimeRequired();
3769 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003770 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003771 }
3772 }
3773 return false;
3774 }
3775
3776 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003777 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003778 * <p>
3779 * The system user is exempt from this policy - it is never ephemeral.
3780 * <p>
3781 * The calling device admin must be the device owner. If it is not, a security exception will be
3782 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003783 *
3784 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3785 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003786 * subsequently created users will be ephemeral.
3787 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003788 * @hide
3789 */
3790 public void setForceEphemeralUsers(
3791 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003792 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003793 if (mService != null) {
3794 try {
3795 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3796 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003797 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003798 }
3799 }
3800 }
3801
3802 /**
3803 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003804 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003805 * @hide
3806 */
3807 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003808 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003809 if (mService != null) {
3810 try {
3811 return mService.getForceEphemeralUsers(admin);
3812 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003813 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003814 }
3815 }
3816 return false;
3817 }
3818
3819 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003820 * Called by an application that is administering the device to disable keyguard customizations,
3821 * such as widgets. After setting this, keyguard features will be disabled according to the
3822 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003823 * <p>
3824 * The calling device admin must have requested
3825 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3826 * if it has not, a security exception will be thrown.
3827 * <p>
3828 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3829 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3830 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003831 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003832 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003833 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003834 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003835 * there is one, or the parent user otherwise.
3836 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3837 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003838 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003839 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3840 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003841 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3842 * profile.
3843 * <p>
3844 * Requests to disable other features on a managed profile will be ignored.
3845 * <p>
3846 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003847 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003848 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003849 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003850 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003851 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3852 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3853 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3854 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3855 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3856 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3857 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003858 */
Robin Lee25e26452015-06-02 09:56:29 -07003859 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003860 if (mService != null) {
3861 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003862 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003863 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003864 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003865 }
3866 }
3867 }
3868
3869 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003870 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003871 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003872 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3873 *
3874 * <p>This method can be called on the {@link DevicePolicyManager} instance
3875 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3876 * restrictions on the parent profile.
3877 *
Esteban Talavera62399912016-01-11 15:37:55 +00003878 * @param admin The name of the admin component to check, or {@code null} to check whether any
3879 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003880 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3881 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003882 */
Robin Lee25e26452015-06-02 09:56:29 -07003883 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003884 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003885 }
3886
3887 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003888 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003889 if (mService != null) {
3890 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003891 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003892 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003893 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003894 }
3895 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003896 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003897 }
3898
3899 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003900 * @hide
3901 */
Robin Lee25e26452015-06-02 09:56:29 -07003902 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3903 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003904 if (mService != null) {
3905 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003906 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003907 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003908 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003909 }
3910 }
3911 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003912
Dianne Hackbornd6847842010-01-12 18:14:19 -08003913 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003914 * @hide
3915 */
Robin Lee25e26452015-06-02 09:56:29 -07003916 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003917 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003918 }
3919
3920 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003921 * @hide
3922 */
Robin Lee25e26452015-06-02 09:56:29 -07003923 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003924 if (mService != null) {
3925 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003926 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003927 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003928 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003929 }
3930 }
3931 }
3932
3933 /**
3934 * @hide
3935 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003936 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003937 if (mService != null) {
3938 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003939 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003940 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003941 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003942 }
3943 }
3944 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003945
Dianne Hackbornd6847842010-01-12 18:14:19 -08003946 /**
3947 * @hide
3948 */
Andrew Scull5daf2732016-11-14 15:02:45 +00003949 public void reportPasswordChanged(@UserIdInt int userId) {
3950 if (mService != null) {
3951 try {
3952 mService.reportPasswordChanged(userId);
3953 } catch (RemoteException e) {
3954 throw e.rethrowFromSystemServer();
3955 }
3956 }
3957 }
3958
3959 /**
3960 * @hide
3961 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003962 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003963 if (mService != null) {
3964 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003965 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003966 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003967 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003968 }
3969 }
3970 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003971
Dianne Hackbornd6847842010-01-12 18:14:19 -08003972 /**
3973 * @hide
3974 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003975 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003976 if (mService != null) {
3977 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003978 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003979 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003980 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003981 }
3982 }
3983 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003984
3985 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003986 * @hide
3987 */
3988 public void reportFailedFingerprintAttempt(int userHandle) {
3989 if (mService != null) {
3990 try {
3991 mService.reportFailedFingerprintAttempt(userHandle);
3992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003993 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003994 }
3995 }
3996 }
3997
3998 /**
3999 * @hide
4000 */
4001 public void reportSuccessfulFingerprintAttempt(int userHandle) {
4002 if (mService != null) {
4003 try {
4004 mService.reportSuccessfulFingerprintAttempt(userHandle);
4005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004006 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004007 }
4008 }
4009 }
4010
4011 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00004012 * Should be called when keyguard has been dismissed.
4013 * @hide
4014 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004015 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004016 if (mService != null) {
4017 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004018 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004019 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004020 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004021 }
4022 }
4023 }
4024
4025 /**
4026 * Should be called when keyguard view has been shown to the user.
4027 * @hide
4028 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004029 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00004030 if (mService != null) {
4031 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00004032 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00004033 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004034 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00004035 }
4036 }
4037 }
4038
4039 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07004040 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004041 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07004042 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
4043 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004044 * @return whether the package was successfully registered as the device owner.
4045 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004046 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004047 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004048 public boolean setDeviceOwner(ComponentName who) {
4049 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004050 }
4051
4052 /**
4053 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07004054 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004055 public boolean setDeviceOwner(ComponentName who, int userId) {
4056 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004057 }
4058
4059 /**
4060 * @hide
4061 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004062 public boolean setDeviceOwner(ComponentName who, String ownerName) {
4063 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07004064 }
4065
4066 /**
4067 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00004068 * Sets the given package as the device owner. The package must already be installed. There
4069 * must not already be a device owner.
4070 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4071 * this method.
4072 * Calling this after the setup phase of the primary user has completed is allowed only if
4073 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07004074 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004075 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07004076 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004077 * @return whether the package was successfully registered as the device owner.
4078 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00004079 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004080 */
Makoto Onukia52562c2015-10-01 16:12:31 -07004081 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004082 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07004083 if (mService != null) {
4084 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004085 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07004086 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004087 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004088 }
4089 }
4090 return false;
4091 }
4092
4093 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004094 * Used to determine if a particular package has been registered as a Device Owner app.
4095 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07004096 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004097 * package is currently registered as the device owner app, pass in the package name from
4098 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07004099 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004100 * exact mechanism by which a device admin app is registered as a device owner app is defined by
4101 * the setup process.
4102 * @param packageName the package name of the app, to compare with the registered device owner
4103 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004104 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07004105 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004106 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004107 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004108 return isDeviceOwnerAppOnCallingUser(packageName);
4109 }
4110
4111 /**
4112 * @return true if a package is registered as device owner, only when it's running on the
4113 * calling user.
4114 *
4115 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
4116 * @hide
4117 */
4118 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
4119 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
4120 }
4121
4122 /**
4123 * @return true if a package is registered as device owner, even if it's running on a different
4124 * user.
4125 *
4126 * <p>Requires the MANAGE_USERS permission.
4127 *
4128 * @hide
4129 */
4130 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
4131 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
4132 }
4133
4134 /**
4135 * @return device owner component name, only when it's running on the calling user.
4136 *
4137 * @hide
4138 */
4139 public ComponentName getDeviceOwnerComponentOnCallingUser() {
4140 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
4141 }
4142
4143 /**
4144 * @return device owner component name, even if it's running on a different user.
4145 *
4146 * <p>Requires the MANAGE_USERS permission.
4147 *
4148 * @hide
4149 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01004150 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004151 public ComponentName getDeviceOwnerComponentOnAnyUser() {
4152 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
4153 }
4154
4155 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08004156 if (packageName == null) {
4157 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07004158 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004159 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08004160 if (deviceOwner == null) {
4161 return false;
4162 }
4163 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07004164 }
4165
Makoto Onukic8a5a552015-11-19 14:29:12 -08004166 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
4167 if (mService != null) {
4168 try {
4169 return mService.getDeviceOwnerComponent(callingUserOnly);
4170 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004171 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004172 }
4173 }
4174 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07004175 }
4176
Jason Monkb0dced82014-06-06 14:36:20 -04004177 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004178 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
4179 * no device owner.
4180 *
4181 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07004182 *
4183 * @hide
4184 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004185 public int getDeviceOwnerUserId() {
4186 if (mService != null) {
4187 try {
4188 return mService.getDeviceOwnerUserId();
4189 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004190 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004191 }
4192 }
4193 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004194 }
4195
4196 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004197 * Clears the current device owner. The caller must be the device owner. This function should be
4198 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4199 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004200 *
4201 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004202 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4203 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004204 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004205 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004206 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004207 if (mService != null) {
4208 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004209 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004210 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004211 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004212 }
4213 }
4214 }
4215
Makoto Onukia52562c2015-10-01 16:12:31 -07004216 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004217 * Returns the device owner package name, only if it's running on the calling user.
4218 *
4219 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004220 *
4221 * @hide
4222 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004223 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004224 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004225 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004226 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4227 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004228 }
4229
4230 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004231 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004232 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004233 * @return whether the device is managed by a Device Owner.
4234 * @throws SecurityException if the caller is not the device owner, does not hold the
4235 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004236 *
4237 * @hide
4238 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004239 @SystemApi
4240 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004241 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004242 try {
4243 return mService.hasDeviceOwner();
4244 } catch (RemoteException re) {
4245 throw re.rethrowFromSystemServer();
4246 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004247 }
4248
4249 /**
4250 * Returns the device owner name. Note this method *will* return the device owner
4251 * name when it's running on a different user.
4252 *
4253 * <p>Requires the MANAGE_USERS permission.
4254 *
4255 * @hide
4256 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004257 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004258 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004259 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004260 if (mService != null) {
4261 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004262 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004263 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004264 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004265 }
4266 }
4267 return null;
4268 }
Adam Connors776c5552014-01-09 10:42:56 +00004269
4270 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004271 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004272 * @deprecated Do not use
4273 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004274 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004275 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004276 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004277 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004278 return null;
4279 }
4280
4281 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004282 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004283 * @deprecated Do not use
4284 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004285 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004286 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004287 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004288 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004289 return null;
4290 }
4291
Julia Reynolds20118f12015-02-11 12:34:08 -05004292 /**
Adam Connors776c5552014-01-09 10:42:56 +00004293 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004294 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304295 * Sets the given component as an active admin and registers the package as the profile
4296 * owner for this user. The package must already be installed and there shouldn't be
4297 * an existing profile owner registered for this user. Also, this method must be called
4298 * before the user setup has been completed.
4299 * <p>
4300 * This method can only be called by system apps that hold MANAGE_USERS permission and
4301 * MANAGE_DEVICE_ADMINS permission.
4302 * @param admin The component to register as an active admin and profile owner.
4303 * @param ownerName The user-visible name of the entity that is managing this user.
4304 * @return whether the admin was successfully registered as the profile owner.
4305 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4306 * the user has already been set up.
4307 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004308 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004309 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004310 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304311 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004312 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304313 if (mService != null) {
4314 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004315 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304316 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004317 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304318 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004319 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304320 }
4321 }
4322 return false;
4323 }
4324
4325 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004326 * Clears the active profile owner and removes all user restrictions. The caller must be from
4327 * the same package as the active profile owner for this user, otherwise a SecurityException
4328 * will be thrown.
4329 * <p>
4330 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004331 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004332 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004333 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004334 */
Robin Lee25e26452015-06-02 09:56:29 -07004335 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004336 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004337 if (mService != null) {
4338 try {
4339 mService.clearProfileOwner(admin);
4340 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004341 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004342 }
4343 }
4344 }
4345
4346 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004347 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004348 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004349 */
4350 public boolean hasUserSetupCompleted() {
4351 if (mService != null) {
4352 try {
4353 return mService.hasUserSetupCompleted();
4354 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004355 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004356 }
4357 }
4358 return true;
4359 }
4360
4361 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004362 * @hide
4363 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004364 * already be installed. There must not already be a profile owner for this user.
4365 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4366 * this method.
4367 * Calling this after the setup phase of the specified user has completed is allowed only if:
4368 * - the caller is SYSTEM_UID.
4369 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004370 * @param admin the component name to be registered as profile owner.
4371 * @param ownerName the human readable name of the organisation associated with this DPM.
4372 * @param userHandle the userId to set the profile owner for.
4373 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004374 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4375 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004376 */
Robin Lee25e26452015-06-02 09:56:29 -07004377 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004378 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004379 if (mService != null) {
4380 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004381 if (ownerName == null) {
4382 ownerName = "";
4383 }
4384 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004385 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004386 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004387 }
4388 }
4389 return false;
4390 }
4391
4392 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004393 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004394 * <p>
4395 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004396 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004397 * <p>
4398 * If the device owner information contains only whitespaces then the message on the lock screen
4399 * will be blank and the user will not be allowed to change it.
4400 * <p>
4401 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004402 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4403 * and set a new version of this string accordingly.
4404 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004405 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004406 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004407 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004408 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004409 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004410 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004411 if (mService != null) {
4412 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004413 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004414 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004415 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004416 }
4417 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004418 }
4419
4420 /**
4421 * @return The device owner information. If it is not set returns {@code null}.
4422 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004423 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004424 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004425 if (mService != null) {
4426 try {
4427 return mService.getDeviceOwnerLockScreenInfo();
4428 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004429 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004430 }
4431 }
4432 return null;
4433 }
4434
4435 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004436 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004437 * <p>
4438 * A suspended package will not be able to start activities. Its notifications will be hidden,
4439 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4440 * device.
4441 * <p>
4442 * The package must already be installed. If the package is uninstalled while suspended the
4443 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004444 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004445 *
4446 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004447 * @param packageNames The package names to suspend or unsuspend.
4448 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004449 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004450 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004451 * this method.
4452 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004453 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004454 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4455 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004456 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004457 if (mService != null) {
4458 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004459 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004460 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004461 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004462 }
4463 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004464 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004465 }
4466
4467 /**
4468 * Called by device or profile owners to determine if a package is suspended.
4469 *
4470 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4471 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004472 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004473 * suspended, could not be found or an error occurred.
4474 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004475 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004476 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004477 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4478 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004479 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004480 if (mService != null) {
4481 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004482 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004483 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004484 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004485 } catch (IllegalArgumentException ex) {
4486 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004487 }
4488 }
4489 return false;
4490 }
4491
4492 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004493 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4494 * be used. Only the profile owner can call this.
4495 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004496 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004497 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004498 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004499 */
Robin Lee25e26452015-06-02 09:56:29 -07004500 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004501 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004502 if (mService != null) {
4503 try {
4504 mService.setProfileEnabled(admin);
4505 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004506 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004507 }
4508 }
4509 }
4510
4511 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004512 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4513 * is called from. Only a profile owner or device owner can call this. If this is never called
4514 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004515 *
4516 * @see #isProfileOwnerApp
4517 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004518 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004519 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004520 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004521 */
Robin Lee25e26452015-06-02 09:56:29 -07004522 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004523 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004524 if (mService != null) {
4525 try {
Robin Lee25e26452015-06-02 09:56:29 -07004526 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004527 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004528 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004529 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004530 }
4531 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004532
4533 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004534 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004535 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004536 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004537 *
4538 * @param packageName The package name of the app to compare with the registered profile owner.
4539 * @return Whether or not the package is registered as the profile owner.
4540 */
4541 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004542 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004543 if (mService != null) {
4544 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004545 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004546 return profileOwner != null
4547 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004548 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004549 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004550 }
4551 }
4552 return false;
4553 }
4554
4555 /**
4556 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004557 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004558 * owner has been set for that user.
4559 * @throws IllegalArgumentException if the userId is invalid.
4560 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004561 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004562 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004563 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004564 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4565 }
4566
4567 /**
4568 * @see #getProfileOwner()
4569 * @hide
4570 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004571 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4572 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004573 if (mService != null) {
4574 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004575 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004576 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004577 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004578 }
4579 }
4580 return null;
4581 }
4582
4583 /**
4584 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004585 * @return the human readable name of the organisation associated with this DPM or {@code null}
4586 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004587 * @throws IllegalArgumentException if the userId is invalid.
4588 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004589 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004590 if (mService != null) {
4591 try {
4592 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4593 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004594 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004595 }
4596 }
4597 return null;
4598 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004599
4600 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004601 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004602 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004603 * @return the human readable name of the organisation associated with this profile owner or
4604 * null if one is not set.
4605 * @throws IllegalArgumentException if the userId is invalid.
4606 */
4607 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004608 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004609 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004610 if (mService != null) {
4611 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004612 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004613 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004614 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004615 }
4616 }
4617 return null;
4618 }
4619
4620 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004621 * Called by a profile owner or device owner to add a default intent handler activity for
4622 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004623 * handler even if the set of potential event handlers for the intent filter changes and if the
4624 * intent preferences are reset.
4625 * <p>
4626 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4627 * When the activity is (re)installed, it is automatically reset as default intent handler for
4628 * the filter.
4629 * <p>
4630 * The calling device admin must be a profile owner or device owner. If it is not, a security
4631 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004632 *
4633 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4634 * @param filter The IntentFilter for which a default handler is added.
4635 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004636 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004637 */
Robin Lee25e26452015-06-02 09:56:29 -07004638 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4639 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004640 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004641 if (mService != null) {
4642 try {
4643 mService.addPersistentPreferredActivity(admin, filter, activity);
4644 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004645 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004646 }
4647 }
4648 }
4649
4650 /**
4651 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004652 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004653 * <p>
4654 * The calling device admin must be a profile owner. If it is not, a security exception will be
4655 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004656 *
4657 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4658 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004659 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004660 */
Robin Lee25e26452015-06-02 09:56:29 -07004661 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004662 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004663 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004664 if (mService != null) {
4665 try {
4666 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4667 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004668 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004669 }
4670 }
4671 }
Robin Lee66e5d962014-04-09 16:44:21 +01004672
4673 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004674 * Called by a profile owner or device owner to grant permission to a package to manage
4675 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4676 * {@link #getApplicationRestrictions}.
4677 * <p>
4678 * This permission is persistent until it is later cleared by calling this method with a
4679 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004680 * <p>
4681 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004682 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004683 *
4684 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4685 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004686 * APIs. If {@code null} is given the current package will be cleared.
4687 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004688 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004689 */
4690 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004691 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004692 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004693 if (mService != null) {
4694 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004695 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4696 throw new NameNotFoundException(packageName);
4697 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004698 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004699 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004700 }
4701 }
4702 }
4703
4704 /**
4705 * Called by a profile owner or device owner to retrieve the application restrictions managing
4706 * package for the current user, or {@code null} if none is set.
4707 *
4708 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4709 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004710 * {@code null} if none is set.
4711 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004712 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004713 public @Nullable String getApplicationRestrictionsManagingPackage(
4714 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004715 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004716 if (mService != null) {
4717 try {
4718 return mService.getApplicationRestrictionsManagingPackage(admin);
4719 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004720 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004721 }
4722 }
4723 return null;
4724 }
4725
4726 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004727 * Called by any application to find out whether it has been granted permission via
4728 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4729 * for the calling user.
4730 *
4731 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4732 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004733 */
4734 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004735 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004736 if (mService != null) {
4737 try {
4738 return mService.isCallerApplicationRestrictionsManagingPackage();
4739 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004740 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004741 }
4742 }
4743 return false;
4744 }
4745
4746 /**
4747 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004748 * <p>
4749 * The caller must be a profile or device owner on that user, or the package allowed to manage
4750 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4751 * security exception will be thrown.
4752 * <p>
4753 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004754 * <ul>
4755 * <li>{@code boolean}
4756 * <li>{@code int}
4757 * <li>{@code String} or {@code String[]}
4758 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4759 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004760 * <p>
4761 * If the restrictions are not available yet, but may be applied in the near future, the caller
4762 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004763 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004764 * <p>
4765 * The application restrictions are only made visible to the target application via
4766 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4767 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004768 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004769 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004770 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4771 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004772 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004773 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004774 * @param packageName The name of the package to update restricted settings for.
4775 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004776 * set of active restrictions.
4777 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004778 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004779 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004780 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004781 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004782 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004783 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004784 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004785 if (mService != null) {
4786 try {
4787 mService.setApplicationRestrictions(admin, packageName, settings);
4788 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004789 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004790 }
4791 }
4792 }
4793
4794 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004795 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4796 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4797 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004798 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004799 * <p>
4800 * The calling device admin must have requested
4801 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4802 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004803 * <p>
4804 * This method can be called on the {@link DevicePolicyManager} instance returned by
4805 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4806 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004807 *
4808 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004809 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004810 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4811 * strictly disabled according to the state of the
4812 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4813 * <p>
4814 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4815 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4816 * device admins.
4817 * <p>
4818 * Consult documentation for the specific TrustAgent to determine legal options
4819 * parameters.
4820 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4821 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004822 */
Robin Lee25e26452015-06-02 09:56:29 -07004823 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4824 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004825 if (mService != null) {
4826 try {
Tony Mak089d8402016-04-05 17:42:55 +01004827 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004828 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004829 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004830 }
4831 }
4832 }
4833
4834 /**
Jim Millere303bf42014-08-26 17:12:29 -07004835 * Gets configuration for the given trust agent based on aggregating all calls to
4836 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4837 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004838 * <p>
4839 * This method can be called on the {@link DevicePolicyManager} instance returned by
4840 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4841 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004842 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004843 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4844 * this function returns a list of configurations for all admins that declare
4845 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4846 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4847 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4848 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004849 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004850 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004851 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004852 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4853 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004854 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004855 }
4856
4857 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004858 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4859 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004860 if (mService != null) {
4861 try {
Tony Mak089d8402016-04-05 17:42:55 +01004862 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4863 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004864 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004865 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004866 }
4867 }
Jim Millere303bf42014-08-26 17:12:29 -07004868 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004869 }
4870
4871 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004872 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4873 * managed profile will be shown in the parent profile, for incoming calls.
4874 * <p>
4875 * The calling device admin must be a profile owner. If it is not, a security exception will be
4876 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004877 *
Robin Lee25e26452015-06-02 09:56:29 -07004878 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004879 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004880 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004881 */
Robin Lee25e26452015-06-02 09:56:29 -07004882 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004883 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004884 if (mService != null) {
4885 try {
Robin Lee25e26452015-06-02 09:56:29 -07004886 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004887 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004888 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004889 }
4890 }
4891 }
4892
4893 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004894 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4895 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004896 * <p>
4897 * The calling device admin must be a profile owner. If it is not, a security exception will be
4898 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004899 *
Robin Lee25e26452015-06-02 09:56:29 -07004900 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004901 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004902 */
Robin Lee25e26452015-06-02 09:56:29 -07004903 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004904 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004905 if (mService != null) {
4906 try {
Robin Lee25e26452015-06-02 09:56:29 -07004907 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004908 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004909 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004910 }
4911 }
4912 return false;
4913 }
4914
4915 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004916 * Determine whether or not caller-Id information has been disabled.
4917 *
4918 * @param userHandle The user for whom to check the caller-id permission
4919 * @hide
4920 */
4921 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4922 if (mService != null) {
4923 try {
4924 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4925 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004926 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004927 }
4928 }
4929 return false;
4930 }
4931
4932 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004933 * Called by a profile owner of a managed profile to set whether contacts search from the
4934 * managed profile will be shown in the parent profile, for incoming calls.
4935 * <p>
4936 * The calling device admin must be a profile owner. If it is not, a security exception will be
4937 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004938 *
4939 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4940 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004941 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004942 */
4943 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4944 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004945 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004946 if (mService != null) {
4947 try {
4948 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4949 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004950 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004951 }
4952 }
4953 }
4954
4955 /**
4956 * Called by a profile owner of a managed profile to determine whether or not contacts search
4957 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004958 * <p>
4959 * The calling device admin must be a profile owner. If it is not, a security exception will be
4960 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004961 *
4962 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004963 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004964 */
4965 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004966 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004967 if (mService != null) {
4968 try {
4969 return mService.getCrossProfileContactsSearchDisabled(admin);
4970 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004971 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004972 }
4973 }
4974 return false;
4975 }
4976
4977
4978 /**
4979 * Determine whether or not contacts search has been disabled.
4980 *
4981 * @param userHandle The user for whom to check the contacts search permission
4982 * @hide
4983 */
4984 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4985 if (mService != null) {
4986 try {
4987 return mService
4988 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4989 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004990 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004991 }
4992 }
4993 return false;
4994 }
4995
4996 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004997 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004998 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004999 * @hide
5000 */
5001 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00005002 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07005003 if (mService != null) {
5004 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00005005 mService.startManagedQuickContact(actualLookupKey, actualContactId,
5006 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07005007 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005008 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07005009 }
5010 }
5011 }
5012
5013 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005014 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00005015 * @hide
5016 */
5017 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
5018 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00005019 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00005020 originalIntent);
5021 }
5022
5023 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005024 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
5025 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005026 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005027 * The calling device admin must be a profile owner. If it is not, a security exception will be
5028 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005029 * <p>
5030 * This API works on managed profile only.
5031 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5033 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
5034 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005035 */
Robin Lee25e26452015-06-02 09:56:29 -07005036 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005037 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005038 if (mService != null) {
5039 try {
Robin Lee25e26452015-06-02 09:56:29 -07005040 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01005041 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005042 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005043 }
5044 }
5045 }
5046
5047 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005048 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
5049 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01005050 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005051 * The calling device admin must be a profile owner. If it is not, a security exception will be
5052 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01005053 * <p>
5054 * This API works on managed profile only.
5055 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005056 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5057 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01005058 */
Robin Lee25e26452015-06-02 09:56:29 -07005059 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005060 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01005061 if (mService != null) {
5062 try {
Robin Lee25e26452015-06-02 09:56:29 -07005063 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01005064 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005065 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005066 }
5067 }
5068 return true;
5069 }
5070
5071 /**
5072 * Determine whether or not Bluetooth devices cannot access contacts.
5073 * <p>
5074 * This API works on managed profile UserHandle only.
5075 *
5076 * @param userHandle The user for whom to check the caller-id permission
5077 * @hide
5078 */
5079 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
5080 if (mService != null) {
5081 try {
5082 return mService.getBluetoothContactSharingDisabledForUser(userHandle
5083 .getIdentifier());
5084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005085 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01005086 }
5087 }
5088 return true;
5089 }
5090
5091 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005092 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005093 * profile can also be resolved in the parent, or vice versa. Only activity intents are
5094 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00005095 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005096 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01005097 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005098 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01005099 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005100 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
5101 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005102 */
Robin Lee25e26452015-06-02 09:56:29 -07005103 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005104 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005105 if (mService != null) {
5106 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005107 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005108 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005109 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005110 }
5111 }
5112 }
5113
5114 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005115 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
5116 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01005117 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005118 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005119 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005120 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005121 */
Robin Lee25e26452015-06-02 09:56:29 -07005122 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005123 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005124 if (mService != null) {
5125 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01005126 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005127 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005128 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00005129 }
5130 }
5131 }
5132
5133 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005134 * Called by a profile or device owner to set the permitted accessibility services. When set by
5135 * a device owner or profile owner the restriction applies to all profiles of the user the
5136 * device owner or profile owner is an admin for. By default the user can use any accessiblity
5137 * service. When zero or more packages have been added, accessiblity services that are not in
5138 * the list and not part of the system can not be enabled by the user.
5139 * <p>
5140 * Calling with a null value for the list disables the restriction so that all services can be
5141 * used, calling with an empty list only allows the builtin system's services.
5142 * <p>
5143 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005144 *
5145 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5146 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005147 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
5148 * accessibility services enabled, that are not in the list.
5149 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005150 */
Robin Lee25e26452015-06-02 09:56:29 -07005151 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005152 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005153 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005154 if (mService != null) {
5155 try {
5156 return mService.setPermittedAccessibilityServices(admin, packageNames);
5157 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005158 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005159 }
5160 }
5161 return false;
5162 }
5163
5164 /**
5165 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005166 * <p>
5167 * An empty list means no accessibility services except system services are allowed. Null means
5168 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005169 *
5170 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5171 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005172 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005173 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005174 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005175 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005176 if (mService != null) {
5177 try {
5178 return mService.getPermittedAccessibilityServices(admin);
5179 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005180 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005181 }
5182 }
5183 return null;
5184 }
5185
5186 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005187 * Called by the system to check if a specific accessibility service is disabled by admin.
5188 *
5189 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5190 * @param packageName Accessibility service package name that needs to be checked.
5191 * @param userHandle user id the admin is running as.
5192 * @return true if the accessibility service is permitted, otherwise false.
5193 *
5194 * @hide
5195 */
5196 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5197 @NonNull String packageName, int userHandle) {
5198 if (mService != null) {
5199 try {
5200 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5201 userHandle);
5202 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005203 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005204 }
5205 }
5206 return false;
5207 }
5208
5209 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005210 * Returns the list of accessibility services permitted by the device or profiles
5211 * owners of this user.
5212 *
5213 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5214 * it will contain the intersection of the permitted lists for any device or profile
5215 * owners that apply to this user. It will also include any system accessibility services.
5216 *
5217 * @param userId which user to check for.
5218 * @return List of accessiblity service package names.
5219 * @hide
5220 */
5221 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005222 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005223 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005224 if (mService != null) {
5225 try {
5226 return mService.getPermittedAccessibilityServicesForUser(userId);
5227 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005228 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005229 }
5230 }
5231 return null;
5232 }
5233
5234 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005235 * Called by a profile or device owner to set the permitted input methods services. When set by
5236 * a device owner or profile owner the restriction applies to all profiles of the user the
5237 * device owner or profile owner is an admin for. By default the user can use any input method.
5238 * When zero or more packages have been added, input method that are not in the list and not
5239 * part of the system can not be enabled by the user. This method will fail if it is called for
5240 * a admin that is not for the foreground user or a profile of the foreground user.
5241 * <p>
5242 * Calling with a null value for the list disables the restriction so that all input methods can
5243 * be used, calling with an empty list disables all but the system's own input methods.
5244 * <p>
5245 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005246 *
5247 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5248 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005249 * @return true if setting the restriction succeeded. It will fail if there are one or more
5250 * non-system input methods currently enabled that are not in the packageNames list.
5251 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005252 */
Robin Lee25e26452015-06-02 09:56:29 -07005253 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005254 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005255 if (mService != null) {
5256 try {
5257 return mService.setPermittedInputMethods(admin, packageNames);
5258 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005259 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005260 }
5261 }
5262 return false;
5263 }
5264
5265
5266 /**
5267 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005268 * <p>
5269 * An empty list means no input methods except system input methods are allowed. Null means all
5270 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005271 *
5272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5273 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005274 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005275 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005276 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005277 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005278 if (mService != null) {
5279 try {
5280 return mService.getPermittedInputMethods(admin);
5281 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005282 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005283 }
5284 }
5285 return null;
5286 }
5287
5288 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005289 * Called by the system to check if a specific input method is disabled by admin.
5290 *
5291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5292 * @param packageName Input method package name that needs to be checked.
5293 * @param userHandle user id the admin is running as.
5294 * @return true if the input method is permitted, otherwise false.
5295 *
5296 * @hide
5297 */
5298 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5299 @NonNull String packageName, int userHandle) {
5300 if (mService != null) {
5301 try {
5302 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5303 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005304 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005305 }
5306 }
5307 return false;
5308 }
5309
5310 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005311 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005312 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005313 *
5314 * <p>Null means all input methods are allowed, if a non-null list is returned
5315 * it will contain the intersection of the permitted lists for any device or profile
5316 * owners that apply to this user. It will also include any system input methods.
5317 *
5318 * @return List of input method package names.
5319 * @hide
5320 */
5321 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005322 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005323 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005324 if (mService != null) {
5325 try {
5326 return mService.getPermittedInputMethodsForCurrentUser();
5327 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005328 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005329 }
5330 }
5331 return null;
5332 }
5333
5334 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005335 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5336 * currently installed it.
5337 *
5338 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5339 *
5340 * @return List of package names to keep cached.
5341 * @hide
5342 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005343 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005344 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005345 if (mService != null) {
5346 try {
5347 return mService.getKeepUninstalledPackages(admin);
5348 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005349 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005350 }
5351 }
5352 return null;
5353 }
5354
5355 /**
5356 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5357 * currently installed it.
5358 *
5359 * <p>Please note that setting this policy does not imply that specified apps will be
5360 * automatically pre-cached.</p>
5361 *
5362 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5363 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005364 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005365 * @hide
5366 */
5367 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5368 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005369 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005370 if (mService != null) {
5371 try {
5372 mService.setKeepUninstalledPackages(admin, packageNames);
5373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005374 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005375 }
5376 }
5377 }
5378
5379 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005380 * Called by a device owner to create a user with the specified name. The UserHandle returned
5381 * by this method should not be persisted as user handles are recycled as users are removed and
5382 * created. If you need to persist an identifier for this user, use
5383 * {@link UserManager#getSerialNumberForUser}.
5384 *
5385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5386 * @param name the user's name
5387 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005388 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5389 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005390 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005391 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005392 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005393 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005394 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005395 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005396 return null;
5397 }
5398
5399 /**
Jason Monk03978a42014-06-10 15:05:30 -04005400 * Called by a device owner to create a user with the specified name. The UserHandle returned
5401 * by this method should not be persisted as user handles are recycled as users are removed and
5402 * created. If you need to persist an identifier for this user, use
5403 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5404 * immediately.
5405 *
5406 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5407 * as registered as an active admin on the new user. The profile owner package will be
5408 * installed on the new user if it already is installed on the device.
5409 *
5410 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5411 * profileOwnerComponent when onEnable is called.
5412 *
5413 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5414 * @param name the user's name
5415 * @param ownerName the human readable name of the organisation associated with this DPM.
5416 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5417 * the user.
5418 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5419 * on the new user.
5420 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005421 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5422 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005423 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005424 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005425 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005426 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005427 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005428 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005429 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005430 return null;
5431 }
5432
5433 /**
phweissa92e1212016-01-25 17:14:10 +01005434 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005435 */
5436 public static final int SKIP_SETUP_WIZARD = 0x0001;
5437
5438 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005439 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5440 * ephemeral.
5441 * @hide
5442 */
5443 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5444
5445 /**
phweissa92e1212016-01-25 17:14:10 +01005446 * Called by a device owner to create a user with the specified name and a given component of
5447 * the calling package as profile owner. The UserHandle returned by this method should not be
5448 * persisted as user handles are recycled as users are removed and created. If you need to
5449 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5450 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005451 * <p>
5452 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5453 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5454 * be registered as an active admin on the new user. The profile owner package will be installed
5455 * on the new user.
5456 * <p>
5457 * If the adminExtras are not null, they will be stored on the device until the user is started
5458 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005459 *
5460 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5461 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005462 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005463 * same package as admin, otherwise no user is created and an
5464 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005465 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005466 * user.
phweissa92e1212016-01-25 17:14:10 +01005467 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005468 * @see UserHandle
5469 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5470 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005471 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005472 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005473 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5474 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005475 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5476 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005477 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005478 try {
phweissa92e1212016-01-25 17:14:10 +01005479 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005480 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005481 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005482 }
phweiss343fb332016-01-25 14:48:59 +01005483 }
5484
5485 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005486 * Called by a device owner to remove a user and all associated data. The primary user can not
5487 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005488 *
5489 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5490 * @param userHandle the user to remove.
5491 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005492 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005493 */
Robin Lee25e26452015-06-02 09:56:29 -07005494 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005495 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005496 try {
5497 return mService.removeUser(admin, userHandle);
5498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005499 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005500 }
5501 }
5502
5503 /**
Jason Monk582d9112014-07-09 19:57:08 -04005504 * Called by a device owner to switch the specified user to the foreground.
5505 *
5506 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5507 * @param userHandle the user to switch to; null will switch to primary.
5508 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005509 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005510 * @see Intent#ACTION_USER_FOREGROUND
5511 */
Robin Lee25e26452015-06-02 09:56:29 -07005512 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005513 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005514 try {
5515 return mService.switchUser(admin, userHandle);
5516 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005517 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005518 }
5519 }
5520
5521 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005522 * Retrieves the application restrictions for a given target application running in the calling
5523 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005524 * <p>
5525 * The caller must be a profile or device owner on that user, or the package allowed to manage
5526 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5527 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005528 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005529 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5530 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005531 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005532 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005533 * @param packageName The name of the package to fetch restricted settings of.
5534 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005535 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5536 * {@link Bundle} if no restrictions have been set.
5537 * @throws SecurityException if {@code admin} is not a device or profile owner.
Pavel Grafovd65799e2016-12-02 11:21:45 +00005538 * @see #setApplicationRestrictionsManagingPackage
Robin Lee66e5d962014-04-09 16:44:21 +01005539 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005540 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005541 public @NonNull Bundle getApplicationRestrictions(
5542 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005543 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005544 if (mService != null) {
5545 try {
5546 return mService.getApplicationRestrictions(admin, packageName);
5547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005548 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005549 }
5550 }
5551 return null;
5552 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005553
5554 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005555 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005556 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005557 * The calling device admin must be a profile or device owner; if it is not, a security
5558 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005559 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005560 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5561 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5562 * for the list of keys.
5563 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005564 */
Robin Lee25e26452015-06-02 09:56:29 -07005565 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005566 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005567 if (mService != null) {
5568 try {
5569 mService.setUserRestriction(admin, key, true);
5570 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005571 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005572 }
5573 }
5574 }
5575
5576 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005577 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005578 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005579 * The calling device admin must be a profile or device owner; if it is not, a security
5580 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005581 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5583 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5584 * for the list of keys.
5585 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005586 */
Robin Lee25e26452015-06-02 09:56:29 -07005587 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005588 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005589 if (mService != null) {
5590 try {
5591 mService.setUserRestriction(admin, key, false);
5592 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005593 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005594 }
5595 }
5596 }
Adam Connors010cfd42014-04-16 12:48:13 +01005597
5598 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005599 * Called by a profile or device owner to get user restrictions set with
5600 * {@link #addUserRestriction(ComponentName, String)}.
5601 * <p>
5602 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005603 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005604 * {@link UserManager#getUserRestrictions()}.
5605 *
5606 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005607 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005608 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005609 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005610 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005611 Bundle ret = null;
5612 if (mService != null) {
5613 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005614 ret = mService.getUserRestrictions(admin);
5615 } catch (RemoteException e) {
5616 throw e.rethrowFromSystemServer();
5617 }
5618 }
5619 return ret == null ? new Bundle() : ret;
5620 }
5621
5622 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005623 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5624 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005625 *
5626 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005627 * @param packageName The name of the package to hide or unhide.
5628 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005629 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005630 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005631 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005632 */
Robin Lee25e26452015-06-02 09:56:29 -07005633 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005634 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005635 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005636 if (mService != null) {
5637 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005638 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005639 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005640 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005641 }
5642 }
5643 return false;
5644 }
5645
5646 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005647 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005648 *
5649 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005650 * @param packageName The name of the package to retrieve the hidden status of.
5651 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005652 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005653 */
Robin Lee25e26452015-06-02 09:56:29 -07005654 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005655 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005656 if (mService != null) {
5657 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005658 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005659 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005660 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005661 }
5662 }
5663 return false;
5664 }
5665
5666 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005667 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005668 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005669 *
5670 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005671 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005672 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005673 */
Robin Lee25e26452015-06-02 09:56:29 -07005674 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005675 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005676 if (mService != null) {
5677 try {
5678 mService.enableSystemApp(admin, packageName);
5679 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005680 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005681 }
5682 }
5683 }
5684
5685 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005686 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5687 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005688 *
5689 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5690 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005691 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005692 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005693 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005694 */
Robin Lee25e26452015-06-02 09:56:29 -07005695 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005696 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005697 if (mService != null) {
5698 try {
5699 return mService.enableSystemAppWithIntent(admin, intent);
5700 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005701 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005702 }
5703 }
5704 return 0;
5705 }
5706
5707 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005708 * Called by a device owner or profile owner to disable account management for a specific type
5709 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005710 * <p>
5711 * The calling device admin must be a device owner or profile owner. If it is not, a security
5712 * exception will be thrown.
5713 * <p>
5714 * When account management is disabled for an account type, adding or removing an account of
5715 * that type will not be possible.
5716 * <p>
5717 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005718 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5719 * management for a specific type is disabled.
5720 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005721 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5722 * @param accountType For which account management is disabled or enabled.
5723 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005724 * enabled (false).
5725 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005726 */
Robin Lee25e26452015-06-02 09:56:29 -07005727 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005728 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005729 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005730 if (mService != null) {
5731 try {
5732 mService.setAccountManagementDisabled(admin, accountType, disabled);
5733 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005734 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005735 }
5736 }
5737 }
5738
5739 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005740 * Gets the array of accounts for which account management is disabled by the profile owner.
5741 *
5742 * <p> Account management can be disabled/enabled by calling
5743 * {@link #setAccountManagementDisabled}.
5744 *
5745 * @return a list of account types for which account management has been disabled.
5746 *
5747 * @see #setAccountManagementDisabled
5748 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005749 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005750 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005751 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005752 }
5753
5754 /**
5755 * @see #getAccountTypesWithManagementDisabled()
5756 * @hide
5757 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005758 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005759 if (mService != null) {
5760 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005761 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005762 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005763 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005764 }
5765 }
5766
5767 return null;
5768 }
justinzhang511e0d82014-03-24 16:09:24 -04005769
5770 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005771 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005772 * <p>
5773 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5774 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5775 * package list results in locked tasks belonging to those packages to be finished. This
5776 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005777 *
Jason Monkd7b86212014-06-16 13:15:38 -04005778 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005779 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005780 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005781 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005782 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5783 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005784 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005785 */
Robin Lee25e26452015-06-02 09:56:29 -07005786 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005787 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005788 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005789 if (mService != null) {
5790 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005791 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005792 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005793 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005794 }
5795 }
5796 }
5797
5798 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005799 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005800 *
5801 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005802 * @hide
5803 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005804 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005805 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005806 if (mService != null) {
5807 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005808 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005810 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005811 }
5812 }
5813 return null;
5814 }
5815
5816 /**
5817 * This function lets the caller know whether the given component is allowed to start the
5818 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005819 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005820 */
Jason Monkd7b86212014-06-16 13:15:38 -04005821 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005822 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005823 if (mService != null) {
5824 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005825 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005826 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005827 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005828 }
5829 }
5830 return false;
5831 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005832
5833 /**
5834 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5835 * 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 -07005836 * <p>
5837 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005838 * <ul>
5839 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5840 * <li>{@link Settings.Global#AUTO_TIME}</li>
5841 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005842 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005843 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005844 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005845 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5846 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5847 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5848 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5849 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005850 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005851 * <p>
5852 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005853 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005854 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5855 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5856 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005857 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005858 * <li>{@link Settings.Global#MODE_RINGER}. Use
5859 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005860 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005861 * <li>{@link Settings.Global#WIFI_ON}. Use
5862 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005863 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005864 *
5865 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5866 * @param setting The name of the setting to update.
5867 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005868 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005869 */
Robin Lee25e26452015-06-02 09:56:29 -07005870 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005871 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005872 if (mService != null) {
5873 try {
5874 mService.setGlobalSetting(admin, setting, value);
5875 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005876 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005877 }
5878 }
5879 }
5880
5881 /**
5882 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5883 * that the value of the setting is in the correct form for the setting type should be performed
5884 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005885 * <p>
5886 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005887 * <ul>
5888 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005889 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005890 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5891 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005892 * <p>
5893 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005894 * <ul>
5895 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5896 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005897 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005898 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5899 * @param setting The name of the setting to update.
5900 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005901 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005902 */
Robin Lee25e26452015-06-02 09:56:29 -07005903 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005904 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005905 if (mService != null) {
5906 try {
5907 mService.setSecureSetting(admin, setting, value);
5908 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005909 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005910 }
5911 }
5912 }
5913
Amith Yamasanif20d6402014-05-24 15:34:37 -07005914 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005915 * Designates a specific service component as the provider for making permission requests of a
5916 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005917 * <p/>
5918 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005919 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005920 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005921 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005922 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5923 * provider previously assigned.
5924 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005925 */
Robin Lee25e26452015-06-02 09:56:29 -07005926 public void setRestrictionsProvider(@NonNull ComponentName admin,
5927 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005928 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005929 if (mService != null) {
5930 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005931 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005932 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005933 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005934 }
5935 }
5936 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005937
5938 /**
5939 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005940 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005941 *
5942 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5943 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005944 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005945 */
Robin Lee25e26452015-06-02 09:56:29 -07005946 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005947 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005948 if (mService != null) {
5949 try {
5950 mService.setMasterVolumeMuted(admin, on);
5951 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005952 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005953 }
5954 }
5955 }
5956
5957 /**
5958 * Called by profile or device owners to check whether the master volume mute is on or off.
5959 *
5960 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5961 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005962 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005963 */
Robin Lee25e26452015-06-02 09:56:29 -07005964 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005965 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005966 if (mService != null) {
5967 try {
5968 return mService.isMasterVolumeMuted(admin);
5969 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005970 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005971 }
5972 }
5973 return false;
5974 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005975
5976 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005977 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005978 *
5979 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5980 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005981 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005982 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005983 */
Robin Lee25e26452015-06-02 09:56:29 -07005984 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005985 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005986 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005987 if (mService != null) {
5988 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005989 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005990 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005991 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005992 }
5993 }
5994 }
5995
5996 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005997 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005998 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005999 * <p>
6000 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006001 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
6002 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
6003 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01006004 *
Robin Lee25e26452015-06-02 09:56:29 -07006005 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006006 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01006007 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00006008 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006009 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01006010 */
Robin Lee25e26452015-06-02 09:56:29 -07006011 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006012 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01006013 if (mService != null) {
6014 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01006015 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01006016 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006017 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01006018 }
6019 }
6020 return false;
6021 }
Svetoslav976e8bd2014-07-16 15:12:03 -07006022
6023 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006024 * Called by the profile owner of a managed profile to enable widget providers from a given
6025 * package to be available in the parent profile. As a result the user will be able to add
6026 * widgets from the white-listed package running under the profile to a widget host which runs
6027 * under the parent profile, for example the home screen. Note that a package may have zero or
6028 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07006029 * <p>
6030 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006031 *
6032 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6033 * @param packageName The package from which widget providers are white-listed.
6034 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006035 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006036 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
6037 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6038 */
Robin Lee25e26452015-06-02 09:56:29 -07006039 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006040 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006041 if (mService != null) {
6042 try {
6043 return mService.addCrossProfileWidgetProvider(admin, packageName);
6044 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006045 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006046 }
6047 }
6048 return false;
6049 }
6050
6051 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006052 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006053 * package to be available in the parent profile. For this method to take effect the package
6054 * should have been added via
6055 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07006056 * <p>
6057 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006058 *
6059 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006060 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07006061 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006062 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006063 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6064 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
6065 */
Esteban Talavera62399912016-01-11 15:37:55 +00006066 public boolean removeCrossProfileWidgetProvider(
6067 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006068 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07006069 if (mService != null) {
6070 try {
6071 return mService.removeCrossProfileWidgetProvider(admin, packageName);
6072 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006073 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006074 }
6075 }
6076 return false;
6077 }
6078
6079 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07006080 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07006081 * available in the parent profile.
6082 *
6083 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6084 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07006085 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
6086 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006087 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07006088 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006089 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006090 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07006091 if (mService != null) {
6092 try {
6093 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
6094 if (providers != null) {
6095 return providers;
6096 }
6097 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006098 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07006099 }
6100 }
6101 return Collections.emptyList();
6102 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006103
6104 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08006105 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006106 *
6107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6108 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006109 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006110 */
Robin Lee25e26452015-06-02 09:56:29 -07006111 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006112 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006113 try {
6114 mService.setUserIcon(admin, icon);
6115 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006116 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05006117 }
6118 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04006119
6120 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006121 * Called by device owners to set a local system update policy. When a new policy is set,
6122 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006123 *
Robin Lee25e26452015-06-02 09:56:29 -07006124 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006125 * components in the device owner package can set system update policies and the most
6126 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07006127 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006128 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01006129 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00006130 */
Robin Lee25e26452015-06-02 09:56:29 -07006131 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006132 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006133 if (mService != null) {
6134 try {
Robin Lee25e26452015-06-02 09:56:29 -07006135 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00006136 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006137 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006138 }
6139 }
6140 }
6141
6142 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01006143 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006144 *
Robin Lee25e26452015-06-02 09:56:29 -07006145 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00006146 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006147 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006148 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00006149 if (mService != null) {
6150 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01006151 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006152 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006153 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00006154 }
6155 }
6156 return null;
6157 }
Benjamin Franze36087e2015-04-07 16:40:34 +01006158
6159 /**
6160 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006161 * <p>
6162 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
6163 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
6164 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
6165 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01006166 *
6167 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006168 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01006169 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006170 * place. {@code true} otherwise.
6171 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01006172 */
Robin Lee25e26452015-06-02 09:56:29 -07006173 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006174 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01006175 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006176 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01006177 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006178 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01006179 }
6180 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00006181
6182 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01006183 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006184 * notifications, quick settings and other screen overlays that allow escaping from a single use
6185 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006186 *
6187 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006188 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006189 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6190 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006191 */
Robin Lee25e26452015-06-02 09:56:29 -07006192 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006193 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006194 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006195 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006196 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006197 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006198 }
6199 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006200
6201 /**
Charles Hedea0c3b2017-01-13 10:04:12 +00006202 * Called by the system update service to notify device and profile owners of pending system
6203 * updates.
Rubin Xudc105cc2015-04-14 23:38:01 +01006204 *
Charles Hedea0c3b2017-01-13 10:04:12 +00006205 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6206 * permission. This method should only be used when it is unknown whether the pending system
6207 * update is a security patch. Otherwise, use
6208 * {@link #notifyPendingSystemUpdate(long, boolean)}.
6209 *
6210 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6211 * indicating when the current pending update was first available. {@code -1} if no
6212 * update is available.
6213 * @see #notifyPendingSystemUpdate(long, boolean)
Rubin Xudc105cc2015-04-14 23:38:01 +01006214 * @hide
6215 */
6216 @SystemApi
6217 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006218 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006219 if (mService != null) {
6220 try {
Charles Hedea0c3b2017-01-13 10:04:12 +00006221 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime));
6222 } catch (RemoteException re) {
6223 throw re.rethrowFromSystemServer();
6224 }
6225 }
6226 }
6227
6228 /**
6229 * Called by the system update service to notify device and profile owners of pending system
6230 * updates.
6231 *
6232 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6233 * permission. This method should be used instead of {@link #notifyPendingSystemUpdate(long)}
6234 * when it is known whether the pending system update is a security patch.
6235 *
6236 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()}
6237 * indicating when the current pending update was first available. {@code -1} if no
6238 * update is available.
6239 * @param isSecurityPatch {@code true} if this system update is purely a security patch;
6240 * {@code false} if not.
6241 * @see #notifyPendingSystemUpdate(long)
6242 * @hide
6243 */
6244 @SystemApi
6245 public void notifyPendingSystemUpdate(long updateReceivedTime, boolean isSecurityPatch) {
6246 throwIfParentInstance("notifyPendingSystemUpdate");
6247 if (mService != null) {
6248 try {
6249 mService.notifyPendingSystemUpdate(SystemUpdateInfo.of(updateReceivedTime,
6250 isSecurityPatch));
Rubin Xudc105cc2015-04-14 23:38:01 +01006251 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006252 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006253 }
6254 }
6255 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006256
6257 /**
Pavel Grafovd65799e2016-12-02 11:21:45 +00006258 * Called by device or profile owners to get information about a pending system update.
6259 *
6260 * @param admin Which profile or device owner this request is associated with.
6261 * @return Information about a pending system update or {@code null} if no update pending.
6262 * @throws SecurityException if {@code admin} is not a device or profile owner.
6263 * @see DeviceAdminReceiver#onSystemUpdatePending(Context, Intent, long)
6264 */
6265 public @Nullable SystemUpdateInfo getPendingSystemUpdate(@NonNull ComponentName admin) {
6266 throwIfParentInstance("getPendingSystemUpdate");
6267 try {
6268 return mService.getPendingSystemUpdate(admin);
6269 } catch (RemoteException re) {
6270 throw re.rethrowFromSystemServer();
6271 }
6272 }
6273
6274 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006275 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006276 * requests by applications. The policy can allow for normal operation which prompts the user to
6277 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6278 * by an application. This also applies to new permissions declared by app updates. When a
6279 * permission is denied or granted this way, the effect is equivalent to setting the permission
6280 * grant state via {@link #setPermissionGrantState}.
6281 * <p/>
6282 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006283 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006284 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006285 * @param admin Which profile or device owner this request is associated with.
6286 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006287 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6288 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006289 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006290 */
Robin Lee25e26452015-06-02 09:56:29 -07006291 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006292 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006293 try {
6294 mService.setPermissionPolicy(admin, policy);
6295 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006296 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006297 }
6298 }
6299
6300 /**
6301 * Returns the current runtime permission policy set by the device or profile owner. The
6302 * default is {@link #PERMISSION_POLICY_PROMPT}.
6303 * @param admin Which profile or device owner this request is associated with.
6304 * @return the current policy for future permission requests.
6305 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006306 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006307 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006308 try {
6309 return mService.getPermissionPolicy(admin);
6310 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006311 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006312 }
6313 }
6314
6315 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006316 * Sets the grant state of a runtime permission for a specific application. The state can be
6317 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6318 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6319 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6320 * the permission is granted and the user cannot manage it through the UI. This might affect all
6321 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006322 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006323 * <p/>
6324 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6325 * the permission. It retains the previous grant, if any.
6326 * <p/>
6327 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006328 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006329 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006330 * @param admin Which profile or device owner this request is associated with.
6331 * @param packageName The application to grant or revoke a permission to.
6332 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006333 * @param grantState The permission grant state which is one of
6334 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6335 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006336 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006337 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006338 * @see #PERMISSION_GRANT_STATE_DENIED
6339 * @see #PERMISSION_GRANT_STATE_DEFAULT
6340 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006341 */
Robin Lee25e26452015-06-02 09:56:29 -07006342 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006343 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006344 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006345 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006346 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006347 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006348 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006349 }
6350 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006351
6352 /**
6353 * Returns the current grant state of a runtime permission for a specific application.
6354 *
6355 * @param admin Which profile or device owner this request is associated with.
6356 * @param packageName The application to check the grant state for.
6357 * @param permission The permission to check for.
6358 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006359 * has not set a grant state, the return value is
6360 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6361 * permission is currently granted for the package.
6362 * <p/>
6363 * If a grant state was set by the profile or device owner, then the return value will
6364 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6365 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6366 * currently denied or granted.
6367 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006368 * @see #setPermissionGrantState(ComponentName, String, String, int)
6369 * @see PackageManager#checkPermission(String, String)
6370 */
Bartosz Fabianowski4b0624f2017-01-16 11:47:28 +01006371 public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006372 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006373 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006374 try {
6375 return mService.getPermissionGrantState(admin, packageName, permission);
6376 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006377 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006378 }
6379 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006380
6381 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006382 * Returns whether it is possible for the caller to initiate provisioning of a managed profile
6383 * or device, setting itself as the device or profile owner.
6384 *
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006385 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6386 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Esteban Talavera01576862016-12-15 11:16:44 +00006387 * @return whether provisioning a managed profile or device is possible.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006388 * @throws IllegalArgumentException if the supplied action is not valid.
6389 */
Esteban Talavera01576862016-12-15 11:16:44 +00006390 public boolean isProvisioningAllowed(@NonNull String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006391 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006392 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006393 return mService.isProvisioningAllowed(action, mContext.getPackageName());
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006394 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006395 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006396 }
6397 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006398
6399 /**
Esteban Talavera01576862016-12-15 11:16:44 +00006400 * Checks whether it is possible to initiate provisioning a managed device,
6401 * profile or user, setting the given package as owner.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006402 *
6403 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6404 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6405 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6406 * {@link #ACTION_PROVISION_MANAGED_USER}
Esteban Talavera01576862016-12-15 11:16:44 +00006407 * @param packageName The package of the component that would be set as device, user, or profile
6408 * owner.
6409 * @return A {@link ProvisioningPreCondition} value indicating whether provisioning is allowed.
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006410 * @hide
6411 */
Esteban Talavera01576862016-12-15 11:16:44 +00006412 public @ProvisioningPreCondition int checkProvisioningPreCondition(
6413 String action, @NonNull String packageName) {
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006414 try {
Esteban Talavera01576862016-12-15 11:16:44 +00006415 return mService.checkProvisioningPreCondition(action, packageName);
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006416 } catch (RemoteException re) {
6417 throw re.rethrowFromSystemServer();
6418 }
6419 }
6420
6421 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006422 * Return if this user is a managed profile of another user. An admin can become the profile
6423 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006424 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006425 * @param admin Which profile owner this request is associated with.
6426 * @return if this user is a managed profile of another user.
6427 */
6428 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006429 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006430 try {
6431 return mService.isManagedProfile(admin);
6432 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006433 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006434 }
6435 }
6436
6437 /**
6438 * @hide
6439 * Return if this user is a system-only user. An admin can manage a device from a system only
6440 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6441 * @param admin Which device owner this request is associated with.
6442 * @return if this user is a system-only user.
6443 */
6444 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6445 try {
6446 return mService.isSystemOnlyUser(admin);
6447 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006448 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006449 }
6450 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006451
6452 /**
6453 * Called by device owner to get the MAC address of the Wi-Fi device.
6454 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006455 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006456 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6457 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6458 * <p>
6459 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6460 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006461 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006462 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006463 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006464 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006465 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006466 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006467 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006468 }
6469 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006470
6471 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006472 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6473 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006474 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006475 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006476 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006477 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006478 */
6479 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006480 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006481 try {
6482 mService.reboot(admin);
6483 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006484 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006485 }
6486 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006487
6488 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006489 * Called by a device admin to set the short support message. This will be displayed to the user
6490 * in settings screens where funtionality has been disabled by the admin. The message should be
6491 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6492 * someone@example.com for support." If the message is longer than 200 characters it may be
6493 * truncated.
6494 * <p>
6495 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006496 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6497 * and set a new version of this string accordingly.
6498 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006499 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006501 * @param message Short message to be displayed to the user in settings or null to clear the
6502 * existing message.
6503 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006504 */
6505 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006506 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006507 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006508 if (mService != null) {
6509 try {
6510 mService.setShortSupportMessage(admin, message);
6511 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006512 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006513 }
6514 }
6515 }
6516
6517 /**
6518 * Called by a device admin to get the short support message.
6519 *
6520 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006521 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6522 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006523 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006524 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006525 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006526 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006527 if (mService != null) {
6528 try {
6529 return mService.getShortSupportMessage(admin);
6530 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006531 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006532 }
6533 }
6534 return null;
6535 }
6536
6537 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006538 * Called by a device admin to set the long support message. This will be displayed to the user
6539 * in the device administators settings screen.
6540 * <p>
6541 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006542 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6543 * and set a new version of this string accordingly.
6544 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006545 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006546 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006547 * @param message Long message to be displayed to the user in settings or null to clear the
6548 * existing message.
6549 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006550 */
6551 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006552 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006553 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006554 if (mService != null) {
6555 try {
6556 mService.setLongSupportMessage(admin, message);
6557 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006558 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006559 }
6560 }
6561 }
6562
6563 /**
6564 * Called by a device admin to get the long support message.
6565 *
6566 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006567 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6568 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006569 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006570 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006571 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006572 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006573 if (mService != null) {
6574 try {
6575 return mService.getLongSupportMessage(admin);
6576 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006577 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006578 }
6579 }
6580 return null;
6581 }
6582
6583 /**
6584 * Called by the system to get the short support message.
6585 *
6586 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6587 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006588 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006589 *
6590 * @hide
6591 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006592 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006593 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006594 if (mService != null) {
6595 try {
6596 return mService.getShortSupportMessageForUser(admin, userHandle);
6597 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006598 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006599 }
6600 }
6601 return null;
6602 }
6603
6604
6605 /**
6606 * Called by the system to get the long support message.
6607 *
6608 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6609 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006610 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006611 *
6612 * @hide
6613 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006614 public @Nullable CharSequence getLongSupportMessageForUser(
6615 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006616 if (mService != null) {
6617 try {
6618 return mService.getLongSupportMessageForUser(admin, userHandle);
6619 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006620 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006621 }
6622 }
6623 return null;
6624 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006625
6626 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006627 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6628 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006629 *
6630 * <p>The following methods are supported for the parent instance, all other methods will
6631 * throw a SecurityException when called on the parent instance:
6632 * <ul>
6633 * <li>{@link #getPasswordQuality}</li>
6634 * <li>{@link #setPasswordQuality}</li>
6635 * <li>{@link #getPasswordMinimumLength}</li>
6636 * <li>{@link #setPasswordMinimumLength}</li>
6637 * <li>{@link #getPasswordMinimumUpperCase}</li>
6638 * <li>{@link #setPasswordMinimumUpperCase}</li>
6639 * <li>{@link #getPasswordMinimumLowerCase}</li>
6640 * <li>{@link #setPasswordMinimumLowerCase}</li>
6641 * <li>{@link #getPasswordMinimumLetters}</li>
6642 * <li>{@link #setPasswordMinimumLetters}</li>
6643 * <li>{@link #getPasswordMinimumNumeric}</li>
6644 * <li>{@link #setPasswordMinimumNumeric}</li>
6645 * <li>{@link #getPasswordMinimumSymbols}</li>
6646 * <li>{@link #setPasswordMinimumSymbols}</li>
6647 * <li>{@link #getPasswordMinimumNonLetter}</li>
6648 * <li>{@link #setPasswordMinimumNonLetter}</li>
6649 * <li>{@link #getPasswordHistoryLength}</li>
6650 * <li>{@link #setPasswordHistoryLength}</li>
6651 * <li>{@link #getPasswordExpirationTimeout}</li>
6652 * <li>{@link #setPasswordExpirationTimeout}</li>
6653 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006654 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006655 * <li>{@link #isActivePasswordSufficient}</li>
6656 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6657 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6658 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6659 * <li>{@link #getMaximumTimeToLock}</li>
6660 * <li>{@link #setMaximumTimeToLock}</li>
6661 * <li>{@link #lockNow}</li>
6662 * <li>{@link #getKeyguardDisabledFeatures}</li>
6663 * <li>{@link #setKeyguardDisabledFeatures}</li>
6664 * <li>{@link #getTrustAgentConfiguration}</li>
6665 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006666 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6667 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006668 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006669 *
6670 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006671 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006672 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006673 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006674 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006675 try {
6676 if (!mService.isManagedProfile(admin)) {
6677 throw new SecurityException("The current user does not have a parent profile.");
6678 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006679 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006681 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006682 }
6683 }
6684
6685 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00006686 * Called by device owner to control the security logging feature.
Michal Karpinski6235a942016-03-15 12:07:23 +00006687 *
6688 * <p> Security logs contain various information intended for security auditing purposes.
6689 * See {@link SecurityEvent} for details.
6690 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006691 * <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
6692 * are unaffiliated secondary users or profiles on the device, regardless of whether the
6693 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
6694 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
6695 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006696 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006697 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006698 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006699 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006700 * @see #retrieveSecurityLogs
6701 */
6702 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006703 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006704 try {
6705 mService.setSecurityLoggingEnabled(admin, enabled);
6706 } catch (RemoteException re) {
6707 throw re.rethrowFromSystemServer();
6708 }
6709 }
6710
6711 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006712 * Return whether security logging is enabled or not by the device owner.
6713 *
6714 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6715 * thrown.
6716 *
6717 * @param admin Which device owner this request is associated with.
6718 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6719 * @throws SecurityException if {@code admin} is not a device owner.
6720 */
6721 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006722 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006723 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006724 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006725 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006726 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006727 }
6728 }
6729
6730 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006731 * Called by device owner to retrieve all new security logging entries since the last call to
6732 * this API after device boots.
6733 *
6734 * <p> Access to the logs is rate limited and it will only return new logs after the device
6735 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6736 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00006737 * <p>If there is any other user or profile on the device, it must be affiliated with the
6738 * device owner. Otherwise a {@link SecurityException} will be thrown. See
6739 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00006740 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006741 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006742 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6743 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00006744 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
6745 * profile or secondary user that is not affiliated with the device owner user.
6746 * @see DeviceAdminReceiver#onSecurityLogsAvailable
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006747 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006748 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006749 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006750 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006751 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006752 if (list != null) {
6753 return list.getList();
6754 } else {
6755 // Rate limit exceeded.
6756 return null;
6757 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006758 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006759 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006760 }
6761 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006762
6763 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006764 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6765 * profile.
6766 *
6767 * @hide
6768 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006769 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006770 mContext.checkSelfPermission(
6771 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6772 if (!uInfo.isManagedProfile()) {
6773 throw new SecurityException("The user " + uInfo.id
6774 + " does not have a parent profile.");
6775 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006776 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006777 }
6778
6779 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006780 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006781 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006782 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6783 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6784 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6785 * about data corruption when parsing. </strong>
Esteban Talaverad36dd152016-12-15 08:51:45 +00006786 *
6787 * <p>If there is any other user or profile on the device, it must be affiliated with the
6788 * device owner. Otherwise a {@link SecurityException} will be thrown. See
6789 * {@link #setAffiliationIds}
Michal Karpinskib58e4962016-03-01 14:55:10 +00006790 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006791 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006792 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6793 * is not supported on the device.
Esteban Talaverad36dd152016-12-15 08:51:45 +00006794 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
6795 * profile or secondary user that is not affiliated with the device owner user.
6796 * @see #retrieveSecurityLogs
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006797 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006798 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6799 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006800 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006801 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006802 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006803 if (list != null) {
6804 return list.getList();
6805 } else {
6806 return null;
6807 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006808 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006809 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006810 }
6811 }
6812
6813 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006814 * Called by a profile owner of a managed profile to set the color used for customization. This
6815 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006816 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006817 * <p>
6818 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006819 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6820 *
6821 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006822 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006823 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006824 */
6825 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006826 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006827 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006828 // always enforce alpha channel to have 100% opacity
6829 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006830 mService.setOrganizationColor(admin, color);
6831 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006832 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006833 }
6834 }
6835
6836 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006837 * @hide
6838 *
6839 * Sets the color used for customization.
6840 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006841 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006842 * @param userId which user to set the color to.
6843 * @RequiresPermission(allOf = {
6844 * Manifest.permission.MANAGE_USERS,
6845 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6846 */
6847 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6848 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006849 // always enforce alpha channel to have 100% opacity
6850 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006851 mService.setOrganizationColorForUser(color, userId);
6852 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006853 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006854 }
6855 }
6856
6857 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006858 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6859 * This color is used as background color of the confirm credentials screen for that user.
6860 *
6861 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006862 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006863 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006864 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006865 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006866 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006867 try {
6868 return mService.getOrganizationColor(admin);
6869 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006870 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006871 }
6872 }
6873
6874 /**
6875 * @hide
6876 * Retrieve the customization color for a given user.
6877 *
6878 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006879 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006880 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006881 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006882 try {
6883 return mService.getOrganizationColorForUser(userHandle);
6884 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006885 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006886 }
6887 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006888
6889 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006890 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006891 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006892 * <p>
6893 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006894 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6895 * and set a new version of this string accordingly.
6896 *
6897 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6898 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006899 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006900 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006901 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006902 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006903 try {
6904 mService.setOrganizationName(admin, title);
6905 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006906 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006907 }
6908 }
6909
6910 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006911 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6912 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006913 *
6914 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6915 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006916 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006917 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006918 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006919 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006920 try {
6921 return mService.getOrganizationName(admin);
6922 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006923 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006924 }
6925 }
6926
6927 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006928 * Called by the system to retrieve the name of the organization managing the device.
6929 *
6930 * @return The organization name or {@code null} if none is set.
6931 * @throws SecurityException if the caller is not the device owner, does not hold the
6932 * MANAGE_USERS permission and is not the system.
6933 *
6934 * @hide
6935 */
6936 @SystemApi
6937 @TestApi
6938 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6939 try {
6940 return mService.getDeviceOwnerOrganizationName();
6941 } catch (RemoteException re) {
6942 throw re.rethrowFromSystemServer();
6943 }
6944 }
6945
6946 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006947 * Retrieve the default title message used in the confirm credentials screen for a given user.
6948 *
6949 * @param userHandle The user id of the user we're interested in.
6950 * @return The organization name or {@code null} if none is set.
6951 *
6952 * @hide
6953 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006954 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006955 try {
6956 return mService.getOrganizationNameForUser(userHandle);
6957 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006958 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006959 }
6960 }
6961
6962 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006963 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6964 * return {@link #STATE_USER_UNMANAGED}
6965 * @hide
6966 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006967 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006968 @UserProvisioningState
6969 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006970 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006971 if (mService != null) {
6972 try {
6973 return mService.getUserProvisioningState();
6974 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006975 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006976 }
6977 }
6978 return STATE_USER_UNMANAGED;
6979 }
6980
6981 /**
6982 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6983 *
6984 * @param state to store
6985 * @param userHandle for user
6986 * @hide
6987 */
6988 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6989 if (mService != null) {
6990 try {
6991 mService.setUserProvisioningState(state, userHandle);
6992 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006993 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006994 }
6995 }
6996 }
6997
6998 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006999 * Indicates the entity that controls the device or profile owner. Two users/profiles are
7000 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007001 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007002 * <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
7003 * or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
7004 * is created, until it becomes affiliated. Therefore it is recommended that the appropriate
7005 * affiliation ids are set by its profile owner as soon as possible after the user/profile is
7006 * created.
7007 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007008 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007009 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
7010 *
7011 * @throws NullPointerException if {@code ids} is null or contains null elements.
7012 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007013 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007014 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007015 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007016 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007017 mService.setAffiliationIds(admin, ids);
7018 } catch (RemoteException e) {
7019 throw e.rethrowFromSystemServer();
7020 }
7021 }
7022
7023 /**
7024 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
7025 * empty list if none have been set.
7026 */
7027 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
7028 throwIfParentInstance("getAffiliationIds");
7029 try {
7030 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007031 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007032 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007033 }
7034 }
7035
7036 /**
7037 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007038 * Returns whether this user/profile is affiliated with the device.
7039 * <p>
7040 * By definition, the user that the device owner runs on is always affiliated with the device.
7041 * Any other user/profile is considered affiliated with the device if the set specified by its
7042 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007043 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007044 */
7045 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01007046 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007047 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00007048 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007049 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007050 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01007051 }
7052 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007053
7054 /**
7055 * @hide
7056 * Returns whether the uninstall for {@code packageName} for the current user is in queue
7057 * to be started
7058 * @param packageName the package to check for
7059 * @return whether the uninstall intent for {@code packageName} is pending
7060 */
7061 public boolean isUninstallInQueue(String packageName) {
7062 try {
7063 return mService.isUninstallInQueue(packageName);
7064 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007065 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007066 }
7067 }
7068
7069 /**
7070 * @hide
7071 * @param packageName the package containing active DAs to be uninstalled
7072 */
7073 public void uninstallPackageWithActiveAdmins(String packageName) {
7074 try {
7075 mService.uninstallPackageWithActiveAdmins(packageName);
7076 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07007077 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08007078 }
7079 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01007080
Kenny Guy38dcca52016-04-19 13:09:18 +01007081 /**
7082 * @hide
7083 * Remove a test admin synchronously without sending it a broadcast about being removed.
7084 * If the admin is a profile owner or device owner it will still be removed.
7085 *
7086 * @param userHandle user id to remove the admin for.
7087 * @param admin The administration compononent to remove.
7088 * @throws SecurityException if the caller is not shell / root or the admin package
7089 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
7090 */
7091 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
7092 try {
7093 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
7094 } catch (RemoteException re) {
7095 throw re.rethrowFromSystemServer();
7096 }
7097 }
7098
Mahaver Chopra790d1982016-07-07 16:06:49 +01007099 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007100 * Returns whether the device has been provisioned.
7101 *
7102 * <p>Not for use by third-party applications.
7103 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01007104 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01007105 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007106 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01007107 public boolean isDeviceProvisioned() {
7108 try {
7109 return mService.isDeviceProvisioned();
7110 } catch (RemoteException re) {
7111 throw re.rethrowFromSystemServer();
7112 }
7113 }
7114
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007115 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007116 * Writes that the provisioning configuration has been applied.
7117 *
7118 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
7119 * permission.
7120 *
7121 * <p>Not for use by third-party applications.
7122 *
7123 * @hide
7124 */
7125 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007126 public void setDeviceProvisioningConfigApplied() {
7127 try {
7128 mService.setDeviceProvisioningConfigApplied();
7129 } catch (RemoteException re) {
7130 throw re.rethrowFromSystemServer();
7131 }
7132 }
7133
7134 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007135 * Returns whether the provisioning configuration has been applied.
7136 *
7137 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
7138 *
7139 * <p>Not for use by third-party applications.
7140 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007141 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007142 *
7143 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007144 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01007145 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01007146 public boolean isDeviceProvisioningConfigApplied() {
7147 try {
7148 return mService.isDeviceProvisioningConfigApplied();
7149 } catch (RemoteException re) {
7150 throw re.rethrowFromSystemServer();
7151 }
7152 }
7153
Victor Chang9bfc65f2016-08-15 12:27:09 +01007154 /**
7155 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01007156 * Force update user setup completed status. This API has no effect on user build.
7157 * @throws {@link SecurityException} if the caller has no
Esteban Talavera01576862016-12-15 11:16:44 +00007158 * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
7159 * not {@link UserHandle#SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01007160 */
7161 public void forceUpdateUserSetupComplete() {
7162 try {
7163 mService.forceUpdateUserSetupComplete();
7164 } catch (RemoteException re) {
7165 throw re.rethrowFromSystemServer();
7166 }
7167 }
7168
Benjamin Franzbc33c822016-04-15 08:57:52 +01007169 private void throwIfParentInstance(String functionName) {
7170 if (mParentInstance) {
7171 throw new SecurityException(functionName + " cannot be called on the parent instance");
7172 }
7173 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007174
7175 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007176 * Allows the device owner to enable or disable the backup service.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007177 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007178 * <p> Backup service manages all backup and restore mechanisms on the device. Setting this to
7179 * false will prevent data from being backed up or restored.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007180 *
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007181 * <p> Backup service is off by default when device owner is present.
7182 *
7183 * @throws SecurityException if {@code admin} is not a device owner.
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007184 */
7185 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
7186 try {
7187 mService.setBackupServiceEnabled(admin, enabled);
7188 } catch (RemoteException re) {
7189 throw re.rethrowFromSystemServer();
7190 }
7191 }
7192
7193 /**
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007194 * Return whether the backup service is enabled by the device owner.
7195 *
7196 * <p> Backup service manages all backup and restore mechanisms on the device.
7197 *
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007198 * @return {@code true} if backup service is enabled, {@code false} otherwise.
Michal Karpinskib71fedc2017-01-05 15:21:38 +00007199 * @see #setBackupServiceEnabled
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02007200 */
7201 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
7202 try {
7203 return mService.isBackupServiceEnabled(admin);
7204 } catch (RemoteException re) {
7205 throw re.rethrowFromSystemServer();
7206 }
7207 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007208
7209 /**
Esteban Talaverad36dd152016-12-15 08:51:45 +00007210 * Called by a device owner to control the network logging feature.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007211 *
7212 * <p> Network logs contain DNS lookup and connect() library call events.
7213 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007214 * <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
7215 * are unaffiliated secondary users or profiles on the device, regardless of whether the
7216 * feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
7217 * all users to become affiliated. Therefore it's recommended that affiliation ids are set for
7218 * new users as soon as possible after provisioning via {@link #setAffiliationIds}.
7219 *
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007220 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7221 * @param enabled whether network logging should be enabled or not.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007222 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007223 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007224 */
7225 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
7226 throwIfParentInstance("setNetworkLoggingEnabled");
7227 try {
7228 mService.setNetworkLoggingEnabled(admin, enabled);
7229 } catch (RemoteException re) {
7230 throw re.rethrowFromSystemServer();
7231 }
7232 }
7233
7234 /**
7235 * Return whether network logging is enabled by a device owner.
7236 *
phweissa4e169e2016-11-24 16:20:57 +01007237 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
7238 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007239 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007240 * @throws SecurityException if {@code admin} is not a device owner and caller has
phweissa4e169e2016-11-24 16:20:57 +01007241 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007242 */
phweissa4e169e2016-11-24 16:20:57 +01007243 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01007244 throwIfParentInstance("isNetworkLoggingEnabled");
7245 try {
7246 return mService.isNetworkLoggingEnabled(admin);
7247 } catch (RemoteException re) {
7248 throw re.rethrowFromSystemServer();
7249 }
7250 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007251
7252 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007253 * Called by device owner to retrieve the most recent batch of network logging events.
7254 * A device owner has to provide a batchToken provided as part of
7255 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
7256 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007257 *
7258 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
7259 *
7260 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
7261 *
7262 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7263 * after the device device owner has been notified via
7264 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7265 *
Esteban Talaverad36dd152016-12-15 08:51:45 +00007266 * <p>If a secondary user or profile is created, calling this method will throw a
7267 * {@link SecurityException} until all users become affiliated again. It will also no longer be
7268 * possible to retrieve the network logs batch with the most recent batchToken provided
7269 * by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
7270 * {@link DevicePolicyManager#setAffiliationIds}.
7271 *
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007272 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007273 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007274 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007275 * {@code null} if the batch represented by batchToken is no longer available or if
7276 * logging is disabled.
Esteban Talaverad36dd152016-12-15 08:51:45 +00007277 * @throws SecurityException if {@code admin} is not a device owner, or there is at least one
7278 * profile or secondary user that is not affiliated with the device owner user.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007279 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007280 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007281 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7282 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007283 throwIfParentInstance("retrieveNetworkLogs");
7284 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007285 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007286 } catch (RemoteException re) {
7287 throw re.rethrowFromSystemServer();
7288 }
7289 }
Tony Mak46aabe52016-11-14 12:53:06 +00007290
7291 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007292 * Called by a device owner to bind to a service from a profile owner of a managed profile or
7293 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
7294 * device/profile owners are allowed to bind to services of another profile/device owner.
7295 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007296 * The service must be unexported. Note that the {@link Context} used to obtain this
7297 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7298 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007299 *
Tony Mak46aabe52016-11-14 12:53:06 +00007300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7301 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7302 * explicit component name or a package name to match an
7303 * {@link IntentFilter} published by a service.
Tony Makbf9928d2016-12-22 11:02:45 +00007304 * @param conn Receives information as the service is started and stopped in main thread. This
7305 * must be a valid {@link ServiceConnection} object; it must not be {@code null}.
Tony Mak46aabe52016-11-14 12:53:06 +00007306 * @param flags Operation options for the binding operation. See
7307 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007308 * @param targetUser Which user to bind to. Must be one of the users returned by
7309 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7310 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007311 * @return If you have successfully bound to the service, {@code true} is returned;
7312 * {@code false} is returned if the connection is not made and you will not
7313 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007314 *
Tony Mak46aabe52016-11-14 12:53:06 +00007315 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007316 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007317 */
7318 public boolean bindDeviceAdminServiceAsUser(
7319 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7320 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7321 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7322 // Keep this in sync with ContextImpl.bindServiceCommon.
7323 try {
Tony Makbf9928d2016-12-22 11:02:45 +00007324 final IServiceConnection sd = mContext.getServiceDispatcher(
7325 conn, mContext.getMainThreadHandler(), flags);
Tony Mak46aabe52016-11-14 12:53:06 +00007326 serviceIntent.prepareToLeaveProcess(mContext);
7327 return mService.bindDeviceAdminServiceAsUser(admin,
7328 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7329 sd, flags, targetUser.getIdentifier());
7330 } catch (RemoteException re) {
7331 throw re.rethrowFromSystemServer();
7332 }
7333 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007334
7335 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007336 * Returns the list of target users that the calling device or profile owner can use when
7337 * calling {@link #bindDeviceAdminServiceAsUser}.
7338 * <p>
7339 * A device owner can bind to a service from a profile owner of a managed profile and
7340 * vice versa, provided that:
7341 * <ul>
7342 * <li>Both belong to the same package name.
7343 * <li>The managed profile is a profile of the user where the device owner is set.
7344 * See {@link UserManager#getUserProfiles()}
7345 * <li>Both users are affiliated.
Nicolas Prevotd5b03602016-12-06 13:32:22 +00007346 * See {@link #setAffiliationIds}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007347 * </ul>
7348 */
7349 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7350 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7351 try {
7352 return mService.getBindDeviceAdminTargetUsers(admin);
7353 } catch (RemoteException re) {
7354 throw re.rethrowFromSystemServer();
7355 }
7356 }
7357
7358 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007359 * Called by the system to get the time at which the device owner last retrieved security
7360 * logging entries.
7361 *
7362 * @return the time at which the device owner most recently retrieved security logging entries,
7363 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007364 * @throws SecurityException if the caller is not the device owner, does not hold the
7365 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007366 *
7367 * @hide
7368 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007369 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007370 public long getLastSecurityLogRetrievalTime() {
7371 try {
7372 return mService.getLastSecurityLogRetrievalTime();
7373 } catch (RemoteException re) {
7374 throw re.rethrowFromSystemServer();
7375 }
7376 }
7377
7378 /**
7379 * Called by the system to get the time at which the device owner last requested a bug report.
7380 *
7381 * @return the time at which the device owner most recently requested a bug report, in
7382 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007383 * @throws SecurityException if the caller is not the device owner, does not hold the
7384 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007385 *
7386 * @hide
7387 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007388 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007389 public long getLastBugReportRequestTime() {
7390 try {
7391 return mService.getLastBugReportRequestTime();
7392 } catch (RemoteException re) {
7393 throw re.rethrowFromSystemServer();
7394 }
7395 }
7396
7397 /**
7398 * Called by the system to get the time at which the device owner last retrieved network logging
7399 * events.
7400 *
7401 * @return the time at which the device owner most recently retrieved network logging events, in
7402 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007403 * @throws SecurityException if the caller is not the device owner, does not hold the
7404 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007405 *
7406 * @hide
7407 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007408 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007409 public long getLastNetworkLogRetrievalTime() {
7410 try {
7411 return mService.getLastNetworkLogRetrievalTime();
7412 } catch (RemoteException re) {
7413 throw re.rethrowFromSystemServer();
7414 }
7415 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007416}