blob: b1e51fbc82a6ed08f81e0a6af90fbb354c62a5d9 [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;
Tony Mak46aabe52016-11-14 12:53:06 +000023import android.annotation.RequiresPermission;
Dianne Hackbornd6847842010-01-12 18:14:19 -080024import android.annotation.SdkConstant;
25import android.annotation.SdkConstant.SdkConstantType;
Justin Moreyb5deda72014-07-24 10:53:40 -050026import android.annotation.SystemApi;
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +010027import android.annotation.TestApi;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +000028import android.annotation.UserIdInt;
Fyodor Kupolov4e9af062016-07-18 16:59:11 -070029import android.annotation.WorkerThread;
Jason Monkd7b86212014-06-16 13:15:38 -040030import android.app.Activity;
Andrew Scull5f9e6f32016-08-02 14:22:17 +010031import android.app.admin.PasswordMetrics;
Tony Mak46aabe52016-11-14 12:53:06 +000032import android.app.IServiceConnection;
Michal Karpinski6235a942016-03-15 12:07:23 +000033import android.app.admin.SecurityLog.SecurityEvent;
Dianne Hackbornd6847842010-01-12 18:14:19 -080034import android.content.ComponentName;
35import android.content.Context;
Adam Connors010cfd42014-04-16 12:48:13 +010036import android.content.Intent;
Sander Alewijnsef475ca32014-02-17 15:13:58 +000037import android.content.IntentFilter;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.content.ServiceConnection;
Dianne Hackbornd6847842010-01-12 18:14:19 -080039import android.content.pm.PackageManager;
Victor Changcd14c0a2016-03-16 19:10:15 +000040import android.content.pm.PackageManager.NameNotFoundException;
Rubin Xuc3cd05f2016-01-11 12:11:35 +000041import android.content.pm.ParceledListSlice;
Sudheer Shanka978fc0d2016-01-28 13:51:10 +000042import android.content.pm.UserInfo;
Julia Reynoldsfca04ca2015-02-17 13:39:12 -050043import android.graphics.Bitmap;
Jason Monk03bc9912014-05-13 09:44:57 -040044import android.net.ProxyInfo;
Nicolas Prevot8b7991c2015-11-12 17:40:12 +000045import android.net.Uri;
Robin Lee66e5d962014-04-09 16:44:21 +010046import android.os.Bundle;
Jim Millere303bf42014-08-26 17:12:29 -070047import android.os.PersistableBundle;
Adam Connors776c5552014-01-09 10:42:56 +000048import android.os.Process;
Dianne Hackborn8ea138c2010-01-26 18:01:04 -080049import android.os.RemoteCallback;
Dianne Hackbornd6847842010-01-12 18:14:19 -080050import android.os.RemoteException;
Amith Yamasani599dd7c2012-09-14 23:20:08 -070051import android.os.UserHandle;
Julia Reynolds1e958392014-05-16 14:25:21 -040052import android.os.UserManager;
Ricky Wai494b95d2015-11-20 16:07:15 +000053import android.provider.ContactsContract.Directory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000054import android.provider.Settings;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010055import android.security.Credentials;
Amith Yamasanid1d7c022014-08-19 17:03:41 -070056import android.service.restrictions.RestrictionsReceiver;
Mahaver Chopra1216ae52016-03-11 15:39:48 +000057import android.telephony.TelephonyManager;
Dianne Hackbornd6847842010-01-12 18:14:19 -080058import android.util.Log;
59
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070060import com.android.internal.annotations.VisibleForTesting;
Maggie Benthallda51e682013-08-08 22:35:44 -040061import com.android.org.conscrypt.TrustedCertificateStore;
62
63import java.io.ByteArrayInputStream;
Dianne Hackbornd6847842010-01-12 18:14:19 -080064import java.io.IOException;
Alan Treadwayafad8782016-01-19 15:15:08 +000065import java.lang.annotation.Retention;
66import java.lang.annotation.RetentionPolicy;
Oscar Montemayor69238c62010-08-03 10:51:06 -070067import java.net.InetSocketAddress;
68import java.net.Proxy;
Robin Lee0d5ccb72014-09-12 17:41:44 +010069import java.security.KeyFactory;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000070import java.security.NoSuchAlgorithmException;
Bernhard Bauer26408cc2014-09-08 14:07:31 +010071import java.security.PrivateKey;
72import java.security.cert.Certificate;
Maggie Benthallda51e682013-08-08 22:35:44 -040073import java.security.cert.CertificateException;
74import java.security.cert.CertificateFactory;
75import java.security.cert.X509Certificate;
Robin Lee0d5ccb72014-09-12 17:41:44 +010076import java.security.spec.InvalidKeySpecException;
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +000077import java.security.spec.PKCS8EncodedKeySpec;
Jim Miller604e7552014-07-18 19:00:02 -070078import java.util.ArrayList;
Rubin Xub4365912016-03-23 12:13:22 +000079import java.util.Arrays;
Svetoslav976e8bd2014-07-16 15:12:03 -070080import java.util.Collections;
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -080081import java.util.List;
Dianne Hackbornd6847842010-01-12 18:14:19 -080082
83/**
Alexandra Gherghina541afcd2014-11-07 11:18:12 +000084 * Public interface for managing policies enforced on a device. Most clients of this class must be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070085 * registered with the system as a <a href="{@docRoot}guide/topics/admin/device-admin.html">device
86 * administrator</a>. Additionally, a device administrator may be registered as either a profile or
87 * device owner. A given method is accessible to all device administrators unless the documentation
88 * for that method specifies that it is restricted to either device or profile owners. Any
89 * application calling an api may only pass as an argument a device administrator component it
90 * owns. Otherwise, a {@link SecurityException} will be thrown.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080091 * <div class="special reference">
92 * <h3>Developer Guides</h3>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -070093 * <p>
94 * For more information about managing policies for device administration, read the <a href=
95 * "{@docRoot}guide/topics/admin/device-admin.html">Device Administration</a> developer
96 * guide. </div>
Dianne Hackbornd6847842010-01-12 18:14:19 -080097 */
98public class DevicePolicyManager {
99 private static String TAG = "DevicePolicyManager";
Dianne Hackbornd6847842010-01-12 18:14:19 -0800100
101 private final Context mContext;
Dianne Hackbornd6847842010-01-12 18:14:19 -0800102 private final IDevicePolicyManager mService;
Esteban Talavera62399912016-01-11 15:37:55 +0000103 private final boolean mParentInstance;
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700104
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600105 /** @hide */
106 public DevicePolicyManager(Context context, IDevicePolicyManager service) {
107 this(context, service, false);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800108 }
109
Dianne Hackborn87bba1e2010-02-26 17:25:54 -0800110 /** @hide */
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700111 @VisibleForTesting
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600112 protected DevicePolicyManager(Context context, IDevicePolicyManager service,
113 boolean parentInstance) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700114 mContext = context;
115 mService = service;
Esteban Talavera62399912016-01-11 15:37:55 +0000116 mParentInstance = parentInstance;
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700117 }
118
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700119 /** @hide test will override it. */
120 @VisibleForTesting
121 protected int myUserId() {
122 return UserHandle.myUserId();
123 }
124
Dianne Hackbornd6847842010-01-12 18:14:19 -0800125 /**
Jessica Hummelf72078b2014-03-06 16:13:12 +0000126 * Activity action: Starts the provisioning flow which sets up a managed profile.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000127 *
Jessica Hummel9da60392014-05-21 12:32:57 +0100128 * <p>A managed profile allows data separation for example for the usage of a
129 * device as a personal and corporate device. The user which provisioning is started from and
130 * the managed profile share a launcher.
131 *
Andrew Solovay27f53372015-03-02 16:37:59 -0800132 * <p>This intent will typically be sent by a mobile device management application (MDM).
133 * Provisioning adds a managed profile and sets the MDM as the profile owner who has full
134 * control over the profile.
Jessica Hummel9da60392014-05-21 12:32:57 +0100135 *
Alan Treadway46dd4492015-11-09 13:57:19 +0000136 * <p>It is possible to check if provisioning is allowed or not by querying the method
137 * {@link #isProvisioningAllowed(String)}.
138 *
139 * <p>In version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this intent must contain the
Nicolas Prevot18440252015-03-09 14:07:17 +0000140 * extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700141 * As of {@link android.os.Build.VERSION_CODES#M}, it should contain the extra
Nicolas Prevot18440252015-03-09 14:07:17 +0000142 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead, although specifying only
143 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000144 *
Benjamin Franzea956242016-03-21 15:45:56 +0000145 * <p>The intent may also contain the following extras:
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000146 * <ul>
Benjamin Franzea956242016-03-21 15:45:56 +0000147 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, optional </li>
148 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional, supported from
149 * {@link android.os.Build.VERSION_CODES#N}</li>
150 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
151 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
152 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Victor Chang51d84f92016-11-16 12:22:56 +0000153 * <li>{@link #EXTRA_PROVISIONING_SKIP_USER_CONSENT}, optional</li>
Victor Chang89ee2792016-11-23 12:10:55 +0000154 * <li>{@link #EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION}, 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>
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100236 * </ul>
237 *
Benjamin Franzea956242016-03-21 15:45:56 +0000238 * <p>When device owner provisioning has completed, an intent of the type
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100239 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
240 * device owner.
241 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000242 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
243 * completed, along with the above broadcast, activity intent
244 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
245 *
Benjamin Franzea956242016-03-21 15:45:56 +0000246 * <p>If provisioning fails, the device is factory reset.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100247 *
Alan Treadway4582f812015-07-28 11:49:35 +0100248 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
249 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
250 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
251 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100252 */
253 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
254 public static final String ACTION_PROVISION_MANAGED_DEVICE
255 = "android.app.action.PROVISION_MANAGED_DEVICE";
256
257 /**
Alan Treadway46dd4492015-11-09 13:57:19 +0000258 * Activity action: Starts the provisioning flow which sets up a managed device.
Steven Ng980a1b62016-02-02 17:43:18 +0000259 *
260 * <p>During device owner provisioning, a device admin app is downloaded and set as the owner of
261 * the device. A device owner has full control over the device. The device owner can not be
262 * modified by the user and the only way of resetting the device is via factory reset.
263 *
264 * <p>A typical use case would be a device that is owned by a company, but used by either an
265 * employee or client.
266 *
267 * <p>The provisioning message should be sent to an unprovisioned device.
268 *
269 * <p>Unlike {@link #ACTION_PROVISION_MANAGED_DEVICE}, the provisioning message can only be sent
270 * by a privileged app with the permission
271 * {@link android.Manifest.permission#DISPATCH_PROVISIONING_MESSAGE}.
272 *
273 * <p>The provisioning intent contains the following properties:
274 * <ul>
275 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
276 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
277 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
278 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
279 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
280 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
281 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
282 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
283 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
284 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
285 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
286 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
287 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
288 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
289 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
290 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li></ul>
291 *
292 * @hide
293 */
294 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
295 @SystemApi
296 public static final String ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE =
297 "android.app.action.PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
298
299 /**
300 * Activity action: Starts the provisioning flow which sets up a managed device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000301 * Must be started with {@link android.app.Activity#startActivityForResult(Intent, int)}.
302 *
303 * <p>NOTE: This is only supported on split system user devices, and puts the device into a
304 * management state that is distinct from that reached by
305 * {@link #ACTION_PROVISION_MANAGED_DEVICE} - specifically the device owner runs on the system
306 * user, and only has control over device-wide policies, not individual users and their data.
307 * The primary benefit is that multiple non-system users are supported when provisioning using
308 * this form of device management.
309 *
Benjamin Franzea956242016-03-21 15:45:56 +0000310 * <p>During device owner provisioning a device admin app is set as the owner of the device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000311 * A device owner has full control over the device. The device owner can not be modified by the
312 * user.
313 *
Benjamin Franzea956242016-03-21 15:45:56 +0000314 * <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 +0000315 * employee or client.
316 *
Benjamin Franzea956242016-03-21 15:45:56 +0000317 * <p>An intent with this action can be sent only on an unprovisioned device.
Alan Treadway46dd4492015-11-09 13:57:19 +0000318 * It is possible to check if provisioning is allowed or not by querying the method
319 * {@link #isProvisioningAllowed(String)}.
320 *
321 * <p>The intent contains the following extras:
322 * <ul>
323 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
324 * <li>{@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION}, optional</li>
325 * <li>{@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}, optional</li>
326 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional</li>
Benjamin Franzea956242016-03-21 15:45:56 +0000327 * <li>{@link #EXTRA_PROVISIONING_LOGO_URI}, optional</li>
328 * <li>{@link #EXTRA_PROVISIONING_MAIN_COLOR}, optional</li>
Alan Treadway46dd4492015-11-09 13:57:19 +0000329 * </ul>
330 *
Benjamin Franzea956242016-03-21 15:45:56 +0000331 * <p>When device owner provisioning has completed, an intent of the type
Alan Treadway46dd4492015-11-09 13:57:19 +0000332 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcast to the
333 * device owner.
334 *
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000335 * <p>From version {@link android.os.Build.VERSION_CODES#O}, when device owner provisioning has
336 * completed, along with the above broadcast, activity intent
337 * {@link #ACTION_PROVISIONING_SUCCESSFUL} will also be sent to the device owner.
338 *
Benjamin Franzea956242016-03-21 15:45:56 +0000339 * <p>If provisioning fails, the device is factory reset.
Alan Treadway46dd4492015-11-09 13:57:19 +0000340 *
341 * <p>A result code of {@link android.app.Activity#RESULT_OK} implies that the synchronous part
342 * of the provisioning flow was successful, although this doesn't guarantee the full flow will
343 * succeed. Conversely a result code of {@link android.app.Activity#RESULT_CANCELED} implies
344 * that the user backed-out of provisioning, or some precondition for provisioning wasn't met.
345 *
346 * @hide
347 */
348 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
349 public static final String ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE
350 = "android.app.action.PROVISION_MANAGED_SHAREABLE_DEVICE";
351
352 /**
Alan Treadwayafad8782016-01-19 15:15:08 +0000353 * Activity action: Finalizes management provisioning, should be used after user-setup
354 * has been completed and {@link #getUserProvisioningState()} returns one of:
355 * <ul>
356 * <li>{@link #STATE_USER_SETUP_INCOMPLETE}</li>
357 * <li>{@link #STATE_USER_SETUP_COMPLETE}</li>
358 * <li>{@link #STATE_USER_PROFILE_COMPLETE}</li>
359 * </ul>
360 *
361 * @hide
362 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +0000363 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +0000364 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
365 public static final String ACTION_PROVISION_FINALIZATION
366 = "android.app.action.PROVISION_FINALIZATION";
367
368 /**
Michal Karpinskiba244092016-02-25 17:28:24 +0000369 * Action: Bugreport sharing with device owner has been accepted by the user.
370 *
371 * @hide
372 */
373 public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
374 "com.android.server.action.BUGREPORT_SHARING_ACCEPTED";
375
376 /**
377 * Action: Bugreport sharing with device owner has been declined by the user.
378 *
379 * @hide
380 */
381 public static final String ACTION_BUGREPORT_SHARING_DECLINED =
382 "com.android.server.action.BUGREPORT_SHARING_DECLINED";
383
384 /**
385 * Action: Bugreport has been collected and is dispatched to {@link DevicePolicyManagerService}.
386 *
387 * @hide
388 */
389 public static final String ACTION_REMOTE_BUGREPORT_DISPATCH =
390 "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
391
392 /**
393 * Extra for shared bugreport's SHA-256 hash.
394 *
395 * @hide
396 */
397 public static final String EXTRA_REMOTE_BUGREPORT_HASH =
398 "android.intent.extra.REMOTE_BUGREPORT_HASH";
399
400 /**
401 * Extra for remote bugreport notification shown type.
402 *
403 * @hide
404 */
405 public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
406 "android.app.extra.bugreport_notification_type";
407
408 /**
409 * Notification type for a started remote bugreport flow.
410 *
411 * @hide
412 */
413 public static final int NOTIFICATION_BUGREPORT_STARTED = 1;
414
415 /**
416 * Notification type for a bugreport that has already been accepted to be shared, but is still
417 * being taken.
418 *
419 * @hide
420 */
421 public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED = 2;
422
423 /**
424 * Notification type for a bugreport that has been taken and can be shared or declined.
425 *
426 * @hide
427 */
428 public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED = 3;
429
430 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +0100431 * Default and maximum timeout in milliseconds after which unlocking with weak auth times out,
432 * i.e. the user has to use a strong authentication method like password, PIN or pattern.
433 *
434 * @hide
435 */
436 public static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = 72 * 60 * 60 * 1000; // 72h
437
438 /**
Rubin Xua4f9dc12015-06-12 13:27:59 +0100439 * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100440 * allows a mobile device management application or NFC programmer application which starts
441 * managed provisioning to pass data to the management application instance after provisioning.
Rubin Xua4f9dc12015-06-12 13:27:59 +0100442 * <p>
443 * If used with {@link #ACTION_PROVISION_MANAGED_PROFILE} it can be used by the application that
444 * sends the intent to pass data to itself on the newly created profile.
445 * If used with {@link #ACTION_PROVISION_MANAGED_DEVICE} it allows passing data to the same
446 * instance of the app on the primary user.
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100447 * Starting from {@link android.os.Build.VERSION_CODES#M}, if used with
448 * {@link #MIME_TYPE_PROVISIONING_NFC} as part of NFC managed device provisioning, the NFC
449 * message should contain a stringified {@link java.util.Properties} instance, whose string
450 * properties will be converted into a {@link android.os.PersistableBundle} and passed to the
451 * management application after provisioning.
452 *
Rubin Xua4f9dc12015-06-12 13:27:59 +0100453 * <p>
454 * In both cases the application receives the data in
Brian Carlstromf1fe51b2014-09-03 08:55:05 -0700455 * {@link DeviceAdminReceiver#onProfileProvisioningComplete} via an intent with the action
456 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}. The bundle is not changed
Rubin Xua4f9dc12015-06-12 13:27:59 +0100457 * during the managed provisioning.
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100458 */
459 public static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE =
Esteban Talavera37f01842014-09-05 10:50:57 +0100460 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE";
Sander Alewijnse90f14bf2014-08-20 16:22:44 +0100461
462 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100463 * A String extra holding the package name of the mobile device management application that
464 * will be set as the profile owner or device owner.
465 *
466 * <p>If an application starts provisioning directly via an intent with action
467 * {@link #ACTION_PROVISION_MANAGED_PROFILE} this package has to match the package name of the
468 * application that started provisioning. The package will be set as profile owner in that case.
469 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000470 * <p>This package is set as device owner when device owner provisioning is started by an NFC
471 * message containing an NFC record with MIME type {@link #MIME_TYPE_PROVISIONING_NFC}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000472 *
473 * <p> When this extra is set, the application must have exactly one device admin receiver.
Robin Lee25e26452015-06-02 09:56:29 -0700474 * This receiver will be set as the profile or device owner and active admin.
Benjamin Franzea956242016-03-21 15:45:56 +0000475 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000476 * @see DeviceAdminReceiver
477 * @deprecated Use {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}. This extra is still
Nicolas Prevot8f78d6a2015-08-21 11:06:31 +0100478 * supported, but only if there is only one device admin receiver in the package that requires
479 * the permission {@link android.Manifest.permission#BIND_DEVICE_ADMIN}.
Jessica Hummelf72078b2014-03-06 16:13:12 +0000480 */
Nicolas Prevot18440252015-03-09 14:07:17 +0000481 @Deprecated
Jessica Hummelf72078b2014-03-06 16:13:12 +0000482 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
Esteban Talaveraef9c5232014-09-08 13:51:18 +0100483 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME";
Jessica Hummelf72078b2014-03-06 16:13:12 +0000484
485 /**
Nicolas Prevot18440252015-03-09 14:07:17 +0000486 * A ComponentName extra indicating the device admin receiver of the mobile device management
487 * application that will be set as the profile owner or device owner and active admin.
488 *
489 * <p>If an application starts provisioning directly via an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100490 * {@link #ACTION_PROVISION_MANAGED_PROFILE} or
491 * {@link #ACTION_PROVISION_MANAGED_DEVICE} the package name of this
492 * component has to match the package name of the application that started provisioning.
Nicolas Prevot18440252015-03-09 14:07:17 +0000493 *
494 * <p>This component is set as device owner and active admin when device owner provisioning is
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100495 * started by an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or by an NFC
496 * message containing an NFC record with MIME type
Benjamin Franzea956242016-03-21 15:45:56 +0000497 * {@link #MIME_TYPE_PROVISIONING_NFC}. For the NFC record, the component name must be
Rubin Xu44ef750b2015-03-23 16:51:33 +0000498 * flattened to a string, via {@link ComponentName#flattenToShortString()}.
Nicolas Prevot18440252015-03-09 14:07:17 +0000499 *
500 * @see DeviceAdminReceiver
501 */
502 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
503 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME";
504
505 /**
Alexandra Gherghinaaaf2f3e2014-11-13 12:46:15 +0000506 * An {@link android.accounts.Account} extra holding the account to migrate during managed
507 * profile provisioning. If the account supplied is present in the primary user, it will be
508 * copied, along with its credentials to the managed profile and removed from the primary user.
509 *
510 * Use with {@link #ACTION_PROVISION_MANAGED_PROFILE}.
511 */
512
513 public static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
514 = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE";
515
516 /**
Victor Changaa9cbc02016-12-05 20:50:57 +0000517 * Boolean extra to indicate that the migrated account should be kept. This is used in
518 * conjunction with {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}. If it's set to {@code true},
519 * the account will not be removed from the primary user after it is migrated to the newly
520 * created user or profile.
Victor Chang89ee2792016-11-23 12:10:55 +0000521 *
522 * <p> Defaults to {@code false}
523 *
Victor Changaa9cbc02016-12-05 20:50:57 +0000524 * <p> Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
525 * {@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}
Victor Chang89ee2792016-11-23 12:10:55 +0000526 */
527 public static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
528 = "android.app.extra.PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION";
529
530 /**
Jessica Hummele3da7902014-08-20 15:20:11 +0100531 * A String extra that, holds the email address of the account which a managed profile is
532 * created for. Used with {@link #ACTION_PROVISION_MANAGED_PROFILE} and
533 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100534 *
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100535 * <p> This extra is part of the {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}.
536 *
Jessica Hummele3da7902014-08-20 15:20:11 +0100537 * <p> If the {@link #ACTION_PROVISION_MANAGED_PROFILE} intent that starts managed provisioning
538 * contains this extra, it is forwarded in the
539 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} intent to the mobile
540 * device management application that was set as the profile owner during provisioning.
541 * It is usually used to avoid that the user has to enter their email address twice.
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100542 */
Sander Alewijnse2b338a22014-09-12 12:28:40 +0100543 public static final String EXTRA_PROVISIONING_EMAIL_ADDRESS
544 = "android.app.extra.PROVISIONING_EMAIL_ADDRESS";
Nicolas Prevot07ac20b2014-05-27 15:37:45 +0100545
546 /**
Nicolas Prevotcd2d8592015-11-23 13:27:21 +0000547 * A integer extra indicating the predominant color to show during the provisioning.
548 * Refer to {@link android.graphics.Color} for how the color is represented.
Nicolas Prevotcaf11cd2015-11-19 10:58:35 +0000549 *
550 * <p>Use with {@link #ACTION_PROVISION_MANAGED_PROFILE} or
551 * {@link #ACTION_PROVISION_MANAGED_DEVICE}.
552 */
553 public static final String EXTRA_PROVISIONING_MAIN_COLOR =
554 "android.app.extra.PROVISIONING_MAIN_COLOR";
555
556 /**
Sander Alewijnse8c411562014-11-12 18:03:11 +0000557 * A Boolean extra that can be used by the mobile device management application to skip the
Robin Lee25e26452015-06-02 09:56:29 -0700558 * disabling of system apps during provisioning when set to {@code true}.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000559 *
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100560 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
561 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Sander Alewijnse8c411562014-11-12 18:03:11 +0000562 */
Sander Alewijnse5a144252014-11-18 13:25:04 +0000563 public static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED =
564 "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED";
Sander Alewijnse8c411562014-11-12 18:03:11 +0000565
566 /**
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100567 * A String extra holding the time zone {@link android.app.AlarmManager} that the device
568 * will be set to.
569 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000570 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
571 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100572 */
573 public static final String EXTRA_PROVISIONING_TIME_ZONE
Esteban Talavera37f01842014-09-05 10:50:57 +0100574 = "android.app.extra.PROVISIONING_TIME_ZONE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100575
576 /**
Esteban Talaverad469a0b2014-08-20 13:54:25 +0100577 * A Long extra holding the wall clock time (in milliseconds) to be set on the device's
578 * {@link android.app.AlarmManager}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100579 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000580 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
581 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100582 */
583 public static final String EXTRA_PROVISIONING_LOCAL_TIME
Esteban Talavera37f01842014-09-05 10:50:57 +0100584 = "android.app.extra.PROVISIONING_LOCAL_TIME";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100585
586 /**
587 * A String extra holding the {@link java.util.Locale} that the device will be set to.
588 * Format: xx_yy, where xx is the language code, and yy the country code.
589 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000590 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
591 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100592 */
593 public static final String EXTRA_PROVISIONING_LOCALE
Esteban Talavera37f01842014-09-05 10:50:57 +0100594 = "android.app.extra.PROVISIONING_LOCALE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100595
596 /**
597 * A String extra holding the ssid of the wifi network that should be used during nfc device
598 * owner provisioning for downloading the mobile device management application.
599 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000600 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
601 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100602 */
603 public static final String EXTRA_PROVISIONING_WIFI_SSID
Esteban Talavera37f01842014-09-05 10:50:57 +0100604 = "android.app.extra.PROVISIONING_WIFI_SSID";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100605
606 /**
607 * A boolean extra indicating whether the wifi network in {@link #EXTRA_PROVISIONING_WIFI_SSID}
608 * is hidden or not.
609 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000610 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
611 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100612 */
613 public static final String EXTRA_PROVISIONING_WIFI_HIDDEN
Esteban Talavera37f01842014-09-05 10:50:57 +0100614 = "android.app.extra.PROVISIONING_WIFI_HIDDEN";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100615
616 /**
617 * A String extra indicating the security type of the wifi network in
Mahaver Chopra76b08a92015-10-08 17:58:45 +0100618 * {@link #EXTRA_PROVISIONING_WIFI_SSID} and could be one of {@code NONE}, {@code WPA} or
619 * {@code WEP}.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100620 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000621 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
622 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100623 */
624 public static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE
Esteban Talavera37f01842014-09-05 10:50:57 +0100625 = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100626
627 /**
628 * A String extra holding the password of the wifi network in
629 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
630 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000631 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
632 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100633 */
634 public static final String EXTRA_PROVISIONING_WIFI_PASSWORD
Esteban Talavera37f01842014-09-05 10:50:57 +0100635 = "android.app.extra.PROVISIONING_WIFI_PASSWORD";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100636
637 /**
638 * A String extra holding the proxy host for the wifi network in
639 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
640 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000641 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
642 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100643 */
644 public static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST
Esteban Talavera37f01842014-09-05 10:50:57 +0100645 = "android.app.extra.PROVISIONING_WIFI_PROXY_HOST";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100646
647 /**
648 * An int extra holding the proxy port for the wifi network in
649 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
650 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000651 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
652 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100653 */
654 public static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT
Esteban Talavera37f01842014-09-05 10:50:57 +0100655 = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100656
657 /**
658 * A String extra holding the proxy bypass for the wifi network in
659 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
660 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000661 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
662 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100663 */
664 public static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS
Esteban Talavera37f01842014-09-05 10:50:57 +0100665 = "android.app.extra.PROVISIONING_WIFI_PROXY_BYPASS";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100666
667 /**
668 * A String extra holding the proxy auto-config (PAC) URL for the wifi network in
669 * {@link #EXTRA_PROVISIONING_WIFI_SSID}.
670 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000671 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
672 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100673 */
674 public static final String EXTRA_PROVISIONING_WIFI_PAC_URL
Esteban Talavera37f01842014-09-05 10:50:57 +0100675 = "android.app.extra.PROVISIONING_WIFI_PAC_URL";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100676
677 /**
678 * A String extra holding a url that specifies the download location of the device admin
679 * package. When not provided it is assumed that the device admin package is already installed.
680 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000681 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
682 * provisioning via an NFC bump.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100683 */
684 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION
Esteban Talavera37f01842014-09-05 10:50:57 +0100685 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100686
687 /**
Julia Reynoldsc1731742015-03-19 14:56:28 -0400688 * An int extra holding a minimum required version code for the device admin package. If the
689 * device admin is already installed on the device, it will only be re-downloaded from
690 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION} if the version of the
691 * installed package is less than this version code.
692 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400693 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
Julia Reynoldsc1731742015-03-19 14:56:28 -0400694 * provisioning via an NFC bump.
695 */
696 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE
697 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE";
698
699 /**
Sander Alewijnse681bce92014-07-24 16:46:26 +0100700 * A String extra holding a http cookie header which should be used in the http request to the
701 * url specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
702 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000703 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
704 * provisioning via an NFC bump.
Sander Alewijnse681bce92014-07-24 16:46:26 +0100705 */
706 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER
Esteban Talavera37f01842014-09-05 10:50:57 +0100707 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
Sander Alewijnse681bce92014-07-24 16:46:26 +0100708
709 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100710 * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
711 * the file at download location specified in
712 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100713 *
Benjamin Franzea956242016-03-21 15:45:56 +0000714 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
715 * present. The provided checksum must match the checksum of the file at the download
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100716 * location. If the checksum doesn't match an error will be shown to the user and the user will
717 * be asked to factory reset the device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100718 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000719 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
720 * provisioning via an NFC bump.
Rubin Xud92e7572015-05-18 17:01:13 +0100721 *
722 * <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
723 * and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700724 * Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
Rubin Xud92e7572015-05-18 17:01:13 +0100725 * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100726 */
727 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
Esteban Talavera37f01842014-09-05 10:50:57 +0100728 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100729
730 /**
Rubin Xud92e7572015-05-18 17:01:13 +0100731 * A String extra holding the URL-safe base64 encoded SHA-256 checksum of any signature of the
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100732 * android package archive at the download location specified in {@link
733 * #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
734 *
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100735 * <p>The signatures of an android package archive can be obtained using
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100736 * {@link android.content.pm.PackageManager#getPackageArchiveInfo} with flag
737 * {@link android.content.pm.PackageManager#GET_SIGNATURES}.
738 *
Benjamin Franzea956242016-03-21 15:45:56 +0000739 * <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM} must be
740 * present. The provided checksum must match the checksum of any signature of the file at
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100741 * the download location. If the checksum does not match an error will be shown to the user and
742 * the user will be asked to factory reset the device.
743 *
744 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
745 * provisioning via an NFC bump.
746 */
Rubin Xu5c82d2c2015-06-02 09:29:46 +0100747 public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM
748 = "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM";
Sander Alewijnsee4f878cb2015-04-14 10:49:17 +0100749
750 /**
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000751 * Broadcast Action: This broadcast is sent to indicate that provisioning of a managed profile
752 * has completed successfully.
753 *
754 * <p>The broadcast is limited to the primary profile, to the app specified in the provisioning
Nicolas Prevotebe2d992015-05-12 18:14:53 -0700755 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000756 *
Mahaver7074caf2016-11-29 20:52:18 +0000757 * <p>This intent will contain the following extras
758 * <ul>
759 * <li>{@link Intent#EXTRA_USER}, corresponds to the {@link UserHandle} of the managed
760 * profile.</li>
761 * <li>{@link #EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}, corresponds to the account requested to
762 * be migrated at provisioning time, if any.</li>
763 * </ul>
Alexandra Gherghinadb4bc572015-01-08 12:17:40 +0000764 */
765 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
766 public static final String ACTION_MANAGED_PROFILE_PROVISIONED
767 = "android.app.action.MANAGED_PROFILE_PROVISIONED";
768
769 /**
Mahaver Chopra3c58cfe2016-11-01 21:25:59 +0000770 * Activity action: This activity action is sent to indicate that provisioning of a managed
771 * profile or managed device has completed successfully. It'll be sent at the same time as
772 * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} broadcast but this will be
773 * delivered faster as it's an activity intent.
774 *
775 * <p>The intent is only sent to the application on the profile that requested provisioning. In
776 * the device owner case the profile is the primary user.
777 *
778 * @see #ACTION_PROVISION_MANAGED_PROFILE
779 * @see #ACTION_PROVISION_MANAGED_DEVICE
780 */
781 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
782 public static final String ACTION_PROVISIONING_SUCCESSFUL =
783 "android.app.action.PROVISIONING_SUCCESSFUL";
784
785 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000786 * A boolean extra indicating whether device encryption can be skipped as part of device owner
787 * or managed profile provisioning.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500788 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400789 * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} or an intent with action
Nicolas Prevot64bf7b22015-04-29 14:43:49 +0100790 * {@link #ACTION_PROVISION_MANAGED_DEVICE} that starts device owner provisioning.
Benjamin Franzea956242016-03-21 15:45:56 +0000791 *
792 * <p>From {@link android.os.Build.VERSION_CODES#N} onwards, this is also supported for an
793 * intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Julia Reynoldsa9ec70b2015-02-02 09:54:26 -0500794 */
795 public static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION =
796 "android.app.extra.PROVISIONING_SKIP_ENCRYPTION";
797
798 /**
Nicolas Prevot8b7991c2015-11-12 17:40:12 +0000799 * A {@link Uri} extra pointing to a logo image. This image will be shown during the
800 * provisioning. If this extra is not passed, a default image will be shown.
801 * <h5>The following URI schemes are accepted:</h5>
802 * <ul>
803 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
804 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
805 * </ul>
806 *
807 * <p> It is the responsability of the caller to provide an image with a reasonable
808 * pixed density for the device.
809 *
810 * <p> If a content: URI is passed, the intent should have the flag
811 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and the uri should be added to the
812 * {@link android.content.ClipData} of the intent too.
813 *
814 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_PROFILE} or
815 * {@link #ACTION_PROVISION_MANAGED_DEVICE}
816 */
817 public static final String EXTRA_PROVISIONING_LOGO_URI =
818 "android.app.extra.PROVISIONING_LOGO_URI";
819
820 /**
Alan Treadway94de8c82016-01-11 10:25:23 +0000821 * A boolean extra indicating if user setup should be skipped, for when provisioning is started
822 * during setup-wizard.
823 *
824 * <p>If unspecified, defaults to {@code true} to match the behavior in
825 * {@link android.os.Build.VERSION_CODES#M} and earlier.
826 *
Alan Treadway1a538d02016-01-18 16:42:30 +0000827 * <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE} or
828 * {@link #ACTION_PROVISION_MANAGED_USER}.
Alan Treadway94de8c82016-01-11 10:25:23 +0000829 *
830 * @hide
831 */
832 public static final String EXTRA_PROVISIONING_SKIP_USER_SETUP =
833 "android.app.extra.PROVISIONING_SKIP_USER_SETUP";
834
835 /**
Victor Chang51d84f92016-11-16 12:22:56 +0000836 * A boolean extra indicating if the user consent steps from the provisioning flow should be
837 * skipped. If unspecified, defaults to {@code false}.
838 *
839 * It can only be used by an existing device owner trying to create a managed profile via
840 * {@link #ACTION_PROVISION_MANAGED_PROFILE}. Otherwise it is ignored.
841 */
842 public static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT =
843 "android.app.extra.PROVISIONING_SKIP_USER_CONSENT";
844
845 /**
Benjamin Franzea956242016-03-21 15:45:56 +0000846 * This MIME type is used for starting the device owner provisioning.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100847 *
Craig Lafayette3cc72ba2015-06-26 11:51:04 -0400848 * <p>During device owner provisioning a device admin app is set as the owner of the device.
849 * A device owner has full control over the device. The device owner can not be modified by the
850 * user and the only way of resetting the device is if the device owner app calls a factory
851 * reset.
852 *
853 * <p> A typical use case would be a device that is owned by a company, but used by either an
854 * employee or client.
855 *
Benjamin Franzea956242016-03-21 15:45:56 +0000856 * <p> The NFC message must be sent to an unprovisioned device.
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100857 *
Sander Alewijnse8c411562014-11-12 18:03:11 +0000858 * <p>The NFC record must contain a serialized {@link java.util.Properties} object which
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100859 * contains the following properties:
860 * <ul>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400861 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}</li>
862 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, optional</li>
Sander Alewijnse681bce92014-07-24 16:46:26 +0100863 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, optional</li>
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400864 * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}, optional</li>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100865 * <li>{@link #EXTRA_PROVISIONING_LOCAL_TIME} (convert to String), optional</li>
866 * <li>{@link #EXTRA_PROVISIONING_TIME_ZONE}, optional</li>
867 * <li>{@link #EXTRA_PROVISIONING_LOCALE}, optional</li>
868 * <li>{@link #EXTRA_PROVISIONING_WIFI_SSID}, optional</li>
869 * <li>{@link #EXTRA_PROVISIONING_WIFI_HIDDEN} (convert to String), optional</li>
870 * <li>{@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, optional</li>
871 * <li>{@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, optional</li>
872 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, optional</li>
873 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT} (convert to String), optional</li>
874 * <li>{@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}, optional</li>
Rubin Xu41f2ccb92015-08-05 16:29:13 +0100875 * <li>{@link #EXTRA_PROVISIONING_WIFI_PAC_URL}, optional</li>
876 * <li>{@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}, optional, supported from
877 * {@link android.os.Build.VERSION_CODES#M} </li></ul>
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100878 *
Nicolas Prevot18440252015-03-09 14:07:17 +0000879 * <p>
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700880 * As of {@link android.os.Build.VERSION_CODES#M}, the properties should contain
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400881 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} instead of
882 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}, (although specifying only
883 * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} is still supported).
Andrei Kapishnikov35e71f52015-03-16 17:24:04 -0400884 */
885 public static final String MIME_TYPE_PROVISIONING_NFC
886 = "application/com.android.managedprovisioning";
887
Sander Alewijnse1cc4ecc2014-06-23 19:56:52 +0100888 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800889 * Activity action: ask the user to add a new device administrator to the system.
890 * The desired policy is the ComponentName of the policy in the
891 * {@link #EXTRA_DEVICE_ADMIN} extra field. This will invoke a UI to
892 * bring the user through adding the device administrator to the system (or
893 * allowing them to reject it).
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700894 *
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800895 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
896 * field to provide the user with additional explanation (in addition
897 * to your component's description) about what is being added.
Andy Stadlerc25f70a2010-12-08 15:56:45 -0800898 *
899 * <p>If your administrator is already active, this will ordinarily return immediately (without
900 * user intervention). However, if your administrator has been updated and is requesting
901 * additional uses-policy flags, the user will be presented with the new list. New policies
902 * will not be available to the updated administrator until the user has accepted the new list.
Dianne Hackbornd6847842010-01-12 18:14:19 -0800903 */
904 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
905 public static final String ACTION_ADD_DEVICE_ADMIN
906 = "android.app.action.ADD_DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700907
Dianne Hackbornd6847842010-01-12 18:14:19 -0800908 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700909 * @hide
910 * Activity action: ask the user to add a new device administrator as the profile owner
Amith Yamasani814e9872015-03-23 14:04:53 -0700911 * for this user. Only system apps can launch this intent.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700912 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700913 * <p>The ComponentName of the profile owner admin is passed in the {@link #EXTRA_DEVICE_ADMIN}
914 * extra field. This will invoke a UI to bring the user through adding the profile owner admin
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700915 * to remotely control restrictions on the user.
916 *
Makoto Onukic8a5a552015-11-19 14:29:12 -0800917 * <p>The intent must be invoked via {@link Activity#startActivityForResult} to receive the
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700918 * result of whether or not the user approved the action. If approved, the result will
919 * be {@link Activity#RESULT_OK} and the component will be set as an active admin as well
920 * as a profile owner.
921 *
922 * <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
923 * field to provide the user with additional explanation (in addition
924 * to your component's description) about what is being added.
925 *
Amith Yamasani814e9872015-03-23 14:04:53 -0700926 * <p>If there is already a profile owner active or the caller is not a system app, the
927 * operation will return a failure result.
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700928 */
929 @SystemApi
930 public static final String ACTION_SET_PROFILE_OWNER
931 = "android.app.action.SET_PROFILE_OWNER";
932
933 /**
934 * @hide
935 * Name of the profile owner admin that controls the user.
936 */
937 @SystemApi
938 public static final String EXTRA_PROFILE_OWNER_NAME
939 = "android.app.extra.PROFILE_OWNER_NAME";
940
941 /**
Nicolas Prevot00799002015-07-27 18:15:20 +0100942 * Broadcast action: send when any policy admin changes a policy.
Jim Miller284b62e2010-06-08 14:27:42 -0700943 * This is generally used to find out when a new policy is in effect.
Jim Miller3e5d3fd2011-09-02 17:30:35 -0700944 *
Jim Miller284b62e2010-06-08 14:27:42 -0700945 * @hide
946 */
947 public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
948 = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
949
950 /**
Tony Mak1970f972016-08-30 17:41:48 +0100951 * Broadcast action: sent when the device owner is set, changed or cleared.
Nicolas Prevot00799002015-07-27 18:15:20 +0100952 *
953 * This broadcast is sent only to the primary user.
954 * @see #ACTION_PROVISION_MANAGED_DEVICE
955 */
956 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
957 public static final String ACTION_DEVICE_OWNER_CHANGED
958 = "android.app.action.DEVICE_OWNER_CHANGED";
959
960 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -0800961 * The ComponentName of the administrator component.
962 *
963 * @see #ACTION_ADD_DEVICE_ADMIN
964 */
965 public static final String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700966
Dianne Hackbornd6847842010-01-12 18:14:19 -0800967 /**
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800968 * An optional CharSequence providing additional explanation for why the
969 * admin is being added.
970 *
971 * @see #ACTION_ADD_DEVICE_ADMIN
972 */
973 public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700974
Dianne Hackborn8ea138c2010-01-26 18:01:04 -0800975 /**
Konstantin Lopyrev32558232010-05-20 16:18:05 -0700976 * Activity action: have the user enter a new password. This activity should
977 * be launched after using {@link #setPasswordQuality(ComponentName, int)},
978 * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the user
979 * enter a new password that meets the current requirements. You can use
980 * {@link #isActivePasswordSufficient()} to determine whether you need to
981 * have the user select a new password in order to meet the current
982 * constraints. Upon being resumed from this activity, you can check the new
983 * password characteristics to see if they are sufficient.
Benjamin Franzc9921092016-01-08 17:17:44 +0000984 *
985 * If the intent is launched from within a managed profile with a profile
986 * owner built against {@link android.os.Build.VERSION_CODES#M} or before,
987 * this will trigger entering a new password for the parent of the profile.
988 * For all other cases it will trigger entering a new password for the user
989 * or profile it is launched from.
Esteban Talaverac1c83592016-02-17 17:56:15 +0000990 *
991 * @see #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
Dianne Hackbornd6847842010-01-12 18:14:19 -0800992 */
993 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
994 public static final String ACTION_SET_NEW_PASSWORD
995 = "android.app.action.SET_NEW_PASSWORD";
Amith Yamasanibf3a9462014-07-28 14:26:42 -0700996
Nicolas Prevot10fa67c2014-03-24 13:44:38 +0000997 /**
Benjamin Franzc9921092016-01-08 17:17:44 +0000998 * Activity action: have the user enter a new password for the parent profile.
999 * If the intent is launched from within a managed profile, this will trigger
1000 * entering a new password for the parent of the profile. In all other cases
1001 * the behaviour is identical to {@link #ACTION_SET_NEW_PASSWORD}.
1002 */
1003 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1004 public static final String ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
1005 = "android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD";
1006
1007 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001008 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1009 * the parent profile to access intents sent from the managed profile.
1010 * That is, when an app in the managed profile calls
1011 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1012 * matching activity in the parent profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001013 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001014 public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 0x0001;
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001015
1016 /**
Nicolas Prevot2c1c5dd2015-01-12 12:32:56 +00001017 * Flag used by {@link #addCrossProfileIntentFilter} to allow activities in
1018 * the managed profile to access intents sent from the parent profile.
1019 * That is, when an app in the parent profile calls
1020 * {@link Activity#startActivity(Intent)}, the intent can be resolved by a
1021 * matching activity in the managed profile.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00001022 */
Nicolas Prevot86a96732014-09-08 12:13:05 +01001023 public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 0x0002;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001024
Dianne Hackbornd6847842010-01-12 18:14:19 -08001025 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01001026 * Broadcast action: notify that a new local system update policy has been set by the device
1027 * owner. The new policy can be retrieved by {@link #getSystemUpdatePolicy()}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00001028 */
1029 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Rubin Xu5faad8e2015-04-20 17:43:48 +01001030 public static final String ACTION_SYSTEM_UPDATE_POLICY_CHANGED
1031 = "android.app.action.SYSTEM_UPDATE_POLICY_CHANGED";
Rubin Xu8027a4f2015-03-10 17:52:37 +00001032
Amith Yamasanid49489b2015-04-28 14:00:26 -07001033 /**
1034 * Permission policy to prompt user for new permission requests for runtime permissions.
1035 * Already granted or denied permissions are not affected by this.
1036 */
1037 public static final int PERMISSION_POLICY_PROMPT = 0;
1038
1039 /**
1040 * Permission policy to always grant new permission requests for runtime permissions.
1041 * Already granted or denied permissions are not affected by this.
1042 */
1043 public static final int PERMISSION_POLICY_AUTO_GRANT = 1;
1044
1045 /**
1046 * Permission policy to always deny new permission requests for runtime permissions.
1047 * Already granted or denied permissions are not affected by this.
1048 */
1049 public static final int PERMISSION_POLICY_AUTO_DENY = 2;
1050
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07001051 /**
1052 * Runtime permission state: The user can manage the permission
1053 * through the UI.
1054 */
1055 public static final int PERMISSION_GRANT_STATE_DEFAULT = 0;
1056
1057 /**
1058 * Runtime permission state: The permission is granted to the app
1059 * and the user cannot manage the permission through the UI.
1060 */
1061 public static final int PERMISSION_GRANT_STATE_GRANTED = 1;
1062
1063 /**
1064 * Runtime permission state: The permission is denied to the app
1065 * and the user cannot manage the permission through the UI.
1066 */
1067 public static final int PERMISSION_GRANT_STATE_DENIED = 2;
Rubin Xu8027a4f2015-03-10 17:52:37 +00001068
1069 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00001070 * No management for current user in-effect. This is the default.
1071 * @hide
1072 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001073 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001074 public static final int STATE_USER_UNMANAGED = 0;
1075
1076 /**
1077 * Management partially setup, user setup needs to be completed.
1078 * @hide
1079 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001080 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001081 public static final int STATE_USER_SETUP_INCOMPLETE = 1;
1082
1083 /**
1084 * Management partially setup, user setup completed.
1085 * @hide
1086 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001087 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001088 public static final int STATE_USER_SETUP_COMPLETE = 2;
1089
1090 /**
1091 * Management setup and active on current user.
1092 * @hide
1093 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001094 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001095 public static final int STATE_USER_SETUP_FINALIZED = 3;
1096
1097 /**
1098 * Management partially setup on a managed profile.
1099 * @hide
1100 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00001101 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00001102 public static final int STATE_USER_PROFILE_COMPLETE = 4;
1103
1104 /**
1105 * @hide
1106 */
1107 @IntDef({STATE_USER_UNMANAGED, STATE_USER_SETUP_INCOMPLETE, STATE_USER_SETUP_COMPLETE,
1108 STATE_USER_SETUP_FINALIZED, STATE_USER_PROFILE_COMPLETE})
1109 @Retention(RetentionPolicy.SOURCE)
1110 public @interface UserProvisioningState {}
1111
1112 /**
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00001113 * Result code for {@link checkProvisioningPreCondition}.
1114 *
1115 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1116 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1117 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when provisioning is allowed.
1118 *
1119 * @hide
1120 */
1121 public static final int CODE_OK = 0;
1122
1123 /**
1124 * Result code for {@link checkProvisioningPreCondition}.
1125 *
1126 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1127 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the device already has a device
1128 * owner.
1129 *
1130 * @hide
1131 */
1132 public static final int CODE_HAS_DEVICE_OWNER = 1;
1133
1134 /**
1135 * Result code for {@link checkProvisioningPreCondition}.
1136 *
1137 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1138 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user has a profile owner and for
1139 * {@link #ACTION_PROVISION_MANAGED_PROFILE} when the profile owner is already set.
1140 *
1141 * @hide
1142 */
1143 public static final int CODE_USER_HAS_PROFILE_OWNER = 2;
1144
1145 /**
1146 * Result code for {@link checkProvisioningPreCondition}.
1147 *
1148 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1149 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} when the user isn't running.
1150 *
1151 * @hide
1152 */
1153 public static final int CODE_USER_NOT_RUNNING = 3;
1154
1155 /**
1156 * Result code for {@link checkProvisioningPreCondition}.
1157 *
1158 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1159 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the device has already been setup and
1160 * for {@link #ACTION_PROVISION_MANAGED_USER} if the user has already been setup.
1161 *
1162 * @hide
1163 */
1164 public static final int CODE_USER_SETUP_COMPLETED = 4;
1165
1166 /**
1167 * Code used to indicate that the device also has a user other than the system user.
1168 *
1169 * @hide
1170 */
1171 public static final int CODE_NONSYSTEM_USER_EXISTS = 5;
1172
1173 /**
1174 * Code used to indicate that device has an account that prevents provisioning.
1175 *
1176 * @hide
1177 */
1178 public static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
1179
1180 /**
1181 * Result code for {@link checkProvisioningPreCondition}.
1182 *
1183 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE} and
1184 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} if the user is not a system user.
1185 *
1186 * @hide
1187 */
1188 public static final int CODE_NOT_SYSTEM_USER = 7;
1189
1190 /**
1191 * Result code for {@link checkProvisioningPreCondition}.
1192 *
1193 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1194 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} and {@link #ACTION_PROVISION_MANAGED_USER}
1195 * when the device is a watch and is already paired.
1196 *
1197 * @hide
1198 */
1199 public static final int CODE_HAS_PAIRED = 8;
1200
1201 /**
1202 * Result code for {@link checkProvisioningPreCondition}.
1203 *
1204 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} and
1205 * {@link #ACTION_PROVISION_MANAGED_USER} on devices which do not support managed users.
1206 *
1207 * @see {@link PackageManager#FEATURE_MANAGED_USERS}
1208 * @hide
1209 */
1210 public static final int CODE_MANAGED_USERS_NOT_SUPPORTED = 9;
1211
1212 /**
1213 * Result code for {@link checkProvisioningPreCondition}.
1214 *
1215 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} if the user is a system user.
1216 *
1217 * @hide
1218 */
1219 public static final int CODE_SYSTEM_USER = 10;
1220
1221 /**
1222 * Result code for {@link checkProvisioningPreCondition}.
1223 *
1224 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the user cannot have more
1225 * managed profiles.
1226 *
1227 * @hide
1228 */
1229 public static final int CODE_CANNOT_ADD_MANAGED_PROFILE = 11;
1230
1231 /**
1232 * Result code for {@link checkProvisioningPreCondition}.
1233 *
1234 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_USER} and
1235 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices not running with split system
1236 * user.
1237 *
1238 * @hide
1239 */
1240 public static final int CODE_NOT_SYSTEM_USER_SPLIT = 12;
1241
1242 /**
1243 * Result code for {@link checkProvisioningPreCondition}.
1244 *
1245 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_DEVICE},
1246 * {@link #ACTION_PROVISION_MANAGED_PROFILE}, {@link #ACTION_PROVISION_MANAGED_USER} and
1247 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE} on devices which do no support device
1248 * admins.
1249 *
1250 * @hide
1251 */
1252 public static final int CODE_DEVICE_ADMIN_NOT_SUPPORTED = 13;
1253
1254 /**
1255 * Result code for {@link checkProvisioningPreCondition}.
1256 *
1257 * <p>Returned for {@link #ACTION_PROVISION_MANAGED_PROFILE} when the device has a device owner
1258 * and the user is a system user on a split system user device.
1259 *
1260 * @hide
1261 */
1262 public static final int CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER = 14;
1263
1264 /**
1265 * Result codes for {@link checkProvisioningPreCondition} indicating all the provisioning pre
1266 * conditions.
1267 *
1268 * @hide
1269 */
1270 @Retention(RetentionPolicy.SOURCE)
1271 @IntDef({CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
1272 CODE_USER_SETUP_COMPLETED, CODE_NOT_SYSTEM_USER, CODE_HAS_PAIRED,
1273 CODE_MANAGED_USERS_NOT_SUPPORTED, CODE_SYSTEM_USER, CODE_CANNOT_ADD_MANAGED_PROFILE,
1274 CODE_NOT_SYSTEM_USER_SPLIT, CODE_DEVICE_ADMIN_NOT_SUPPORTED,
1275 CODE_SPLIT_SYSTEM_USER_DEVICE_SYSTEM_USER})
1276 public @interface ProvisioningPreCondition {}
1277
1278 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001279 * Return true if the given administrator component is currently active (enabled) in the system.
1280 *
1281 * @param admin The administrator component to check for.
1282 * @return {@code true} if {@code admin} is currently enabled in the system, {@code false}
1283 * otherwise
Dianne Hackbornd6847842010-01-12 18:14:19 -08001284 */
Robin Lee25e26452015-06-02 09:56:29 -07001285 public boolean isAdminActive(@NonNull ComponentName admin) {
Charles He8c760562016-10-25 16:36:53 +01001286 throwIfParentInstance("isAdminActive");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001287 return isAdminActiveAsUser(admin, myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001288 }
1289
1290 /**
1291 * @see #isAdminActive(ComponentName)
1292 * @hide
1293 */
Robin Lee25e26452015-06-02 09:56:29 -07001294 public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001295 if (mService != null) {
1296 try {
Robin Lee25e26452015-06-02 09:56:29 -07001297 return mService.isAdminActive(admin, userId);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001298 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001299 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001300 }
1301 }
1302 return false;
1303 }
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001304 /**
1305 * Return true if the given administrator component is currently being removed
1306 * for the user.
1307 * @hide
1308 */
Robin Lee25e26452015-06-02 09:56:29 -07001309 public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001310 if (mService != null) {
1311 try {
Robin Lee25e26452015-06-02 09:56:29 -07001312 return mService.isRemovingAdmin(admin, userId);
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001313 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001314 throw e.rethrowFromSystemServer();
Fyodor Kupolov96fb9322014-12-01 15:08:09 -08001315 }
1316 }
1317 return false;
1318 }
1319
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001320
Dianne Hackbornd6847842010-01-12 18:14:19 -08001321 /**
Robin Lee25e26452015-06-02 09:56:29 -07001322 * Return a list of all currently active device administrators' component
1323 * names. If there are no administrators {@code null} may be
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001324 * returned.
1325 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001326 public @Nullable List<ComponentName> getActiveAdmins() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001327 throwIfParentInstance("getActiveAdmins");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001328 return getActiveAdminsAsUser(myUserId());
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001329 }
1330
1331 /**
1332 * @see #getActiveAdmins()
1333 * @hide
1334 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07001335 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001336 if (mService != null) {
1337 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01001338 return mService.getActiveAdmins(userId);
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001339 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001340 throw e.rethrowFromSystemServer();
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001341 }
1342 }
1343 return null;
1344 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001345
Dianne Hackbornd47c6ed2010-01-27 16:21:20 -08001346 /**
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001347 * Used by package administration code to determine if a package can be stopped
1348 * or uninstalled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001349 * @hide
1350 */
1351 public boolean packageHasActiveAdmins(String packageName) {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001352 return packageHasActiveAdmins(packageName, myUserId());
1353 }
1354
1355 /**
1356 * Used by package administration code to determine if a package can be stopped
1357 * or uninstalled.
1358 * @hide
1359 */
1360 public boolean packageHasActiveAdmins(String packageName, int userId) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001361 if (mService != null) {
1362 try {
Amith Yamasanica5d6d22016-02-16 13:58:46 -08001363 return mService.packageHasActiveAdmins(packageName, userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001364 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001365 throw e.rethrowFromSystemServer();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001366 }
1367 }
1368 return false;
1369 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001370
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001371 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08001372 * Remove a current administration component. This can only be called
1373 * by the application that owns the administration component; if you
1374 * try to remove someone else's component, a security exception will be
1375 * thrown.
Esteban Talavera552a5612016-02-19 17:02:24 +00001376 *
1377 * <p>Note that the operation is not synchronous and the admin might still be active (as
1378 * indicated by {@link #getActiveAdmins()}) by the time this method returns.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001379 *
1380 * @param admin The administration compononent to remove.
1381 * @throws SecurityException if the caller is not in the owner application of {@code admin}.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001382 */
Robin Lee25e26452015-06-02 09:56:29 -07001383 public void removeActiveAdmin(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001384 throwIfParentInstance("removeActiveAdmin");
Dianne Hackbornd6847842010-01-12 18:14:19 -08001385 if (mService != null) {
1386 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001387 mService.removeActiveAdmin(admin, myUserId());
Dianne Hackbornd6847842010-01-12 18:14:19 -08001388 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001389 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001390 }
1391 }
1392 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001393
Dianne Hackbornd6847842010-01-12 18:14:19 -08001394 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001395 * Returns true if an administrator has been granted a particular device policy. This can be
1396 * used to check whether the administrator was activated under an earlier set of policies, but
1397 * requires additional policies after an upgrade.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001398 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001399 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Must be an
1400 * active administrator, or an exception will be thrown.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001401 * @param usesPolicy Which uses-policy to check, as defined in {@link DeviceAdminInfo}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001402 * @throws SecurityException if {@code admin} is not an active administrator.
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001403 */
Robin Lee25e26452015-06-02 09:56:29 -07001404 public boolean hasGrantedPolicy(@NonNull ComponentName admin, int usesPolicy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01001405 throwIfParentInstance("hasGrantedPolicy");
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001406 if (mService != null) {
1407 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001408 return mService.hasGrantedPolicy(admin, usesPolicy, myUserId());
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001409 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001410 throw e.rethrowFromSystemServer();
Andy Stadlerc25f70a2010-12-08 15:56:45 -08001411 }
1412 }
1413 return false;
1414 }
1415
1416 /**
Clara Bayarria1771112015-12-18 16:29:18 +00001417 * Returns true if the Profile Challenge is available to use for the given profile user.
1418 *
1419 * @hide
1420 */
1421 public boolean isSeparateProfileChallengeAllowed(int userHandle) {
1422 if (mService != null) {
1423 try {
1424 return mService.isSeparateProfileChallengeAllowed(userHandle);
1425 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001426 throw e.rethrowFromSystemServer();
Clara Bayarria1771112015-12-18 16:29:18 +00001427 }
1428 }
1429 return false;
1430 }
1431
1432 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001433 * Constant for {@link #setPasswordQuality}: the policy has no requirements
1434 * for the password. Note that quality constants are ordered so that higher
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001435 * values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001436 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001437 public static final int PASSWORD_QUALITY_UNSPECIFIED = 0;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001438
Dianne Hackbornd6847842010-01-12 18:14:19 -08001439 /**
Jim Miller3e5d3fd2011-09-02 17:30:35 -07001440 * Constant for {@link #setPasswordQuality}: the policy allows for low-security biometric
1441 * recognition technology. This implies technologies that can recognize the identity of
1442 * an individual to about a 3 digit PIN (false detection is less than 1 in 1,000).
1443 * Note that quality constants are ordered so that higher values are more restrictive.
1444 */
1445 public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 0x8000;
1446
1447 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001448 * Constant for {@link #setPasswordQuality}: the policy requires some kind
Benjamin Franzc6a96532015-06-16 11:23:38 +01001449 * of password or pattern, but doesn't care what it is. Note that quality constants
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001450 * are ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001451 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001452 public static final int PASSWORD_QUALITY_SOMETHING = 0x10000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001453
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001454 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001455 * Constant for {@link #setPasswordQuality}: the user must have entered a
1456 * password containing at least numeric characters. Note that quality
1457 * constants are ordered so that higher values are more restrictive.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08001458 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001459 public static final int PASSWORD_QUALITY_NUMERIC = 0x20000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001460
Dianne Hackbornd6847842010-01-12 18:14:19 -08001461 /**
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001462 * Constant for {@link #setPasswordQuality}: the user must have entered a
Jim Miller85516d02014-01-31 17:08:37 -08001463 * password containing at least numeric characters with no repeating (4444)
1464 * or ordered (1234, 4321, 2468) sequences. Note that quality
1465 * constants are ordered so that higher values are more restrictive.
1466 */
1467 public static final int PASSWORD_QUALITY_NUMERIC_COMPLEX = 0x30000;
1468
1469 /**
1470 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001471 * password containing at least alphabetic (or other symbol) characters.
1472 * Note that quality constants are ordered so that higher values are more
1473 * restrictive.
1474 */
1475 public static final int PASSWORD_QUALITY_ALPHABETIC = 0x40000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001476
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001477 /**
1478 * Constant for {@link #setPasswordQuality}: the user must have entered a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001479 * password containing at least <em>both></em> numeric <em>and</em>
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001480 * alphabetic (or other symbol) characters. Note that quality constants are
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001481 * ordered so that higher values are more restrictive.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001482 */
Dianne Hackborn85f2c9c2010-03-22 11:12:48 -07001483 public static final int PASSWORD_QUALITY_ALPHANUMERIC = 0x50000;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001484
Dianne Hackbornd6847842010-01-12 18:14:19 -08001485 /**
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001486 * Constant for {@link #setPasswordQuality}: the user must have entered a
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001487 * password containing at least a letter, a numerical digit and a special
1488 * symbol, by default. With this password quality, passwords can be
1489 * restricted to contain various sets of characters, like at least an
1490 * uppercase letter, etc. These are specified using various methods,
1491 * like {@link #setPasswordMinimumLowerCase(ComponentName, int)}. Note
1492 * that quality constants are ordered so that higher values are more
1493 * restrictive.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001494 */
1495 public static final int PASSWORD_QUALITY_COMPLEX = 0x60000;
1496
1497 /**
Oleksandr Peletskyi0fdcd3d2016-01-13 16:49:56 +01001498 * Constant for {@link #setPasswordQuality}: the user is not allowed to
1499 * modify password. In case this password quality is set, the password is
1500 * managed by a profile owner. The profile owner can set any password,
1501 * as if {@link #PASSWORD_QUALITY_UNSPECIFIED} is used. Note
1502 * that quality constants are ordered so that higher values are more
1503 * restrictive. The value of {@link #PASSWORD_QUALITY_MANAGED} is
1504 * the highest.
1505 * @hide
1506 */
1507 public static final int PASSWORD_QUALITY_MANAGED = 0x80000;
1508
1509 /**
Makoto Onuki5e7e06702016-09-01 18:02:01 -07001510 * @hide
1511 *
1512 * adb shell dpm set-{device,profile}-owner will normally not allow installing an owner to
1513 * a user with accounts. {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED}
1514 * and {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} are the account features
1515 * used by authenticator to exempt their accounts from this:
1516 *
1517 * <ul>
1518 * <li>Non-test-only DO/PO still can't be installed when there are accounts.
1519 * <p>In order to make an apk test-only, add android:testOnly="true" to the
1520 * &lt;application&gt; tag in the manifest.
1521 *
1522 * <li>Test-only DO/PO can be installed even when there are accounts, as long as all the
1523 * accounts have the {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} feature.
1524 * Some authenticators claim to have any features, so to detect it, we also check
1525 * {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED} and disallow installing
1526 * if any of the accounts have it.
1527 * </ul>
1528 */
1529 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED =
1530 "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
1531
1532 /** @hide See {@link #ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED} */
1533 public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED =
1534 "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
1535
1536 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001537 * Called by an application that is administering the device to set the password restrictions it
1538 * is imposing. After setting this, the user will not be able to enter a new password that is
1539 * not at least as restrictive as what has been set. Note that the current password will remain
1540 * until the user has set a new one, so the change does not take place immediately. To prompt
1541 * the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
Esteban Talaverac1c83592016-02-17 17:56:15 +00001542 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after calling this method.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001543 * <p>
1544 * Quality constants are ordered so that higher values are more restrictive; thus the highest
1545 * requested quality constant (between the policy set here, the user's preference, and any other
1546 * considerations) is the one that is in effect.
1547 * <p>
1548 * The calling device admin must have requested
1549 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1550 * not, a security exception will be thrown.
1551 * <p>
1552 * This method can be called on the {@link DevicePolicyManager} instance returned by
1553 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1554 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001555 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001556 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001557 * @param quality The new desired quality. One of {@link #PASSWORD_QUALITY_UNSPECIFIED},
1558 * {@link #PASSWORD_QUALITY_SOMETHING}, {@link #PASSWORD_QUALITY_NUMERIC},
1559 * {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1560 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} or {@link #PASSWORD_QUALITY_COMPLEX}.
1561 * @throws SecurityException if {@code admin} is not an active administrator or if {@code admin}
1562 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001563 */
Robin Lee25e26452015-06-02 09:56:29 -07001564 public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001565 if (mService != null) {
1566 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001567 mService.setPasswordQuality(admin, quality, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001568 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001569 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001570 }
1571 }
1572 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001573
Dianne Hackbornd6847842010-01-12 18:14:19 -08001574 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001575 * Retrieve the current minimum password quality for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001576 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001577 * a separate challenge are not taken into account.
1578 *
1579 * <p>This method can be called on the {@link DevicePolicyManager} instance
1580 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1581 * restrictions on the parent profile.
1582 *
Robin Lee25e26452015-06-02 09:56:29 -07001583 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001584 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001585 */
Robin Lee25e26452015-06-02 09:56:29 -07001586 public int getPasswordQuality(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001587 return getPasswordQuality(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001588 }
1589
1590 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001591 public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001592 if (mService != null) {
1593 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00001594 return mService.getPasswordQuality(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001596 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001597 }
1598 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08001599 return PASSWORD_QUALITY_UNSPECIFIED;
Dianne Hackbornd6847842010-01-12 18:14:19 -08001600 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001601
Dianne Hackbornd6847842010-01-12 18:14:19 -08001602 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001603 * Called by an application that is administering the device to set the minimum allowed password
1604 * length. After setting this, the user will not be able to enter a new password that is not at
1605 * least as restrictive as what has been set. Note that the current password will remain until
1606 * the user has set a new one, so the change does not take place immediately. To prompt the user
1607 * for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1608 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1609 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
1610 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX}, {@link #PASSWORD_QUALITY_ALPHABETIC},
1611 * {@link #PASSWORD_QUALITY_ALPHANUMERIC}, or {@link #PASSWORD_QUALITY_COMPLEX} with
1612 * {@link #setPasswordQuality}.
1613 * <p>
1614 * The calling device admin must have requested
1615 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1616 * not, a security exception will be thrown.
1617 * <p>
1618 * This method can be called on the {@link DevicePolicyManager} instance returned by
1619 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1620 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00001621 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08001622 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001623 * @param length The new desired minimum password length. A value of 0 means there is no
1624 * restriction.
1625 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1626 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Dianne Hackbornd6847842010-01-12 18:14:19 -08001627 */
Robin Lee25e26452015-06-02 09:56:29 -07001628 public void setPasswordMinimumLength(@NonNull ComponentName admin, int length) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001629 if (mService != null) {
1630 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001631 mService.setPasswordMinimumLength(admin, length, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001632 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001633 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001634 }
1635 }
1636 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001637
Dianne Hackbornd6847842010-01-12 18:14:19 -08001638 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001639 * Retrieve the current minimum password length for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01001640 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00001641 * a separate challenge are not taken into account.
1642 *
1643 * <p>This method can be called on the {@link DevicePolicyManager} instance
1644 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1645 * restrictions on the parent profile.
1646 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01001647 * user and its profiles or a particular one.
Robin Lee25e26452015-06-02 09:56:29 -07001648 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08001649 * all admins.
Dianne Hackbornd6847842010-01-12 18:14:19 -08001650 */
Robin Lee25e26452015-06-02 09:56:29 -07001651 public int getPasswordMinimumLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001652 return getPasswordMinimumLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001653 }
1654
1655 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001656 public int getPasswordMinimumLength(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08001657 if (mService != null) {
1658 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001659 return mService.getPasswordMinimumLength(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08001660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001661 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001662 }
1663 }
1664 return 0;
1665 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07001666
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001667 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001668 * Called by an application that is administering the device to set the minimum number of upper
1669 * case letters required in the password. After setting this, the user will not be able to enter
1670 * a new password that is not at least as restrictive as what has been set. Note that the
1671 * current password will remain until the user has set a new one, so the change does not take
1672 * place immediately. To prompt the user for a new password, use
1673 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1674 * setting this value. This constraint is only imposed if the administrator has also requested
1675 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001676 * <p>
1677 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001678 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1679 * not, a security exception will be thrown.
1680 * <p>
1681 * This method can be called on the {@link DevicePolicyManager} instance returned by
1682 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1683 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001684 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001685 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1686 * @param length The new desired minimum number of upper case letters required in the password.
1687 * A value of 0 means there is no restriction.
1688 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1689 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001690 */
Robin Lee25e26452015-06-02 09:56:29 -07001691 public void setPasswordMinimumUpperCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001692 if (mService != null) {
1693 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001694 mService.setPasswordMinimumUpperCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001695 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001696 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001697 }
1698 }
1699 }
1700
1701 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001702 * Retrieve the current number of upper case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001703 * for a particular admin or all admins that set restrictions on this user and
Esteban Talaverac1c83592016-02-17 17:56:15 +00001704 * its participating profiles. Restrictions on profiles that have a separate challenge
1705 * are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001706 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001707 * {@link #setPasswordMinimumUpperCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001708 * and only applies when the password quality is
1709 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001710 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001711 * <p>This method can be called on the {@link DevicePolicyManager} instance
1712 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1713 * restrictions on the parent profile.
1714 *
Robin Lee25e26452015-06-02 09:56:29 -07001715 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001716 * aggregate all admins.
1717 * @return The minimum number of upper case letters required in the
1718 * password.
1719 */
Robin Lee25e26452015-06-02 09:56:29 -07001720 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001721 return getPasswordMinimumUpperCase(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001722 }
1723
1724 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001725 public int getPasswordMinimumUpperCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001726 if (mService != null) {
1727 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001728 return mService.getPasswordMinimumUpperCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001729 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001730 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001731 }
1732 }
1733 return 0;
1734 }
1735
1736 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001737 * Called by an application that is administering the device to set the minimum number of lower
1738 * case letters required in the password. After setting this, the user will not be able to enter
1739 * a new password that is not at least as restrictive as what has been set. Note that the
1740 * current password will remain until the user has set a new one, so the change does not take
1741 * place immediately. To prompt the user for a new password, use
1742 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1743 * setting this value. This constraint is only imposed if the administrator has also requested
1744 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001745 * <p>
1746 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001747 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1748 * not, a security exception will be thrown.
1749 * <p>
1750 * This method can be called on the {@link DevicePolicyManager} instance returned by
1751 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1752 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001753 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001754 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1755 * @param length The new desired minimum number of lower case letters required in the password.
1756 * A value of 0 means there is no restriction.
1757 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1758 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001759 */
Robin Lee25e26452015-06-02 09:56:29 -07001760 public void setPasswordMinimumLowerCase(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001761 if (mService != null) {
1762 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001763 mService.setPasswordMinimumLowerCase(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001764 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001765 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001766 }
1767 }
1768 }
1769
1770 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001771 * Retrieve the current number of lower case letters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001772 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001773 * and its participating profiles. Restrictions on profiles that have
1774 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001775 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001776 * {@link #setPasswordMinimumLowerCase(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001777 * and only applies when the password quality is
1778 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001779 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001780 * <p>This method can be called on the {@link DevicePolicyManager} instance
1781 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1782 * restrictions on the parent profile.
1783 *
Robin Lee25e26452015-06-02 09:56:29 -07001784 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001785 * aggregate all admins.
1786 * @return The minimum number of lower case letters required in the
1787 * password.
1788 */
Robin Lee25e26452015-06-02 09:56:29 -07001789 public int getPasswordMinimumLowerCase(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001790 return getPasswordMinimumLowerCase(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 getPasswordMinimumLowerCase(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001795 if (mService != null) {
1796 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001797 return mService.getPasswordMinimumLowerCase(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001798 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001799 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001800 }
1801 }
1802 return 0;
1803 }
1804
1805 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001806 * Called by an application that is administering the device to set the minimum number of
1807 * letters required in the password. After setting this, the user will not be able to enter a
1808 * new password that is not at least as restrictive as what has been set. Note that the current
1809 * password will remain until the user has set a new one, so the change does not take place
1810 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1811 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1812 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1813 * {@link #setPasswordQuality}. The default value is 1.
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 letters required in the password. A value of
1825 * 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 setPasswordMinimumLetters(@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.setPasswordMinimumLetters(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 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
Esteban Talaverac1c83592016-02-17 17:56:15 +00001842 * and its participating profiles. Restrictions on profiles that have
1843 * a separate challenge are not taken into account.
1844 * This is the same value as set by
1845 * {@link #setPasswordMinimumLetters(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 letters required in the password.
1856 */
Robin Lee25e26452015-06-02 09:56:29 -07001857 public int getPasswordMinimumLetters(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001858 return getPasswordMinimumLetters(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001859 }
1860
1861 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001862 public int getPasswordMinimumLetters(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001863 if (mService != null) {
1864 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001865 return mService.getPasswordMinimumLetters(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001866 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001867 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001868 }
1869 }
1870 return 0;
1871 }
1872
1873 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001874 * Called by an application that is administering the device to set the minimum number of
1875 * numerical digits required in the password. After setting this, the user will not be able to
1876 * enter a new password that is not at least as restrictive as what has been set. Note that the
1877 * current password will remain until the user has set a new one, so the change does not take
1878 * place immediately. To prompt the user for a new password, use
1879 * {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
1880 * setting this value. This constraint is only imposed if the administrator has also requested
1881 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001882 * <p>
1883 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001884 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1885 * not, a security exception will be thrown.
1886 * <p>
1887 * This method can be called on the {@link DevicePolicyManager} instance returned by
1888 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1889 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001890 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001891 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1892 * @param length The new desired minimum number of numerical digits required in the password. A
1893 * value of 0 means there is no restriction.
1894 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1895 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001896 */
Robin Lee25e26452015-06-02 09:56:29 -07001897 public void setPasswordMinimumNumeric(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001898 if (mService != null) {
1899 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001900 mService.setPasswordMinimumNumeric(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001901 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001902 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001903 }
1904 }
1905 }
1906
1907 /**
1908 * Retrieve the current number of numerical digits required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001909 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001910 * and its participating profiles. Restrictions on profiles that have
1911 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01001912 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00001913 * {@link #setPasswordMinimumNumeric(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001914 * and only applies when the password quality is
1915 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001916 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001917 * <p>This method can be called on the {@link DevicePolicyManager} instance
1918 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1919 * restrictions on the parent profile.
1920 *
Robin Lee25e26452015-06-02 09:56:29 -07001921 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001922 * aggregate all admins.
1923 * @return The minimum number of numerical digits required in the password.
1924 */
Robin Lee25e26452015-06-02 09:56:29 -07001925 public int getPasswordMinimumNumeric(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001926 return getPasswordMinimumNumeric(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001927 }
1928
1929 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001930 public int getPasswordMinimumNumeric(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001931 if (mService != null) {
1932 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001933 return mService.getPasswordMinimumNumeric(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001934 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001935 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001936 }
1937 }
1938 return 0;
1939 }
1940
1941 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001942 * Called by an application that is administering the device to set the minimum number of
1943 * symbols required in the password. After setting this, the user will not be able to enter a
1944 * new password that is not at least as restrictive as what has been set. Note that the current
1945 * password will remain until the user has set a new one, so the change does not take place
1946 * immediately. To prompt the user for a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
1947 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
1948 * only imposed if the administrator has also requested {@link #PASSWORD_QUALITY_COMPLEX} with
1949 * {@link #setPasswordQuality}. The default value is 1.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001950 * <p>
1951 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001952 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
1953 * not, a security exception will be thrown.
1954 * <p>
1955 * This method can be called on the {@link DevicePolicyManager} instance returned by
1956 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
1957 * profile.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001958 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07001959 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
1960 * @param length The new desired minimum number of symbols required in the password. A value of
1961 * 0 means there is no restriction.
1962 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
1963 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001964 */
Robin Lee25e26452015-06-02 09:56:29 -07001965 public void setPasswordMinimumSymbols(@NonNull ComponentName admin, int length) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001966 if (mService != null) {
1967 try {
Esteban Talavera62399912016-01-11 15:37:55 +00001968 mService.setPasswordMinimumSymbols(admin, length, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001969 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07001970 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001971 }
1972 }
1973 }
1974
1975 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00001976 * Retrieve the current number of symbols required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01001977 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00001978 * and its participating profiles. Restrictions on profiles that have
1979 * a separate challenge are not taken into account. This is the same value as
1980 * set by {@link #setPasswordMinimumSymbols(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07001981 * and only applies when the password quality is
1982 * {@link #PASSWORD_QUALITY_COMPLEX}.
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001983 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00001984 * <p>This method can be called on the {@link DevicePolicyManager} instance
1985 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
1986 * restrictions on the parent profile.
1987 *
Robin Lee25e26452015-06-02 09:56:29 -07001988 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001989 * aggregate all admins.
1990 * @return The minimum number of symbols required in the password.
1991 */
Robin Lee25e26452015-06-02 09:56:29 -07001992 public int getPasswordMinimumSymbols(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07001993 return getPasswordMinimumSymbols(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07001994 }
1995
1996 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07001997 public int getPasswordMinimumSymbols(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07001998 if (mService != null) {
1999 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002000 return mService.getPasswordMinimumSymbols(admin, userHandle, mParentInstance);
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002001 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002002 throw e.rethrowFromSystemServer();
Konstantin Lopyreva15dcfa2010-05-24 17:10:56 -07002003 }
2004 }
2005 return 0;
2006 }
2007
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002008 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002009 * Called by an application that is administering the device to set the minimum number of
2010 * non-letter characters (numerical digits or symbols) required in the password. After setting
2011 * this, the user will not be able to enter a new password that is not at least as restrictive
2012 * as what has been set. Note that the current password will remain until the user has set a new
2013 * one, so the change does not take place immediately. To prompt the user for a new password,
2014 * use {@link #ACTION_SET_NEW_PASSWORD} or {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after
2015 * setting this value. This constraint is only imposed if the administrator has also requested
2016 * {@link #PASSWORD_QUALITY_COMPLEX} with {@link #setPasswordQuality}. The default value is 0.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002017 * <p>
2018 * The calling device admin must have requested
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002019 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2020 * not, a security exception will be thrown.
2021 * <p>
2022 * This method can be called on the {@link DevicePolicyManager} instance returned by
2023 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2024 * profile.
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002025 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002026 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2027 * @param length The new desired minimum number of letters required in the password. A value of
2028 * 0 means there is no restriction.
2029 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2030 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002031 */
Robin Lee25e26452015-06-02 09:56:29 -07002032 public void setPasswordMinimumNonLetter(@NonNull ComponentName admin, int length) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002033 if (mService != null) {
2034 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002035 mService.setPasswordMinimumNonLetter(admin, length, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002036 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002037 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002038 }
2039 }
2040 }
2041
2042 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002043 * Retrieve the current number of non-letter characters required in the password
Rubin Xud3609d42016-07-13 18:32:57 +01002044 * for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002045 * and its participating profiles. Restrictions on profiles that have
2046 * a separate challenge are not taken into account.
Jessica Hummel91da58d2014-04-10 17:39:43 +01002047 * This is the same value as set by
Esteban Talaverac1c83592016-02-17 17:56:15 +00002048 * {@link #setPasswordMinimumNonLetter(ComponentName, int)}
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002049 * and only applies when the password quality is
2050 * {@link #PASSWORD_QUALITY_COMPLEX}.
2051 *
Esteban Talaverac1c83592016-02-17 17:56:15 +00002052 * <p>This method can be called on the {@link DevicePolicyManager} instance
2053 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2054 * restrictions on the parent profile.
2055 *
Robin Lee25e26452015-06-02 09:56:29 -07002056 * @param admin The name of the admin component to check, or {@code null} to
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002057 * aggregate all admins.
2058 * @return The minimum number of letters required in the password.
2059 */
Robin Lee25e26452015-06-02 09:56:29 -07002060 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002061 return getPasswordMinimumNonLetter(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002062 }
2063
2064 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002065 public int getPasswordMinimumNonLetter(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002066 if (mService != null) {
2067 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002068 return mService.getPasswordMinimumNonLetter(admin, userHandle, mParentInstance);
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002069 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002070 throw e.rethrowFromSystemServer();
Konstantin Lopyrevc8577402010-06-04 17:15:02 -07002071 }
2072 }
2073 return 0;
2074 }
2075
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002076 /**
2077 * Called by an application that is administering the device to set the length of the password
2078 * history. After setting this, the user will not be able to enter a new password that is the
2079 * same as any password in the history. Note that the current password will remain until the
2080 * user has set a new one, so the change does not take place immediately. To prompt the user for
2081 * a new password, use {@link #ACTION_SET_NEW_PASSWORD} or
2082 * {@link #ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} after setting this value. This constraint is
2083 * only imposed if the administrator has also requested either {@link #PASSWORD_QUALITY_NUMERIC}
2084 * , {@link #PASSWORD_QUALITY_NUMERIC_COMPLEX} {@link #PASSWORD_QUALITY_ALPHABETIC}, or
2085 * {@link #PASSWORD_QUALITY_ALPHANUMERIC} with {@link #setPasswordQuality}.
2086 * <p>
2087 * The calling device admin must have requested
2088 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2089 * not, a security exception will be thrown.
2090 * <p>
2091 * This method can be called on the {@link DevicePolicyManager} instance returned by
2092 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2093 * profile.
2094 *
2095 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2096 * @param length The new desired length of password history. A value of 0 means there is no
2097 * restriction.
2098 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2099 * does not use {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
2100 */
Robin Lee25e26452015-06-02 09:56:29 -07002101 public void setPasswordHistoryLength(@NonNull ComponentName admin, int length) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002102 if (mService != null) {
2103 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002104 mService.setPasswordHistoryLength(admin, length, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002105 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002106 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002107 }
2108 }
2109 }
2110
2111 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002112 * Called by a device admin to set the password expiration timeout. Calling this method will
2113 * restart the countdown for password expiration for the given admin, as will changing the
2114 * device password (for all admins).
2115 * <p>
2116 * The provided timeout is the time delta in ms and will be added to the current time. For
2117 * example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 =
2118 * 432000000 ms for timeout.
2119 * <p>
2120 * To disable password expiration, a value of 0 may be used for timeout.
2121 * <p>
2122 * The calling device admin must have requested
2123 * {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this method; if it has
2124 * not, a security exception will be thrown.
2125 * <p>
2126 * Note that setting the password will automatically reset the expiration time for all active
2127 * admins. Active admins do not need to explicitly call this method in that case.
2128 * <p>
2129 * This method can be called on the {@link DevicePolicyManager} instance returned by
2130 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2131 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002132 *
Jim Millera4e28d12010-11-08 16:15:47 -08002133 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002134 * @param timeout The limit (in ms) that a password can remain in effect. A value of 0 means
2135 * there is no restriction (unlimited).
2136 * @throws SecurityException if {@code admin} is not an active administrator or {@code admin}
2137 * does not use {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD}
Jim Millera4e28d12010-11-08 16:15:47 -08002138 */
Robin Lee25e26452015-06-02 09:56:29 -07002139 public void setPasswordExpirationTimeout(@NonNull ComponentName admin, long timeout) {
Jim Millera4e28d12010-11-08 16:15:47 -08002140 if (mService != null) {
2141 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002142 mService.setPasswordExpirationTimeout(admin, timeout, mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002144 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002145 }
2146 }
2147 }
2148
2149 /**
Jim Miller6b857682011-02-16 16:27:41 -08002150 * Get the password expiration timeout for the given admin. The expiration timeout is the
2151 * recurring expiration timeout provided in the call to
2152 * {@link #setPasswordExpirationTimeout(ComponentName, long)} for the given admin or the
Esteban Talaverac1c83592016-02-17 17:56:15 +00002153 * aggregate of all participating policy administrators if {@code admin} is null. Admins that
2154 * have set restrictions on profiles that have a separate challenge are not taken into account.
2155 *
2156 * <p>This method can be called on the {@link DevicePolicyManager} instance
2157 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2158 * restrictions on the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002159 *
Robin Lee25e26452015-06-02 09:56:29 -07002160 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Jim Millera4e28d12010-11-08 16:15:47 -08002161 * @return The timeout for the given admin or the minimum of all timeouts
2162 */
Robin Lee25e26452015-06-02 09:56:29 -07002163 public long getPasswordExpirationTimeout(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002164 if (mService != null) {
2165 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002166 return mService.getPasswordExpirationTimeout(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002167 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002168 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002169 }
2170 }
2171 return 0;
2172 }
2173
2174 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002175 * Get the current password expiration time for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002176 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002177 * a separate challenge are not taken into account. If admin is {@code null}, then a composite
2178 * of all expiration times is returned - which will be the minimum of all of them.
2179 *
2180 * <p>This method can be called on the {@link DevicePolicyManager} instance
2181 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2182 * the password expiration for the parent profile.
Jim Millera4e28d12010-11-08 16:15:47 -08002183 *
Robin Lee25e26452015-06-02 09:56:29 -07002184 * @param admin The name of the admin component to check, or {@code null} to aggregate all admins.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002185 * @return The password expiration time, in milliseconds since epoch.
Jim Millera4e28d12010-11-08 16:15:47 -08002186 */
Robin Lee25e26452015-06-02 09:56:29 -07002187 public long getPasswordExpiration(@Nullable ComponentName admin) {
Jim Millera4e28d12010-11-08 16:15:47 -08002188 if (mService != null) {
2189 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002190 return mService.getPasswordExpiration(admin, myUserId(), mParentInstance);
Jim Millera4e28d12010-11-08 16:15:47 -08002191 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002192 throw e.rethrowFromSystemServer();
Jim Millera4e28d12010-11-08 16:15:47 -08002193 }
2194 }
2195 return 0;
2196 }
2197
2198 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002199 * Retrieve the current password history length for a particular admin or all admins that
Rubin Xud3609d42016-07-13 18:32:57 +01002200 * set restrictions on this user and its participating profiles. Restrictions on profiles that
Esteban Talaverac1c83592016-02-17 17:56:15 +00002201 * have a separate challenge are not taken into account.
2202 *
2203 * <p>This method can be called on the {@link DevicePolicyManager} instance
2204 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2205 * restrictions on the parent profile.
2206 *
Robin Lee25e26452015-06-02 09:56:29 -07002207 * @param admin The name of the admin component to check, or {@code null} to aggregate
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002208 * all admins.
2209 * @return The length of the password history
2210 */
Robin Lee25e26452015-06-02 09:56:29 -07002211 public int getPasswordHistoryLength(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002212 return getPasswordHistoryLength(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002213 }
2214
2215 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002216 public int getPasswordHistoryLength(@Nullable ComponentName admin, int userHandle) {
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002217 if (mService != null) {
2218 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002219 return mService.getPasswordHistoryLength(admin, userHandle, mParentInstance);
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002220 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002221 throw e.rethrowFromSystemServer();
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002222 }
2223 }
2224 return 0;
2225 }
2226
Dianne Hackbornd6847842010-01-12 18:14:19 -08002227 /**
Dianne Hackborn254cb442010-01-27 19:23:59 -08002228 * Return the maximum password length that the device supports for a
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002229 * particular password quality.
Dianne Hackborn364f6e32010-01-29 17:38:20 -08002230 * @param quality The quality being interrogated.
Dianne Hackborn254cb442010-01-27 19:23:59 -08002231 * @return Returns the maximum length that the user can enter.
2232 */
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08002233 public int getPasswordMaximumLength(int quality) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002234 // Kind-of arbitrary.
2235 return 16;
2236 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002237
Dianne Hackborn254cb442010-01-27 19:23:59 -08002238 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002239 * Determine whether the current password the user has set is sufficient to meet the policy
2240 * requirements (e.g. quality, minimum length) that have been requested by the admins of this
2241 * user and its participating profiles. Restrictions on profiles that have a separate challenge
Andrew Scull5daf2732016-11-14 15:02:45 +00002242 * are not taken into account. The user must be unlocked in order to perform the check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002243 * <p>
2244 * The calling device admin must have requested
2245 * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
2246 * not, a security exception will be thrown.
2247 * <p>
2248 * This method can be called on the {@link DevicePolicyManager} instance returned by
2249 * {@link #getParentProfileInstance(ComponentName)} in order to determine if the password set on
2250 * the parent profile is sufficient.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002251 *
Jessica Hummel91da58d2014-04-10 17:39:43 +01002252 * @return Returns true if the password meets the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002253 * @throws SecurityException if the calling application does not own an active administrator
2254 * that uses {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD}
Andrew Scull5daf2732016-11-14 15:02:45 +00002255 * @throws InvalidStateException if the user is not unlocked.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002256 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002257 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002258 if (mService != null) {
2259 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002260 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002261 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002262 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002263 }
2264 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002265 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002266 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002267
Dianne Hackbornd6847842010-01-12 18:14:19 -08002268 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002269 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002270 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002271 * requested by the admins of the parent user and its profiles.
2272 *
2273 * @param userHandle the userId of the profile to check the password for.
2274 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002275 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002276 * @hide
2277 */
2278 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2279 if (mService != null) {
2280 try {
2281 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2282 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002283 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002284 }
2285 }
2286 return false;
2287 }
2288
2289 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002290 * Retrieve the number of times the user has failed at entering a password since that last
2291 * successful password entry.
2292 * <p>
2293 * This method can be called on the {@link DevicePolicyManager} instance returned by
2294 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2295 * password attemts for the parent user.
2296 * <p>
2297 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2298 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002299 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002300 * @return The number of times user has entered an incorrect password since the last correct
2301 * password entry.
2302 * @throws SecurityException if the calling application does not own an active administrator
2303 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002304 */
2305 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002306 return getCurrentFailedPasswordAttempts(myUserId());
2307 }
2308
2309 /**
2310 * Retrieve the number of times the given user has failed at entering a
2311 * password since that last successful password entry.
2312 *
2313 * <p>The calling device admin must have requested
2314 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2315 * not and it is not the system uid, a security exception will be thrown.
2316 *
2317 * @hide
2318 */
2319 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002320 if (mService != null) {
2321 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002322 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002323 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002324 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002325 }
2326 }
2327 return -1;
2328 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002329
2330 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002331 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002332 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002333 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002334 * @hide
2335 */
2336 public boolean getDoNotAskCredentialsOnBoot() {
2337 if (mService != null) {
2338 try {
2339 return mService.getDoNotAskCredentialsOnBoot();
2340 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002341 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002342 }
2343 }
2344 return false;
2345 }
2346
2347 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002348 * Setting this to a value greater than zero enables a built-in policy that will perform a
2349 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2350 * This built-in policy combines watching for failed passwords and wiping the device, and
2351 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002352 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002353 * <p>
2354 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2355 * revoking credentials, or reporting the failure to a server), you should implement
2356 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2357 * use this API, because if the maximum count is reached, the device or profile will be wiped
2358 * immediately, and your callback will not be invoked.
2359 * <p>
2360 * This method can be called on the {@link DevicePolicyManager} instance returned by
2361 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2362 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002363 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002364 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002365 * @param num The number of failed password attempts at which point the device or profile will
2366 * be wiped.
2367 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2368 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2369 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002370 */
Robin Lee25e26452015-06-02 09:56:29 -07002371 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002372 if (mService != null) {
2373 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002374 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002375 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002376 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002377 }
2378 }
2379 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002380
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002381 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002382 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002383 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002384 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2385 * not taken into account.
2386 *
2387 * <p>This method can be called on the {@link DevicePolicyManager} instance
2388 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2389 * the value for the parent profile.
2390 *
Robin Lee25e26452015-06-02 09:56:29 -07002391 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002392 * all admins.
2393 */
Robin Lee25e26452015-06-02 09:56:29 -07002394 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002395 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002396 }
2397
2398 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002399 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002400 if (mService != null) {
2401 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002402 return mService.getMaximumFailedPasswordsForWipe(
2403 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002404 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002405 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002406 }
2407 }
2408 return 0;
2409 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002410
Dianne Hackborn254cb442010-01-27 19:23:59 -08002411 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002412 * Returns the profile with the smallest maximum failed passwords for wipe,
2413 * for the given user. So for primary user, it might return the primary or
2414 * a managed profile. For a secondary user, it would be the same as the
2415 * user passed in.
2416 * @hide Used only by Keyguard
2417 */
2418 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2419 if (mService != null) {
2420 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002421 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2422 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002423 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002424 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002425 }
2426 }
2427 return UserHandle.USER_NULL;
2428 }
2429
2430 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002431 * Flag for {@link #resetPassword}: don't allow other admins to change
2432 * the password again until the user has entered it.
2433 */
2434 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002435
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002436 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002437 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2438 * If the flag is set, the device can be booted without asking for user password.
2439 * The absence of this flag does not change the current boot requirements. This flag
2440 * can be set by the device owner only. If the app is not the device owner, the flag
2441 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2442 * device to factory defaults.
2443 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002444 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002445
2446 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002447 * Force a new device unlock password (the password needed to access the entire device, not for
2448 * individual accounts) on the user. This takes effect immediately.
2449 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002450 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002451 * device admins that are not device owner and not profile owner.
2452 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002453 * and profile owner can still do this when user is unlocked and does not have a managed
2454 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002455 * <p>
2456 * The given password must be sufficient for the current password quality and length constraints
2457 * as returned by {@link #getPasswordQuality(ComponentName)} and
2458 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2459 * it will be rejected and false returned. Note that the password may be a stronger quality
2460 * (containing alphanumeric characters when the requested quality is only numeric), in which
2461 * case the currently active quality will be increased to match.
2462 * <p>
2463 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002464 * current password constraints allow it. <em>Note: This will not work in
2465 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2466 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2467 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002468 * <p>
2469 * The calling device admin must have requested
2470 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2471 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002472 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002473 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002474 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002475 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2476 * @return Returns true if the password was applied, or false if it is not acceptable for the
2477 * current constraints or if the user has not been decrypted yet.
2478 * @throws SecurityException if the calling application does not own an active administrator
2479 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002480 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002481 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002482 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002483 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002484 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002485 if (mService != null) {
2486 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002487 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002488 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002489 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002490 }
2491 }
2492 return false;
2493 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002494
Dianne Hackbornd6847842010-01-12 18:14:19 -08002495 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002496 * Called by an application that is administering the device to set the maximum time for user
2497 * activity until the device will lock. This limits the length that the user can set. It takes
2498 * effect immediately.
2499 * <p>
2500 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2501 * to be able to call this method; if it has not, a security exception will be thrown.
2502 * <p>
2503 * This method can be called on the {@link DevicePolicyManager} instance returned by
2504 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2505 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002506 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002507 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002508 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2509 * is no restriction.
2510 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2511 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002512 */
Robin Lee25e26452015-06-02 09:56:29 -07002513 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002514 if (mService != null) {
2515 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002516 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002517 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002518 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002519 }
2520 }
2521 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002522
Dianne Hackbornd6847842010-01-12 18:14:19 -08002523 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002524 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002525 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002526 * a separate challenge are not taken into account.
2527 *
2528 * <p>This method can be called on the {@link DevicePolicyManager} instance
2529 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2530 * restrictions on the parent profile.
2531 *
Robin Lee25e26452015-06-02 09:56:29 -07002532 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002533 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002534 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002535 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002536 */
Robin Lee25e26452015-06-02 09:56:29 -07002537 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002538 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002539 }
2540
2541 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002542 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002543 if (mService != null) {
2544 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002545 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002547 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002548 }
2549 }
2550 return 0;
2551 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002552
Dianne Hackbornd6847842010-01-12 18:14:19 -08002553 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002554 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2555 * do not have a separate timeout to lock for work challenge only.
2556 *
2557 * @hide
2558 */
2559 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2560 if (mService != null) {
2561 try {
2562 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2563 } catch (RemoteException e) {
2564 throw e.rethrowFromSystemServer();
2565 }
2566 }
2567 return 0;
2568 }
2569
2570 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002571 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2572 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2573 * authentication method like password, pin or pattern.
2574 *
2575 * <p>This timeout is used internally to reset the timer to require strong auth again after
2576 * specified timeout each time it has been successfully used.
2577 *
2578 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2579 *
2580 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2581 *
2582 * <p>The calling device admin must be a device or profile owner. If it is not,
2583 * a {@link SecurityException} will be thrown.
2584 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002585 * <p>The calling device admin can verify the value it has set by calling
2586 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2587 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002588 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2589 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2590 * profile.
2591 *
2592 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2593 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002594 * authentication method. A value of 0 means the admin is not participating in
2595 * controlling the timeout.
2596 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2597 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2598 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2599 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002600 *
2601 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002602 */
2603 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2604 long timeoutMs) {
2605 if (mService != null) {
2606 try {
2607 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2608 } catch (RemoteException e) {
2609 throw e.rethrowFromSystemServer();
2610 }
2611 }
2612 }
2613
2614 /**
2615 * Determine for how long the user will be able to use secondary, non strong auth for
2616 * authentication, since last strong method authentication (password, pin or pattern) was used.
2617 * After the returned timeout the user is required to use strong authentication method.
2618 *
2619 * <p>This method can be called on the {@link DevicePolicyManager} instance
2620 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2621 * restrictions on the parent profile.
2622 *
2623 * @param admin The name of the admin component to check, or {@code null} to aggregate
2624 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002625 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002626 */
2627 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2628 return getRequiredStrongAuthTimeout(admin, myUserId());
2629 }
2630
2631 /** @hide per-user version */
2632 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2633 if (mService != null) {
2634 try {
2635 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2636 } catch (RemoteException e) {
2637 throw e.rethrowFromSystemServer();
2638 }
2639 }
2640 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2641 }
2642
2643 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002644 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2645 * this call.
2646 * <p>
2647 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2648 * to be able to call this method; if it has not, a security exception will be thrown.
2649 * <p>
2650 * This method can be called on the {@link DevicePolicyManager} instance returned by
2651 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002652 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002653 * @throws SecurityException if the calling application does not own an active administrator
2654 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002655 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002656 public void lockNow() {
2657 if (mService != null) {
2658 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002659 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002660 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002661 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002662 }
2663 }
2664 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002665
Dianne Hackbornd6847842010-01-12 18:14:19 -08002666 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002667 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002668 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002669 */
2670 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2671
2672 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002673 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2674 * data.
2675 *
Paul Crowley2934b262014-12-02 11:21:13 +00002676 * <p>This flag may only be set by device owner admins; if it is set by
2677 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002678 */
2679 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2680
2681 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002682 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2683 * other users will remain unaffected. Calling from the primary user will cause the device to
2684 * reboot, erasing all device data - including all the secondary users and their data - while
2685 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002686 * <p>
2687 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2688 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002689 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002690 * @param flags Bit mask of additional options: currently supported flags are
2691 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2692 * @throws SecurityException if the calling application does not own an active administrator
2693 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002694 */
2695 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002696 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002697 if (mService != null) {
2698 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002699 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002700 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002701 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002702 }
2703 }
2704 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002705
Dianne Hackbornd6847842010-01-12 18:14:19 -08002706 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002707 * Called by an application that is administering the device to set the
2708 * global proxy and exclusion list.
2709 * <p>
2710 * The calling device admin must have requested
2711 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2712 * this method; if it has not, a security exception will be thrown.
2713 * Only the first device admin can set the proxy. If a second admin attempts
2714 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002715 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002716 * be returned.
2717 * The method can be called repeatedly by the device admin alrady setting the
2718 * proxy to update the proxy and exclusion list.
2719 *
Robin Lee25e26452015-06-02 09:56:29 -07002720 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002721 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2722 * Pass Proxy.NO_PROXY to reset the proxy.
2723 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002724 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2725 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002726 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002727 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002728 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002729 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002730 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002731 if (proxySpec == null) {
2732 throw new NullPointerException();
2733 }
2734 if (mService != null) {
2735 try {
2736 String hostSpec;
2737 String exclSpec;
2738 if (proxySpec.equals(Proxy.NO_PROXY)) {
2739 hostSpec = null;
2740 exclSpec = null;
2741 } else {
2742 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2743 throw new IllegalArgumentException();
2744 }
2745 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2746 String hostName = sa.getHostName();
2747 int port = sa.getPort();
2748 StringBuilder hostBuilder = new StringBuilder();
2749 hostSpec = hostBuilder.append(hostName)
2750 .append(":").append(Integer.toString(port)).toString();
2751 if (exclusionList == null) {
2752 exclSpec = "";
2753 } else {
2754 StringBuilder listBuilder = new StringBuilder();
2755 boolean firstDomain = true;
2756 for (String exclDomain : exclusionList) {
2757 if (!firstDomain) {
2758 listBuilder = listBuilder.append(",");
2759 } else {
2760 firstDomain = false;
2761 }
2762 listBuilder = listBuilder.append(exclDomain.trim());
2763 }
2764 exclSpec = listBuilder.toString();
2765 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002766 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2767 != android.net.Proxy.PROXY_VALID)
2768 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002769 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002770 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002771 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002772 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002773 }
2774 }
2775 return null;
2776 }
2777
2778 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002779 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2780 * HTTP proxies - they are generally network dependent. However if you're doing something
2781 * unusual like general internal filtering this may be useful. On a private network where the
2782 * proxy is not accessible, you may break HTTP using this.
2783 * <p>
2784 * This method requires the caller to be the device owner.
2785 * <p>
2786 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002787 *
Jason Monk03bc9912014-05-13 09:44:57 -04002788 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002789 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2790 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2791 * {@code null} value will clear the global HTTP proxy.
2792 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002793 */
Robin Lee25e26452015-06-02 09:56:29 -07002794 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2795 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002796 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002797 if (mService != null) {
2798 try {
2799 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2800 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002801 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002802 }
2803 }
2804 }
2805
2806 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002807 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002808 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2809 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002810 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002811 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002812 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002813 if (mService != null) {
2814 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002815 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002816 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002817 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002818 }
2819 }
2820 return null;
2821 }
2822
2823 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002824 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002825 * indicating that encryption is not supported.
2826 */
2827 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2828
2829 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002830 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002831 * indicating that encryption is supported, but is not currently active.
2832 */
2833 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2834
2835 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002836 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002837 * indicating that encryption is not currently active, but is currently
2838 * being activated. This is only reported by devices that support
2839 * encryption of data and only when the storage is currently
2840 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2841 * to become encrypted will never return this value.
2842 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002843 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002844
2845 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002846 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002847 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002848 * <p>
2849 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002850 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002851 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002852
2853 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002854 * Result code for {@link #getStorageEncryptionStatus}:
2855 * indicating that encryption is active, but an encryption key has not
2856 * been set by the user.
2857 */
2858 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2859
2860 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002861 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002862 * indicating that encryption is active and the encryption key is tied to the user or profile.
2863 * <p>
2864 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2865 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2866 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002867 */
2868 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2869
2870 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002871 * Activity action: begin the process of encrypting data on the device. This activity should
2872 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2873 * After resuming from this activity, use {@link #getStorageEncryption}
2874 * to check encryption status. However, on some devices this activity may never return, as
2875 * it may trigger a reboot and in some cases a complete data wipe of the device.
2876 */
2877 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2878 public static final String ACTION_START_ENCRYPTION
2879 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002880 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002881 * Widgets are enabled in keyguard
2882 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002883 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002884
2885 /**
Jim Miller50e62182014-04-23 17:25:00 -07002886 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002887 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002888 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2889
2890 /**
2891 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2892 */
2893 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2894
2895 /**
Jim Miller50e62182014-04-23 17:25:00 -07002896 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2897 */
2898 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2899
2900 /**
2901 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2902 */
2903 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2904
2905 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002906 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002907 * (e.g. PIN/Pattern/Password).
2908 */
2909 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2910
2911 /**
Jim Miller06e34502014-07-17 14:46:05 -07002912 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2913 */
2914 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2915
2916 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002917 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2918 */
2919 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2920
2921 /**
Jim Miller35207742012-11-02 15:33:20 -07002922 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002923 */
2924 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002925
2926 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002927 * Called by an application that is administering the device to request that the storage system
2928 * be encrypted.
2929 * <p>
2930 * When multiple device administrators attempt to control device encryption, the most secure,
2931 * supported setting will always be used. If any device administrator requests device
2932 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2933 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002934 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002935 * <p>
2936 * This policy controls encryption of the secure (application data) storage area. Data written
2937 * to other storage areas may or may not be encrypted, and this policy does not require or
2938 * control the encryption of any other storage areas. There is one exception: If
2939 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2940 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2941 * written to disk within the encrypted storage area.
2942 * <p>
2943 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2944 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2945 * encryption key may not be fully secured. For maximum security, the administrator should also
2946 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002947 *
2948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2949 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002950 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002951 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2952 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2953 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2954 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2955 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002956 */
Robin Lee25e26452015-06-02 09:56:29 -07002957 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002958 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002959 if (mService != null) {
2960 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002961 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002962 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002963 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002964 }
2965 }
2966 return ENCRYPTION_STATUS_UNSUPPORTED;
2967 }
2968
2969 /**
2970 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002971 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002972 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002973 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2974 * this will return the requested encryption setting as an aggregate of all active
2975 * administrators.
2976 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002977 */
Robin Lee25e26452015-06-02 09:56:29 -07002978 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002979 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002980 if (mService != null) {
2981 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002982 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002983 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002984 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002985 }
2986 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002987 return false;
2988 }
2989
2990 /**
2991 * Called by an application that is administering the device to
2992 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07002993 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08002994 * Depending on the returned status code, the caller may proceed in different
2995 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2996 * storage system does not support encryption. If the
2997 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2998 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002999 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
3000 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003001 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3002 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3003 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003004 *
Robin Lee7e678712014-07-24 16:41:31 +01003005 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003006 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003007 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003008 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003009 */
3010 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003011 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003012 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003013 }
3014
3015 /** @hide per-user version */
3016 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003017 if (mService != null) {
3018 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003019 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003020 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003021 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003022 }
3023 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003024 return ENCRYPTION_STATUS_UNSUPPORTED;
3025 }
3026
3027 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003028 * Mark a CA certificate as approved by the device user. This means that they have been notified
3029 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3030 * keep the certificate on the device.
3031 *
3032 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3033 * this certificate.
3034 *
3035 * @hide
3036 */
3037 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3038 if (mService != null) {
3039 try {
3040 return mService.approveCaCert(alias, userHandle, approval);
3041 } catch (RemoteException e) {
3042 throw e.rethrowFromSystemServer();
3043 }
3044 }
3045 return false;
3046 }
3047
3048 /**
3049 * Check whether a CA certificate has been approved by the device user.
3050 *
3051 * @hide
3052 */
3053 public boolean isCaCertApproved(String alias, int userHandle) {
3054 if (mService != null) {
3055 try {
3056 return mService.isCaCertApproved(alias, userHandle);
3057 } catch (RemoteException e) {
3058 throw e.rethrowFromSystemServer();
3059 }
3060 }
3061 return false;
3062 }
3063
3064 /**
Robin Lee7e678712014-07-24 16:41:31 +01003065 * Installs the given certificate as a user CA.
3066 *
Robin Lee25e26452015-06-02 09:56:29 -07003067 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3068 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003069 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003070 *
3071 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003072 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003073 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3074 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003075 */
Robin Lee25e26452015-06-02 09:56:29 -07003076 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003077 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003078 if (mService != null) {
3079 try {
Robin Lee7e678712014-07-24 16:41:31 +01003080 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003081 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003082 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003083 }
3084 }
3085 return false;
3086 }
3087
3088 /**
Robin Lee7e678712014-07-24 16:41:31 +01003089 * Uninstalls the given certificate from trusted user CAs, if present.
3090 *
Robin Lee25e26452015-06-02 09:56:29 -07003091 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3092 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003093 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003094 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3095 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003096 */
Robin Lee25e26452015-06-02 09:56:29 -07003097 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003098 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003099 if (mService != null) {
3100 try {
Robin Lee306fe082014-06-19 14:04:24 +00003101 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07003102 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003103 } catch (CertificateException e) {
3104 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003105 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003106 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003107 }
3108 }
3109 }
3110
3111 /**
Robin Lee7e678712014-07-24 16:41:31 +01003112 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3113 * If a user has installed any certificates by other means than device policy these will be
3114 * included too.
3115 *
Robin Lee25e26452015-06-02 09:56:29 -07003116 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3117 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003118 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003119 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3120 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003121 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003122 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3123 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003124 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003125 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003126 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003127 mService.enforceCanManageCaCerts(admin);
3128 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3129 for (String alias : certStore.userAliases()) {
3130 try {
3131 certs.add(certStore.getCertificate(alias).getEncoded());
3132 } catch (CertificateException ce) {
3133 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3134 }
3135 }
3136 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003137 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003138 }
3139 }
3140 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003141 }
3142
3143 /**
Robin Lee7e678712014-07-24 16:41:31 +01003144 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3145 * means other than device policy will also be removed, except for system CA certificates.
3146 *
Robin Lee25e26452015-06-02 09:56:29 -07003147 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3148 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003149 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3150 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003151 */
Robin Lee25e26452015-06-02 09:56:29 -07003152 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003153 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003154 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003155 try {
3156 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
3157 .toArray(new String[0]));
3158 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003159 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003160 }
3161 }
3162 }
3163
3164 /**
3165 * Returns whether this certificate is installed as a trusted CA.
3166 *
Robin Lee25e26452015-06-02 09:56:29 -07003167 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3168 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003169 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003170 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3171 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003172 */
Robin Lee25e26452015-06-02 09:56:29 -07003173 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003174 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003175 if (mService != null) {
3176 try {
3177 mService.enforceCanManageCaCerts(admin);
3178 return getCaCertAlias(certBuffer) != null;
3179 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003180 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003181 } catch (CertificateException ce) {
3182 Log.w(TAG, "Could not parse certificate", ce);
3183 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003184 }
3185 return false;
3186 }
3187
3188 /**
Robin Leece3399f2016-02-24 12:08:32 +00003189 * Called by a device or profile owner, or delegated certificate installer, to install a
3190 * certificate and corresponding private key. All apps within the profile will be able to access
3191 * the certificate and use the private key, given direct user approval.
3192 *
3193 * <p>Access to the installed credentials will not be granted to the caller of this API without
3194 * direct user approval. This is for security - should a certificate installer become
3195 * compromised, certificates it had already installed will be protected.
3196 *
3197 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003198 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003199 *
Robin Lee25e26452015-06-02 09:56:29 -07003200 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3201 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003202 * @param privKey The private key to install.
3203 * @param cert The certificate to install.
3204 * @param alias The private key alias under which to install the certificate. If a certificate
3205 * with that alias already exists, it will be overwritten.
3206 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003207 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3208 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003209 */
Robin Leefbc65642015-08-03 16:21:22 +01003210 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3211 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003212 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003213 }
3214
3215 /**
3216 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003217 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3218 * profile will be able to access the certificate chain and use the private key, given direct
3219 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003220 *
Robin Leea1b290e2016-03-09 14:38:36 +00003221 * <p>The caller of this API may grant itself access to the certificate and private key
3222 * immediately, without user approval. It is a best practice not to request this unless strictly
3223 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003224 *
3225 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003226 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003227 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003228 * @param certs The certificate chain to install. The chain should start with the leaf
3229 * certificate and include the chain of trust in order. This will be returned by
3230 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003231 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003232 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003233 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003234 * credentials immediately. Otherwise, access to the credentials will be gated by user
3235 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003236 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003237 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3238 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003239 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003240 */
3241 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003242 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003243 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003244 try {
Rubin Xub4365912016-03-23 12:13:22 +00003245 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3246 byte[] pemChain = null;
3247 if (certs.length > 1) {
3248 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3249 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003250 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3251 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003252 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3253 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003254 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003255 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003256 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3257 Log.w(TAG, "Failed to obtain private key material", e);
3258 } catch (CertificateException | IOException e) {
3259 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003260 }
3261 return false;
3262 }
3263
3264 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003265 * Called by a device or profile owner, or delegated certificate installer, to remove a
3266 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003267 *
3268 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003269 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003270 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003271 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003272 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3273 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003274 */
3275 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003276 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003277 try {
3278 return mService.removeKeyPair(admin, alias);
3279 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003280 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003281 }
Robin Leefbc65642015-08-03 16:21:22 +01003282 }
3283
3284 /**
Robin Lee25e26452015-06-02 09:56:29 -07003285 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003286 * doesn't exist.
3287 */
3288 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3289 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3290 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3291 new ByteArrayInputStream(certBuffer));
3292 return new TrustedCertificateStore().getCertificateAlias(cert);
3293 }
3294
3295 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003296 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003297 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003298 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003299 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003300 * <p>
3301 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3302 * it is later cleared by calling this method with a null value or uninstallling the certificate
3303 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003304 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003305 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3306 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003307 * supplied certificate installer package must be installed when calling this API, otherwise an
3308 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003309 *
Robin Lee25e26452015-06-02 09:56:29 -07003310 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003311 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003312 * access. If {@code null} is given the current package will be cleared.
3313 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003314 */
Robin Lee25e26452015-06-02 09:56:29 -07003315 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3316 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003317 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003318 if (mService != null) {
3319 try {
Robin Lee25e26452015-06-02 09:56:29 -07003320 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003322 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003323 }
3324 }
3325 }
3326
3327 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003328 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3329 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003330 *
Robin Lee25e26452015-06-02 09:56:29 -07003331 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003332 * @return The package name of the current delegated certificate installer, or {@code null} if
3333 * none is set.
3334 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003335 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003336 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3337 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003338 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003339 if (mService != null) {
3340 try {
Robin Lee25e26452015-06-02 09:56:29 -07003341 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003342 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003343 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003344 }
3345 }
3346 return null;
3347 }
3348
3349 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003350 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003351 * specific application for the current user.
3352 *
3353 * @deprecated this version only exists for compability with previous developer preview builds.
3354 * TODO: delete once there are no longer any live references.
3355 * @hide
3356 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003357 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003358 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3359 throws NameNotFoundException, UnsupportedOperationException {
3360 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3361 }
3362
3363 /**
3364 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003365 * specific application for the current user. This connection is automatically granted and
3366 * persisted after a reboot.
3367 * <p>
3368 * The designated package should declare a {@link android.net.VpnService} in its manifest
3369 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3370 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003371 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003372 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003373 * remove an existing always-on VPN configuration.
3374 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3375 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3376 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003377 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003378 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3379 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3380 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003381 */
Robin Leedc679712016-05-03 13:23:03 +01003382 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3383 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003384 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003385 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003386 if (mService != null) {
3387 try {
Robin Leedc679712016-05-03 13:23:03 +01003388 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003389 throw new NameNotFoundException(vpnPackage);
3390 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003391 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003392 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003393 }
3394 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003395 }
3396
3397 /**
3398 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003399 * always-on VPN connection for the current user. If there is no such package, or the always-on
3400 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003401 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003402 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3403 * is set.
3404 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003405 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003406 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003407 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003408 if (mService != null) {
3409 try {
3410 return mService.getAlwaysOnVpnPackage(admin);
3411 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003412 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003413 }
3414 }
3415 return null;
3416 }
3417
3418 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003419 * Called by an application that is administering the device to disable all cameras on the
3420 * device, for this user. After setting this, no applications running as this user will be able
3421 * to access any cameras on the device.
3422 * <p>
3423 * If the caller is device owner, then the restriction will be applied to all users.
3424 * <p>
3425 * The calling device admin must have requested
3426 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3427 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003428 *
3429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3430 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003431 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3432 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003433 */
Robin Lee25e26452015-06-02 09:56:29 -07003434 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003435 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003436 if (mService != null) {
3437 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003438 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003439 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003440 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003441 }
3442 }
3443 }
3444
3445 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003446 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003447 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003448 * @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 -07003449 * have disabled the camera
3450 */
Robin Lee25e26452015-06-02 09:56:29 -07003451 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003452 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003453 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003454 }
3455
3456 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003457 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003458 if (mService != null) {
3459 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003460 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003461 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003462 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003463 }
3464 }
3465 return false;
3466 }
3467
3468 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003469 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003470 * <p>
3471 * There must be only one user on the device, managed by the device owner. Otherwise a
3472 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003473 *
3474 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003475 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3476 * wasn't triggered because a previous bugreport operation is still active (either the
3477 * bugreport is still running or waiting for the user to share or decline)
3478 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3479 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003480 */
3481 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003482 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003483 if (mService != null) {
3484 try {
3485 return mService.requestBugreport(admin);
3486 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003487 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003488 }
3489 }
3490 return false;
3491 }
3492
3493 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003494 * Determine whether or not creating a guest user has been disabled for the device
3495 *
3496 * @hide
3497 */
3498 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3499 // Currently guest users can always be created if multi-user is enabled
3500 // TODO introduce a policy for guest user creation
3501 return false;
3502 }
3503
3504 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003505 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3506 * screen capture also prevents the content from being shown on display devices that do not have
3507 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3508 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003509 * <p>
3510 * The calling device admin must be a device or profile owner. If it is not, a security
3511 * exception will be thrown.
3512 * <p>
3513 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3514 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003515 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003516 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003517 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003518 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003519 */
Robin Lee25e26452015-06-02 09:56:29 -07003520 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003521 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003522 if (mService != null) {
3523 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003524 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003525 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003526 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003527 }
3528 }
3529 }
3530
3531 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003532 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003533 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003534 * @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 +01003535 * have disabled screen capture.
3536 */
Robin Lee25e26452015-06-02 09:56:29 -07003537 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003538 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003539 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003540 }
3541
3542 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003543 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003544 if (mService != null) {
3545 try {
3546 return mService.getScreenCaptureDisabled(admin, userHandle);
3547 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003548 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003549 }
3550 }
3551 return false;
3552 }
3553
3554 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003555 * Called by a device owner to set whether auto time is required. If auto time is required the
3556 * user cannot set the date and time, but has to use network date and time.
3557 * <p>
3558 * Note: if auto time is required the user can still manually set the time zone.
3559 * <p>
3560 * The calling device admin must be a device owner. If it is not, a security exception will be
3561 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003562 *
3563 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3564 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003565 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003566 */
Robin Lee25e26452015-06-02 09:56:29 -07003567 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003568 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003569 if (mService != null) {
3570 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003571 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003572 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003573 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003574 }
3575 }
3576 }
3577
3578 /**
3579 * @return true if auto time is required.
3580 */
3581 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003582 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003583 if (mService != null) {
3584 try {
3585 return mService.getAutoTimeRequired();
3586 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003587 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003588 }
3589 }
3590 return false;
3591 }
3592
3593 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003594 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003595 * <p>
3596 * The system user is exempt from this policy - it is never ephemeral.
3597 * <p>
3598 * The calling device admin must be the device owner. If it is not, a security exception will be
3599 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003600 *
3601 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3602 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003603 * subsequently created users will be ephemeral.
3604 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003605 * @hide
3606 */
3607 public void setForceEphemeralUsers(
3608 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003609 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003610 if (mService != null) {
3611 try {
3612 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3613 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003614 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003615 }
3616 }
3617 }
3618
3619 /**
3620 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003621 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003622 * @hide
3623 */
3624 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003625 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003626 if (mService != null) {
3627 try {
3628 return mService.getForceEphemeralUsers(admin);
3629 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003630 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003631 }
3632 }
3633 return false;
3634 }
3635
3636 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003637 * Called by an application that is administering the device to disable keyguard customizations,
3638 * such as widgets. After setting this, keyguard features will be disabled according to the
3639 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003640 * <p>
3641 * The calling device admin must have requested
3642 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3643 * if it has not, a security exception will be thrown.
3644 * <p>
3645 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3646 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3647 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003648 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003649 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003650 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003651 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003652 * there is one, or the parent user otherwise.
3653 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3654 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003655 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003656 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3657 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003658 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3659 * profile.
3660 * <p>
3661 * Requests to disable other features on a managed profile will be ignored.
3662 * <p>
3663 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003664 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003665 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003666 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003667 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003668 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3669 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3670 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3671 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3672 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3673 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3674 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003675 */
Robin Lee25e26452015-06-02 09:56:29 -07003676 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003677 if (mService != null) {
3678 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003679 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003681 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003682 }
3683 }
3684 }
3685
3686 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003687 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003688 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003689 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3690 *
3691 * <p>This method can be called on the {@link DevicePolicyManager} instance
3692 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3693 * restrictions on the parent profile.
3694 *
Esteban Talavera62399912016-01-11 15:37:55 +00003695 * @param admin The name of the admin component to check, or {@code null} to check whether any
3696 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003697 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3698 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003699 */
Robin Lee25e26452015-06-02 09:56:29 -07003700 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003701 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003702 }
3703
3704 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003705 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003706 if (mService != null) {
3707 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003708 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003709 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003710 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003711 }
3712 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003713 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003714 }
3715
3716 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003717 * @hide
3718 */
Robin Lee25e26452015-06-02 09:56:29 -07003719 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3720 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003721 if (mService != null) {
3722 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003723 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003725 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003726 }
3727 }
3728 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003729
Dianne Hackbornd6847842010-01-12 18:14:19 -08003730 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003731 * @hide
3732 */
Robin Lee25e26452015-06-02 09:56:29 -07003733 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003734 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003735 }
3736
3737 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003738 * @hide
3739 */
Robin Lee25e26452015-06-02 09:56:29 -07003740 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003741 if (mService != null) {
3742 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003743 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003744 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003745 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003746 }
3747 }
3748 }
3749
3750 /**
3751 * @hide
3752 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003753 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003754 if (mService != null) {
3755 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003756 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003757 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003758 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003759 }
3760 }
3761 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003762
Dianne Hackbornd6847842010-01-12 18:14:19 -08003763 /**
3764 * @hide
3765 */
Andrew Scull5daf2732016-11-14 15:02:45 +00003766 public void reportPasswordChanged(@UserIdInt int userId) {
3767 if (mService != null) {
3768 try {
3769 mService.reportPasswordChanged(userId);
3770 } catch (RemoteException e) {
3771 throw e.rethrowFromSystemServer();
3772 }
3773 }
3774 }
3775
3776 /**
3777 * @hide
3778 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003779 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003780 if (mService != null) {
3781 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003782 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003783 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003784 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003785 }
3786 }
3787 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003788
Dianne Hackbornd6847842010-01-12 18:14:19 -08003789 /**
3790 * @hide
3791 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003792 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003793 if (mService != null) {
3794 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003795 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003796 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003797 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003798 }
3799 }
3800 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003801
3802 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003803 * @hide
3804 */
3805 public void reportFailedFingerprintAttempt(int userHandle) {
3806 if (mService != null) {
3807 try {
3808 mService.reportFailedFingerprintAttempt(userHandle);
3809 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003810 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003811 }
3812 }
3813 }
3814
3815 /**
3816 * @hide
3817 */
3818 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3819 if (mService != null) {
3820 try {
3821 mService.reportSuccessfulFingerprintAttempt(userHandle);
3822 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003823 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003824 }
3825 }
3826 }
3827
3828 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003829 * Should be called when keyguard has been dismissed.
3830 * @hide
3831 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003832 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003833 if (mService != null) {
3834 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003835 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003836 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003837 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003838 }
3839 }
3840 }
3841
3842 /**
3843 * Should be called when keyguard view has been shown to the user.
3844 * @hide
3845 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003846 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003847 if (mService != null) {
3848 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003849 mService.reportKeyguardSecured(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003850 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003851 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003852 }
3853 }
3854 }
3855
3856 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003857 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003858 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003859 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3860 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003861 * @return whether the package was successfully registered as the device owner.
3862 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003863 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003864 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003865 public boolean setDeviceOwner(ComponentName who) {
3866 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003867 }
3868
3869 /**
3870 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003871 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003872 public boolean setDeviceOwner(ComponentName who, int userId) {
3873 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003874 }
3875
3876 /**
3877 * @hide
3878 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003879 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3880 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003881 }
3882
3883 /**
3884 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003885 * Sets the given package as the device owner. The package must already be installed. There
3886 * must not already be a device owner.
3887 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3888 * this method.
3889 * Calling this after the setup phase of the primary user has completed is allowed only if
3890 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003891 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003892 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003893 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003894 * @return whether the package was successfully registered as the device owner.
3895 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003896 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003897 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003898 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003899 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003900 if (mService != null) {
3901 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003902 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003903 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003904 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003905 }
3906 }
3907 return false;
3908 }
3909
3910 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003911 * Used to determine if a particular package has been registered as a Device Owner app.
3912 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003913 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003914 * package is currently registered as the device owner app, pass in the package name from
3915 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003916 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003917 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3918 * the setup process.
3919 * @param packageName the package name of the app, to compare with the registered device owner
3920 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003921 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003922 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003923 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003924 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003925 return isDeviceOwnerAppOnCallingUser(packageName);
3926 }
3927
3928 /**
3929 * @return true if a package is registered as device owner, only when it's running on the
3930 * calling user.
3931 *
3932 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3933 * @hide
3934 */
3935 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3936 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3937 }
3938
3939 /**
3940 * @return true if a package is registered as device owner, even if it's running on a different
3941 * user.
3942 *
3943 * <p>Requires the MANAGE_USERS permission.
3944 *
3945 * @hide
3946 */
3947 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3948 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3949 }
3950
3951 /**
3952 * @return device owner component name, only when it's running on the calling user.
3953 *
3954 * @hide
3955 */
3956 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3957 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3958 }
3959
3960 /**
3961 * @return device owner component name, even if it's running on a different user.
3962 *
3963 * <p>Requires the MANAGE_USERS permission.
3964 *
3965 * @hide
3966 */
3967 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3968 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3969 }
3970
3971 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003972 if (packageName == null) {
3973 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003974 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003975 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003976 if (deviceOwner == null) {
3977 return false;
3978 }
3979 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003980 }
3981
Makoto Onukic8a5a552015-11-19 14:29:12 -08003982 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3983 if (mService != null) {
3984 try {
3985 return mService.getDeviceOwnerComponent(callingUserOnly);
3986 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003987 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003988 }
3989 }
3990 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003991 }
3992
Jason Monkb0dced82014-06-06 14:36:20 -04003993 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003994 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3995 * no device owner.
3996 *
3997 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003998 *
3999 * @hide
4000 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08004001 public int getDeviceOwnerUserId() {
4002 if (mService != null) {
4003 try {
4004 return mService.getDeviceOwnerUserId();
4005 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004006 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08004007 }
4008 }
4009 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07004010 }
4011
4012 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004013 * Clears the current device owner. The caller must be the device owner. This function should be
4014 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4015 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004016 *
4017 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004018 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4019 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004020 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004021 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004022 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004023 if (mService != null) {
4024 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004025 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004026 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004027 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004028 }
4029 }
4030 }
4031
Makoto Onukia52562c2015-10-01 16:12:31 -07004032 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004033 * Returns the device owner package name, only if it's running on the calling user.
4034 *
4035 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004036 *
4037 * @hide
4038 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004039 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004040 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004041 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004042 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4043 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004044 }
4045
4046 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004047 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004048 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004049 * @return whether the device is managed by a Device Owner.
4050 * @throws SecurityException if the caller is not the device owner, does not hold the
4051 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004052 *
4053 * @hide
4054 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004055 @SystemApi
4056 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004057 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004058 try {
4059 return mService.hasDeviceOwner();
4060 } catch (RemoteException re) {
4061 throw re.rethrowFromSystemServer();
4062 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004063 }
4064
4065 /**
4066 * Returns the device owner name. Note this method *will* return the device owner
4067 * name when it's running on a different user.
4068 *
4069 * <p>Requires the MANAGE_USERS permission.
4070 *
4071 * @hide
4072 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004073 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004074 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004075 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004076 if (mService != null) {
4077 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004078 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004079 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004080 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004081 }
4082 }
4083 return null;
4084 }
Adam Connors776c5552014-01-09 10:42:56 +00004085
4086 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004087 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004088 * @deprecated Do not use
4089 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004090 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004091 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004092 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004093 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004094 return null;
4095 }
4096
4097 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004098 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004099 * @deprecated Do not use
4100 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004101 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004102 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004103 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004104 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004105 return null;
4106 }
4107
Julia Reynolds20118f12015-02-11 12:34:08 -05004108 /**
Adam Connors776c5552014-01-09 10:42:56 +00004109 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004110 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304111 * Sets the given component as an active admin and registers the package as the profile
4112 * owner for this user. The package must already be installed and there shouldn't be
4113 * an existing profile owner registered for this user. Also, this method must be called
4114 * before the user setup has been completed.
4115 * <p>
4116 * This method can only be called by system apps that hold MANAGE_USERS permission and
4117 * MANAGE_DEVICE_ADMINS permission.
4118 * @param admin The component to register as an active admin and profile owner.
4119 * @param ownerName The user-visible name of the entity that is managing this user.
4120 * @return whether the admin was successfully registered as the profile owner.
4121 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4122 * the user has already been set up.
4123 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004124 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004125 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004126 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304127 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004128 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304129 if (mService != null) {
4130 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004131 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304132 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004133 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304134 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004135 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304136 }
4137 }
4138 return false;
4139 }
4140
4141 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004142 * Clears the active profile owner and removes all user restrictions. The caller must be from
4143 * the same package as the active profile owner for this user, otherwise a SecurityException
4144 * will be thrown.
4145 * <p>
4146 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004147 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004148 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004149 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004150 */
Robin Lee25e26452015-06-02 09:56:29 -07004151 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004152 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004153 if (mService != null) {
4154 try {
4155 mService.clearProfileOwner(admin);
4156 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004157 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004158 }
4159 }
4160 }
4161
4162 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004163 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004164 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004165 */
4166 public boolean hasUserSetupCompleted() {
4167 if (mService != null) {
4168 try {
4169 return mService.hasUserSetupCompleted();
4170 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004171 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004172 }
4173 }
4174 return true;
4175 }
4176
4177 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004178 * @hide
4179 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004180 * already be installed. There must not already be a profile owner for this user.
4181 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4182 * this method.
4183 * Calling this after the setup phase of the specified user has completed is allowed only if:
4184 * - the caller is SYSTEM_UID.
4185 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004186 * @param admin the component name to be registered as profile owner.
4187 * @param ownerName the human readable name of the organisation associated with this DPM.
4188 * @param userHandle the userId to set the profile owner for.
4189 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004190 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4191 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004192 */
Robin Lee25e26452015-06-02 09:56:29 -07004193 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004194 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004195 if (mService != null) {
4196 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004197 if (ownerName == null) {
4198 ownerName = "";
4199 }
4200 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004201 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004202 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004203 }
4204 }
4205 return false;
4206 }
4207
4208 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004209 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004210 * <p>
4211 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004212 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004213 * <p>
4214 * If the device owner information contains only whitespaces then the message on the lock screen
4215 * will be blank and the user will not be allowed to change it.
4216 * <p>
4217 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004218 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4219 * and set a new version of this string accordingly.
4220 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004221 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004222 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004223 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004224 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004225 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004226 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004227 if (mService != null) {
4228 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004229 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004230 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004231 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004232 }
4233 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004234 }
4235
4236 /**
4237 * @return The device owner information. If it is not set returns {@code null}.
4238 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004239 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004240 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004241 if (mService != null) {
4242 try {
4243 return mService.getDeviceOwnerLockScreenInfo();
4244 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004245 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004246 }
4247 }
4248 return null;
4249 }
4250
4251 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004252 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004253 * <p>
4254 * A suspended package will not be able to start activities. Its notifications will be hidden,
4255 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4256 * device.
4257 * <p>
4258 * The package must already be installed. If the package is uninstalled while suspended the
4259 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004260 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004261 *
4262 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004263 * @param packageNames The package names to suspend or unsuspend.
4264 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004265 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004266 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004267 * this method.
4268 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004269 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004270 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4271 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004272 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004273 if (mService != null) {
4274 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004275 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004276 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004277 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004278 }
4279 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004280 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004281 }
4282
4283 /**
4284 * Called by device or profile owners to determine if a package is suspended.
4285 *
4286 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4287 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004288 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004289 * suspended, could not be found or an error occurred.
4290 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004291 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004292 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004293 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4294 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004295 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004296 if (mService != null) {
4297 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004298 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004299 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004300 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004301 } catch (IllegalArgumentException ex) {
4302 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004303 }
4304 }
4305 return false;
4306 }
4307
4308 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004309 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4310 * be used. Only the profile owner can call this.
4311 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004312 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004313 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004314 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004315 */
Robin Lee25e26452015-06-02 09:56:29 -07004316 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004317 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004318 if (mService != null) {
4319 try {
4320 mService.setProfileEnabled(admin);
4321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004322 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004323 }
4324 }
4325 }
4326
4327 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004328 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4329 * is called from. Only a profile owner or device owner can call this. If this is never called
4330 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004331 *
4332 * @see #isProfileOwnerApp
4333 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004334 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004335 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004336 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004337 */
Robin Lee25e26452015-06-02 09:56:29 -07004338 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004339 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004340 if (mService != null) {
4341 try {
Robin Lee25e26452015-06-02 09:56:29 -07004342 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004343 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004344 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004345 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004346 }
4347 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004348
4349 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004350 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004351 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004352 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004353 *
4354 * @param packageName The package name of the app to compare with the registered profile owner.
4355 * @return Whether or not the package is registered as the profile owner.
4356 */
4357 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004358 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004359 if (mService != null) {
4360 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004361 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004362 return profileOwner != null
4363 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004364 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004365 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004366 }
4367 }
4368 return false;
4369 }
4370
4371 /**
4372 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004373 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004374 * owner has been set for that user.
4375 * @throws IllegalArgumentException if the userId is invalid.
4376 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004377 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004378 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004379 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004380 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4381 }
4382
4383 /**
4384 * @see #getProfileOwner()
4385 * @hide
4386 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004387 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4388 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004389 if (mService != null) {
4390 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004391 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004392 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004393 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004394 }
4395 }
4396 return null;
4397 }
4398
4399 /**
4400 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004401 * @return the human readable name of the organisation associated with this DPM or {@code null}
4402 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004403 * @throws IllegalArgumentException if the userId is invalid.
4404 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004405 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004406 if (mService != null) {
4407 try {
4408 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4409 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004410 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004411 }
4412 }
4413 return null;
4414 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004415
4416 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004417 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004418 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004419 * @return the human readable name of the organisation associated with this profile owner or
4420 * null if one is not set.
4421 * @throws IllegalArgumentException if the userId is invalid.
4422 */
4423 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004424 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004425 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004426 if (mService != null) {
4427 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004428 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004429 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004430 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004431 }
4432 }
4433 return null;
4434 }
4435
4436 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004437 * Called by a profile owner or device owner to add a default intent handler activity for
4438 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004439 * handler even if the set of potential event handlers for the intent filter changes and if the
4440 * intent preferences are reset.
4441 * <p>
4442 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4443 * When the activity is (re)installed, it is automatically reset as default intent handler for
4444 * the filter.
4445 * <p>
4446 * The calling device admin must be a profile owner or device owner. If it is not, a security
4447 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004448 *
4449 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4450 * @param filter The IntentFilter for which a default handler is added.
4451 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004452 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004453 */
Robin Lee25e26452015-06-02 09:56:29 -07004454 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4455 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004456 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004457 if (mService != null) {
4458 try {
4459 mService.addPersistentPreferredActivity(admin, filter, activity);
4460 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004461 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004462 }
4463 }
4464 }
4465
4466 /**
4467 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004468 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004469 * <p>
4470 * The calling device admin must be a profile owner. If it is not, a security exception will be
4471 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004472 *
4473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4474 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004475 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004476 */
Robin Lee25e26452015-06-02 09:56:29 -07004477 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004478 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004479 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004480 if (mService != null) {
4481 try {
4482 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4483 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004484 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004485 }
4486 }
4487 }
Robin Lee66e5d962014-04-09 16:44:21 +01004488
4489 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004490 * Called by a profile owner or device owner to grant permission to a package to manage
4491 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4492 * {@link #getApplicationRestrictions}.
4493 * <p>
4494 * This permission is persistent until it is later cleared by calling this method with a
4495 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004496 * <p>
4497 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004498 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004499 *
4500 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4501 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004502 * APIs. If {@code null} is given the current package will be cleared.
4503 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004504 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004505 */
4506 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004507 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004508 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004509 if (mService != null) {
4510 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004511 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4512 throw new NameNotFoundException(packageName);
4513 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004514 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004515 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004516 }
4517 }
4518 }
4519
4520 /**
4521 * Called by a profile owner or device owner to retrieve the application restrictions managing
4522 * package for the current user, or {@code null} if none is set.
4523 *
4524 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4525 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004526 * {@code null} if none is set.
4527 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004528 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004529 public @Nullable String getApplicationRestrictionsManagingPackage(
4530 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004531 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004532 if (mService != null) {
4533 try {
4534 return mService.getApplicationRestrictionsManagingPackage(admin);
4535 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004536 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004537 }
4538 }
4539 return null;
4540 }
4541
4542 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004543 * Called by any application to find out whether it has been granted permission via
4544 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4545 * for the calling user.
4546 *
4547 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4548 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004549 */
4550 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004551 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004552 if (mService != null) {
4553 try {
4554 return mService.isCallerApplicationRestrictionsManagingPackage();
4555 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004556 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004557 }
4558 }
4559 return false;
4560 }
4561
4562 /**
4563 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004564 * <p>
4565 * The caller must be a profile or device owner on that user, or the package allowed to manage
4566 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4567 * security exception will be thrown.
4568 * <p>
4569 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004570 * <ul>
4571 * <li>{@code boolean}
4572 * <li>{@code int}
4573 * <li>{@code String} or {@code String[]}
4574 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4575 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004576 * <p>
4577 * If the restrictions are not available yet, but may be applied in the near future, the caller
4578 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004579 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004580 * <p>
4581 * The application restrictions are only made visible to the target application via
4582 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4583 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004584 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004585 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004586 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4587 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004588 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004589 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004590 * @param packageName The name of the package to update restricted settings for.
4591 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004592 * set of active restrictions.
4593 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004594 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004595 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004596 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004597 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004598 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004599 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004600 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004601 if (mService != null) {
4602 try {
4603 mService.setApplicationRestrictions(admin, packageName, settings);
4604 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004605 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004606 }
4607 }
4608 }
4609
4610 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004611 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4612 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4613 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004614 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004615 * <p>
4616 * The calling device admin must have requested
4617 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4618 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004619 * <p>
4620 * This method can be called on the {@link DevicePolicyManager} instance returned by
4621 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4622 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004623 *
4624 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004625 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004626 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4627 * strictly disabled according to the state of the
4628 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4629 * <p>
4630 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4631 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4632 * device admins.
4633 * <p>
4634 * Consult documentation for the specific TrustAgent to determine legal options
4635 * parameters.
4636 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4637 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004638 */
Robin Lee25e26452015-06-02 09:56:29 -07004639 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4640 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004641 if (mService != null) {
4642 try {
Tony Mak089d8402016-04-05 17:42:55 +01004643 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004644 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004645 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004646 }
4647 }
4648 }
4649
4650 /**
Jim Millere303bf42014-08-26 17:12:29 -07004651 * Gets configuration for the given trust agent based on aggregating all calls to
4652 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4653 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004654 * <p>
4655 * This method can be called on the {@link DevicePolicyManager} instance returned by
4656 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4657 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004658 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004659 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4660 * this function returns a list of configurations for all admins that declare
4661 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4662 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4663 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4664 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004665 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004666 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004667 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004668 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4669 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004670 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004671 }
4672
4673 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004674 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4675 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004676 if (mService != null) {
4677 try {
Tony Mak089d8402016-04-05 17:42:55 +01004678 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4679 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004680 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004681 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004682 }
4683 }
Jim Millere303bf42014-08-26 17:12:29 -07004684 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004685 }
4686
4687 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004688 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4689 * managed profile will be shown in the parent profile, for incoming calls.
4690 * <p>
4691 * The calling device admin must be a profile owner. If it is not, a security exception will be
4692 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004693 *
Robin Lee25e26452015-06-02 09:56:29 -07004694 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004695 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004696 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004697 */
Robin Lee25e26452015-06-02 09:56:29 -07004698 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004699 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004700 if (mService != null) {
4701 try {
Robin Lee25e26452015-06-02 09:56:29 -07004702 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004703 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004704 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004705 }
4706 }
4707 }
4708
4709 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004710 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4711 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004712 * <p>
4713 * The calling device admin must be a profile owner. If it is not, a security exception will be
4714 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004715 *
Robin Lee25e26452015-06-02 09:56:29 -07004716 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004717 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004718 */
Robin Lee25e26452015-06-02 09:56:29 -07004719 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004720 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004721 if (mService != null) {
4722 try {
Robin Lee25e26452015-06-02 09:56:29 -07004723 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004725 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004726 }
4727 }
4728 return false;
4729 }
4730
4731 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004732 * Determine whether or not caller-Id information has been disabled.
4733 *
4734 * @param userHandle The user for whom to check the caller-id permission
4735 * @hide
4736 */
4737 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4738 if (mService != null) {
4739 try {
4740 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4741 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004742 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004743 }
4744 }
4745 return false;
4746 }
4747
4748 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004749 * Called by a profile owner of a managed profile to set whether contacts search from the
4750 * managed profile will be shown in the parent profile, for incoming calls.
4751 * <p>
4752 * The calling device admin must be a profile owner. If it is not, a security exception will be
4753 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004754 *
4755 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4756 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004757 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004758 */
4759 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4760 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004761 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004762 if (mService != null) {
4763 try {
4764 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4765 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004766 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004767 }
4768 }
4769 }
4770
4771 /**
4772 * Called by a profile owner of a managed profile to determine whether or not contacts search
4773 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004774 * <p>
4775 * The calling device admin must be a profile owner. If it is not, a security exception will be
4776 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004777 *
4778 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004779 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004780 */
4781 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004782 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004783 if (mService != null) {
4784 try {
4785 return mService.getCrossProfileContactsSearchDisabled(admin);
4786 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004787 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004788 }
4789 }
4790 return false;
4791 }
4792
4793
4794 /**
4795 * Determine whether or not contacts search has been disabled.
4796 *
4797 * @param userHandle The user for whom to check the contacts search permission
4798 * @hide
4799 */
4800 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4801 if (mService != null) {
4802 try {
4803 return mService
4804 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4805 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004806 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004807 }
4808 }
4809 return false;
4810 }
4811
4812 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004813 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004814 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004815 * @hide
4816 */
4817 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004818 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004819 if (mService != null) {
4820 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004821 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4822 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004823 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004824 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004825 }
4826 }
4827 }
4828
4829 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004830 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004831 * @hide
4832 */
4833 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4834 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004835 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004836 originalIntent);
4837 }
4838
4839 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004840 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4841 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004842 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004843 * The calling device admin must be a profile owner. If it is not, a security exception will be
4844 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004845 * <p>
4846 * This API works on managed profile only.
4847 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4849 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4850 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004851 */
Robin Lee25e26452015-06-02 09:56:29 -07004852 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004853 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004854 if (mService != null) {
4855 try {
Robin Lee25e26452015-06-02 09:56:29 -07004856 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004857 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004858 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004859 }
4860 }
4861 }
4862
4863 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004864 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4865 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004866 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004867 * The calling device admin must be a profile owner. If it is not, a security exception will be
4868 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004869 * <p>
4870 * This API works on managed profile only.
4871 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004872 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4873 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004874 */
Robin Lee25e26452015-06-02 09:56:29 -07004875 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004876 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004877 if (mService != null) {
4878 try {
Robin Lee25e26452015-06-02 09:56:29 -07004879 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004880 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004881 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004882 }
4883 }
4884 return true;
4885 }
4886
4887 /**
4888 * Determine whether or not Bluetooth devices cannot access contacts.
4889 * <p>
4890 * This API works on managed profile UserHandle only.
4891 *
4892 * @param userHandle The user for whom to check the caller-id permission
4893 * @hide
4894 */
4895 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4896 if (mService != null) {
4897 try {
4898 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4899 .getIdentifier());
4900 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004901 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004902 }
4903 }
4904 return true;
4905 }
4906
4907 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004908 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004909 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4910 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004911 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004912 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004913 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004914 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004915 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004916 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4917 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004918 */
Robin Lee25e26452015-06-02 09:56:29 -07004919 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004920 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004921 if (mService != null) {
4922 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004923 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004924 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004925 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004926 }
4927 }
4928 }
4929
4930 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004931 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4932 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004933 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004934 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004935 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004936 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004937 */
Robin Lee25e26452015-06-02 09:56:29 -07004938 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004939 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004940 if (mService != null) {
4941 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004942 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004943 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004944 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004945 }
4946 }
4947 }
4948
4949 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004950 * Called by a profile or device owner to set the permitted accessibility services. When set by
4951 * a device owner or profile owner the restriction applies to all profiles of the user the
4952 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4953 * service. When zero or more packages have been added, accessiblity services that are not in
4954 * the list and not part of the system can not be enabled by the user.
4955 * <p>
4956 * Calling with a null value for the list disables the restriction so that all services can be
4957 * used, calling with an empty list only allows the builtin system's services.
4958 * <p>
4959 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004960 *
4961 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4962 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004963 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4964 * accessibility services enabled, that are not in the list.
4965 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004966 */
Robin Lee25e26452015-06-02 09:56:29 -07004967 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004968 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004969 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004970 if (mService != null) {
4971 try {
4972 return mService.setPermittedAccessibilityServices(admin, packageNames);
4973 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004974 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004975 }
4976 }
4977 return false;
4978 }
4979
4980 /**
4981 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004982 * <p>
4983 * An empty list means no accessibility services except system services are allowed. Null means
4984 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004985 *
4986 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4987 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004988 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004989 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004990 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004991 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004992 if (mService != null) {
4993 try {
4994 return mService.getPermittedAccessibilityServices(admin);
4995 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004996 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004997 }
4998 }
4999 return null;
5000 }
5001
5002 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005003 * Called by the system to check if a specific accessibility service is disabled by admin.
5004 *
5005 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5006 * @param packageName Accessibility service package name that needs to be checked.
5007 * @param userHandle user id the admin is running as.
5008 * @return true if the accessibility service is permitted, otherwise false.
5009 *
5010 * @hide
5011 */
5012 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5013 @NonNull String packageName, int userHandle) {
5014 if (mService != null) {
5015 try {
5016 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5017 userHandle);
5018 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005019 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005020 }
5021 }
5022 return false;
5023 }
5024
5025 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005026 * Returns the list of accessibility services permitted by the device or profiles
5027 * owners of this user.
5028 *
5029 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5030 * it will contain the intersection of the permitted lists for any device or profile
5031 * owners that apply to this user. It will also include any system accessibility services.
5032 *
5033 * @param userId which user to check for.
5034 * @return List of accessiblity service package names.
5035 * @hide
5036 */
5037 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005038 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005039 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005040 if (mService != null) {
5041 try {
5042 return mService.getPermittedAccessibilityServicesForUser(userId);
5043 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005044 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005045 }
5046 }
5047 return null;
5048 }
5049
5050 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005051 * Called by a profile or device owner to set the permitted input methods services. When set by
5052 * a device owner or profile owner the restriction applies to all profiles of the user the
5053 * device owner or profile owner is an admin for. By default the user can use any input method.
5054 * When zero or more packages have been added, input method that are not in the list and not
5055 * part of the system can not be enabled by the user. This method will fail if it is called for
5056 * a admin that is not for the foreground user or a profile of the foreground user.
5057 * <p>
5058 * Calling with a null value for the list disables the restriction so that all input methods can
5059 * be used, calling with an empty list disables all but the system's own input methods.
5060 * <p>
5061 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005062 *
5063 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5064 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005065 * @return true if setting the restriction succeeded. It will fail if there are one or more
5066 * non-system input methods currently enabled that are not in the packageNames list.
5067 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005068 */
Robin Lee25e26452015-06-02 09:56:29 -07005069 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005070 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005071 if (mService != null) {
5072 try {
5073 return mService.setPermittedInputMethods(admin, packageNames);
5074 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005075 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005076 }
5077 }
5078 return false;
5079 }
5080
5081
5082 /**
5083 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005084 * <p>
5085 * An empty list means no input methods except system input methods are allowed. Null means all
5086 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005087 *
5088 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5089 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005090 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005091 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005092 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005093 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005094 if (mService != null) {
5095 try {
5096 return mService.getPermittedInputMethods(admin);
5097 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005098 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005099 }
5100 }
5101 return null;
5102 }
5103
5104 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005105 * Called by the system to check if a specific input method is disabled by admin.
5106 *
5107 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5108 * @param packageName Input method package name that needs to be checked.
5109 * @param userHandle user id the admin is running as.
5110 * @return true if the input method is permitted, otherwise false.
5111 *
5112 * @hide
5113 */
5114 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5115 @NonNull String packageName, int userHandle) {
5116 if (mService != null) {
5117 try {
5118 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5119 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005120 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005121 }
5122 }
5123 return false;
5124 }
5125
5126 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005127 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005128 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005129 *
5130 * <p>Null means all input methods are allowed, if a non-null list is returned
5131 * it will contain the intersection of the permitted lists for any device or profile
5132 * owners that apply to this user. It will also include any system input methods.
5133 *
5134 * @return List of input method package names.
5135 * @hide
5136 */
5137 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005138 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005139 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005140 if (mService != null) {
5141 try {
5142 return mService.getPermittedInputMethodsForCurrentUser();
5143 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005144 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005145 }
5146 }
5147 return null;
5148 }
5149
5150 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005151 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5152 * currently installed it.
5153 *
5154 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5155 *
5156 * @return List of package names to keep cached.
5157 * @hide
5158 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005159 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005160 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005161 if (mService != null) {
5162 try {
5163 return mService.getKeepUninstalledPackages(admin);
5164 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005165 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005166 }
5167 }
5168 return null;
5169 }
5170
5171 /**
5172 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5173 * currently installed it.
5174 *
5175 * <p>Please note that setting this policy does not imply that specified apps will be
5176 * automatically pre-cached.</p>
5177 *
5178 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5179 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005180 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005181 * @hide
5182 */
5183 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5184 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005185 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005186 if (mService != null) {
5187 try {
5188 mService.setKeepUninstalledPackages(admin, packageNames);
5189 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005190 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005191 }
5192 }
5193 }
5194
5195 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005196 * Called by a device owner to create a user with the specified name. The UserHandle returned
5197 * by this method should not be persisted as user handles are recycled as users are removed and
5198 * created. If you need to persist an identifier for this user, use
5199 * {@link UserManager#getSerialNumberForUser}.
5200 *
5201 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5202 * @param name the user's name
5203 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005204 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5205 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005206 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005207 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005208 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005209 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005210 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005211 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005212 return null;
5213 }
5214
5215 /**
Jason Monk03978a42014-06-10 15:05:30 -04005216 * Called by a device owner to create a user with the specified name. The UserHandle returned
5217 * by this method should not be persisted as user handles are recycled as users are removed and
5218 * created. If you need to persist an identifier for this user, use
5219 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5220 * immediately.
5221 *
5222 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5223 * as registered as an active admin on the new user. The profile owner package will be
5224 * installed on the new user if it already is installed on the device.
5225 *
5226 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5227 * profileOwnerComponent when onEnable is called.
5228 *
5229 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5230 * @param name the user's name
5231 * @param ownerName the human readable name of the organisation associated with this DPM.
5232 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5233 * the user.
5234 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5235 * on the new user.
5236 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005237 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5238 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005239 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005240 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005241 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005242 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005243 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005244 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005245 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005246 return null;
5247 }
5248
5249 /**
phweissa92e1212016-01-25 17:14:10 +01005250 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005251 */
5252 public static final int SKIP_SETUP_WIZARD = 0x0001;
5253
5254 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005255 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5256 * ephemeral.
5257 * @hide
5258 */
5259 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5260
5261 /**
phweissa92e1212016-01-25 17:14:10 +01005262 * Called by a device owner to create a user with the specified name and a given component of
5263 * the calling package as profile owner. The UserHandle returned by this method should not be
5264 * persisted as user handles are recycled as users are removed and created. If you need to
5265 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5266 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005267 * <p>
5268 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5269 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5270 * be registered as an active admin on the new user. The profile owner package will be installed
5271 * on the new user.
5272 * <p>
5273 * If the adminExtras are not null, they will be stored on the device until the user is started
5274 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005275 *
5276 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5277 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005278 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005279 * same package as admin, otherwise no user is created and an
5280 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005281 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005282 * user.
phweissa92e1212016-01-25 17:14:10 +01005283 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005284 * @see UserHandle
5285 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5286 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005287 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005288 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005289 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5290 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005291 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5292 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005293 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005294 try {
phweissa92e1212016-01-25 17:14:10 +01005295 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005296 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005297 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005298 }
phweiss343fb332016-01-25 14:48:59 +01005299 }
5300
5301 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005302 * Called by a device owner to remove a user and all associated data. The primary user can not
5303 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005304 *
5305 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5306 * @param userHandle the user to remove.
5307 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005308 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005309 */
Robin Lee25e26452015-06-02 09:56:29 -07005310 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005311 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005312 try {
5313 return mService.removeUser(admin, userHandle);
5314 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005315 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005316 }
5317 }
5318
5319 /**
Jason Monk582d9112014-07-09 19:57:08 -04005320 * Called by a device owner to switch the specified user to the foreground.
5321 *
5322 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5323 * @param userHandle the user to switch to; null will switch to primary.
5324 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005325 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005326 * @see Intent#ACTION_USER_FOREGROUND
5327 */
Robin Lee25e26452015-06-02 09:56:29 -07005328 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005329 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005330 try {
5331 return mService.switchUser(admin, userHandle);
5332 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005333 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005334 }
5335 }
5336
5337 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005338 * Retrieves the application restrictions for a given target application running in the calling
5339 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005340 * <p>
5341 * The caller must be a profile or device owner on that user, or the package allowed to manage
5342 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5343 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005344 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005345 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5346 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005347 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005348 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005349 * @param packageName The name of the package to fetch restricted settings of.
5350 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005351 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5352 * {@link Bundle} if no restrictions have been set.
5353 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005354 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005355 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005356 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005357 public @NonNull Bundle getApplicationRestrictions(
5358 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005359 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005360 if (mService != null) {
5361 try {
5362 return mService.getApplicationRestrictions(admin, packageName);
5363 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005364 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005365 }
5366 }
5367 return null;
5368 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005369
5370 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005371 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005372 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005373 * The calling device admin must be a profile or device owner; if it is not, a security
5374 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005375 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005376 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5377 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5378 * for the list of keys.
5379 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005380 */
Robin Lee25e26452015-06-02 09:56:29 -07005381 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005382 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005383 if (mService != null) {
5384 try {
5385 mService.setUserRestriction(admin, key, true);
5386 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005387 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005388 }
5389 }
5390 }
5391
5392 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005393 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005394 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005395 * The calling device admin must be a profile or device owner; if it is not, a security
5396 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005397 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005398 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5399 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5400 * for the list of keys.
5401 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005402 */
Robin Lee25e26452015-06-02 09:56:29 -07005403 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005404 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005405 if (mService != null) {
5406 try {
5407 mService.setUserRestriction(admin, key, false);
5408 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005409 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005410 }
5411 }
5412 }
Adam Connors010cfd42014-04-16 12:48:13 +01005413
5414 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005415 * Called by a profile or device owner to get user restrictions set with
5416 * {@link #addUserRestriction(ComponentName, String)}.
5417 * <p>
5418 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005419 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005420 * {@link UserManager#getUserRestrictions()}.
5421 *
5422 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005423 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005424 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005425 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005426 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005427 Bundle ret = null;
5428 if (mService != null) {
5429 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005430 ret = mService.getUserRestrictions(admin);
5431 } catch (RemoteException e) {
5432 throw e.rethrowFromSystemServer();
5433 }
5434 }
5435 return ret == null ? new Bundle() : ret;
5436 }
5437
5438 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005439 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5440 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005441 *
5442 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005443 * @param packageName The name of the package to hide or unhide.
5444 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005445 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005446 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005447 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005448 */
Robin Lee25e26452015-06-02 09:56:29 -07005449 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005450 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005451 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005452 if (mService != null) {
5453 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005454 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005455 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005456 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005457 }
5458 }
5459 return false;
5460 }
5461
5462 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005463 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005464 *
5465 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005466 * @param packageName The name of the package to retrieve the hidden status of.
5467 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005468 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005469 */
Robin Lee25e26452015-06-02 09:56:29 -07005470 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005471 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005472 if (mService != null) {
5473 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005474 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005475 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005476 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005477 }
5478 }
5479 return false;
5480 }
5481
5482 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005483 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005484 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005485 *
5486 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005487 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005488 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005489 */
Robin Lee25e26452015-06-02 09:56:29 -07005490 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005491 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005492 if (mService != null) {
5493 try {
5494 mService.enableSystemApp(admin, packageName);
5495 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005496 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005497 }
5498 }
5499 }
5500
5501 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005502 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5503 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005504 *
5505 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5506 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005507 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005508 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005509 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005510 */
Robin Lee25e26452015-06-02 09:56:29 -07005511 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005512 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005513 if (mService != null) {
5514 try {
5515 return mService.enableSystemAppWithIntent(admin, intent);
5516 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005517 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005518 }
5519 }
5520 return 0;
5521 }
5522
5523 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005524 * Called by a device owner or profile owner to disable account management for a specific type
5525 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005526 * <p>
5527 * The calling device admin must be a device owner or profile owner. If it is not, a security
5528 * exception will be thrown.
5529 * <p>
5530 * When account management is disabled for an account type, adding or removing an account of
5531 * that type will not be possible.
5532 * <p>
5533 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005534 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5535 * management for a specific type is disabled.
5536 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005537 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5538 * @param accountType For which account management is disabled or enabled.
5539 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005540 * enabled (false).
5541 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005542 */
Robin Lee25e26452015-06-02 09:56:29 -07005543 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005544 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005545 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005546 if (mService != null) {
5547 try {
5548 mService.setAccountManagementDisabled(admin, accountType, disabled);
5549 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005550 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005551 }
5552 }
5553 }
5554
5555 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005556 * Gets the array of accounts for which account management is disabled by the profile owner.
5557 *
5558 * <p> Account management can be disabled/enabled by calling
5559 * {@link #setAccountManagementDisabled}.
5560 *
5561 * @return a list of account types for which account management has been disabled.
5562 *
5563 * @see #setAccountManagementDisabled
5564 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005565 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005566 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005567 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005568 }
5569
5570 /**
5571 * @see #getAccountTypesWithManagementDisabled()
5572 * @hide
5573 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005574 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005575 if (mService != null) {
5576 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005577 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005578 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005579 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005580 }
5581 }
5582
5583 return null;
5584 }
justinzhang511e0d82014-03-24 16:09:24 -04005585
5586 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005587 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005588 * <p>
5589 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5590 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5591 * package list results in locked tasks belonging to those packages to be finished. This
5592 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005593 *
Jason Monkd7b86212014-06-16 13:15:38 -04005594 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005595 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005596 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005597 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005598 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5599 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005600 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005601 */
Robin Lee25e26452015-06-02 09:56:29 -07005602 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005603 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005604 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005605 if (mService != null) {
5606 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005607 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005608 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005609 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005610 }
5611 }
5612 }
5613
5614 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005615 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005616 *
5617 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005618 * @hide
5619 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005620 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005621 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005622 if (mService != null) {
5623 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005624 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005625 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005626 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005627 }
5628 }
5629 return null;
5630 }
5631
5632 /**
5633 * This function lets the caller know whether the given component is allowed to start the
5634 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005635 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005636 */
Jason Monkd7b86212014-06-16 13:15:38 -04005637 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005638 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005639 if (mService != null) {
5640 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005641 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005642 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005643 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005644 }
5645 }
5646 return false;
5647 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005648
5649 /**
5650 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5651 * 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 -07005652 * <p>
5653 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005654 * <ul>
5655 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5656 * <li>{@link Settings.Global#AUTO_TIME}</li>
5657 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005658 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005659 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005660 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005661 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5662 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5663 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5664 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5665 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005666 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005667 * <p>
5668 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005669 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005670 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5671 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5672 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005673 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005674 * <li>{@link Settings.Global#MODE_RINGER}. Use
5675 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005676 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005677 * <li>{@link Settings.Global#WIFI_ON}. Use
5678 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005679 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005680 *
5681 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5682 * @param setting The name of the setting to update.
5683 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005684 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005685 */
Robin Lee25e26452015-06-02 09:56:29 -07005686 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005687 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005688 if (mService != null) {
5689 try {
5690 mService.setGlobalSetting(admin, setting, value);
5691 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005692 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005693 }
5694 }
5695 }
5696
5697 /**
5698 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5699 * that the value of the setting is in the correct form for the setting type should be performed
5700 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005701 * <p>
5702 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005703 * <ul>
5704 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005705 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005706 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5707 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005708 * <p>
5709 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005710 * <ul>
5711 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5712 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005713 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005714 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5715 * @param setting The name of the setting to update.
5716 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005717 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005718 */
Robin Lee25e26452015-06-02 09:56:29 -07005719 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005720 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005721 if (mService != null) {
5722 try {
5723 mService.setSecureSetting(admin, setting, value);
5724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005725 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005726 }
5727 }
5728 }
5729
Amith Yamasanif20d6402014-05-24 15:34:37 -07005730 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005731 * Designates a specific service component as the provider for making permission requests of a
5732 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005733 * <p/>
5734 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005735 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005736 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005737 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005738 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5739 * provider previously assigned.
5740 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005741 */
Robin Lee25e26452015-06-02 09:56:29 -07005742 public void setRestrictionsProvider(@NonNull ComponentName admin,
5743 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005744 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005745 if (mService != null) {
5746 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005747 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005748 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005749 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005750 }
5751 }
5752 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005753
5754 /**
5755 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005756 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005757 *
5758 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5759 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005760 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005761 */
Robin Lee25e26452015-06-02 09:56:29 -07005762 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005763 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005764 if (mService != null) {
5765 try {
5766 mService.setMasterVolumeMuted(admin, on);
5767 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005768 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005769 }
5770 }
5771 }
5772
5773 /**
5774 * Called by profile or device owners to check whether the master volume mute is on or off.
5775 *
5776 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5777 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005778 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005779 */
Robin Lee25e26452015-06-02 09:56:29 -07005780 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005781 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005782 if (mService != null) {
5783 try {
5784 return mService.isMasterVolumeMuted(admin);
5785 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005786 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005787 }
5788 }
5789 return false;
5790 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005791
5792 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005793 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005794 *
5795 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5796 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005797 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005798 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005799 */
Robin Lee25e26452015-06-02 09:56:29 -07005800 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005801 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005802 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005803 if (mService != null) {
5804 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005805 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005806 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005807 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005808 }
5809 }
5810 }
5811
5812 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005813 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005814 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005815 * <p>
5816 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005817 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5818 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5819 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005820 *
Robin Lee25e26452015-06-02 09:56:29 -07005821 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005822 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005823 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005824 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005825 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005826 */
Robin Lee25e26452015-06-02 09:56:29 -07005827 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005828 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005829 if (mService != null) {
5830 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005831 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005832 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005833 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005834 }
5835 }
5836 return false;
5837 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005838
5839 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005840 * Called by the profile owner of a managed profile to enable widget providers from a given
5841 * package to be available in the parent profile. As a result the user will be able to add
5842 * widgets from the white-listed package running under the profile to a widget host which runs
5843 * under the parent profile, for example the home screen. Note that a package may have zero or
5844 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005845 * <p>
5846 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005847 *
5848 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5849 * @param packageName The package from which widget providers are white-listed.
5850 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005851 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005852 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5853 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5854 */
Robin Lee25e26452015-06-02 09:56:29 -07005855 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005856 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005857 if (mService != null) {
5858 try {
5859 return mService.addCrossProfileWidgetProvider(admin, packageName);
5860 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005861 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005862 }
5863 }
5864 return false;
5865 }
5866
5867 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005868 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005869 * package to be available in the parent profile. For this method to take effect the package
5870 * should have been added via
5871 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005872 * <p>
5873 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005874 *
5875 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005876 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005877 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005878 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005879 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5880 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5881 */
Esteban Talavera62399912016-01-11 15:37:55 +00005882 public boolean removeCrossProfileWidgetProvider(
5883 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005884 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005885 if (mService != null) {
5886 try {
5887 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5888 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005889 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005890 }
5891 }
5892 return false;
5893 }
5894
5895 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005896 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005897 * available in the parent profile.
5898 *
5899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5900 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005901 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5902 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005903 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005904 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005905 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005906 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005907 if (mService != null) {
5908 try {
5909 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5910 if (providers != null) {
5911 return providers;
5912 }
5913 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005914 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005915 }
5916 }
5917 return Collections.emptyList();
5918 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005919
5920 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005921 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005922 *
5923 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5924 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005925 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005926 */
Robin Lee25e26452015-06-02 09:56:29 -07005927 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005928 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005929 try {
5930 mService.setUserIcon(admin, icon);
5931 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005932 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005933 }
5934 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005935
5936 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005937 * Called by device owners to set a local system update policy. When a new policy is set,
5938 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005939 *
Robin Lee25e26452015-06-02 09:56:29 -07005940 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005941 * components in the device owner package can set system update policies and the most
5942 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005943 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005944 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005945 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005946 */
Robin Lee25e26452015-06-02 09:56:29 -07005947 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005948 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005949 if (mService != null) {
5950 try {
Robin Lee25e26452015-06-02 09:56:29 -07005951 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005952 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005953 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005954 }
5955 }
5956 }
5957
5958 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005959 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005960 *
Robin Lee25e26452015-06-02 09:56:29 -07005961 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005962 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005963 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005964 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005965 if (mService != null) {
5966 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005967 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005968 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005969 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005970 }
5971 }
5972 return null;
5973 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005974
5975 /**
5976 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005977 * <p>
5978 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5979 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5980 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5981 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005982 *
5983 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005984 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005985 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005986 * place. {@code true} otherwise.
5987 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005988 */
Robin Lee25e26452015-06-02 09:56:29 -07005989 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005990 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005991 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005992 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005993 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005994 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005995 }
5996 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005997
5998 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005999 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006000 * notifications, quick settings and other screen overlays that allow escaping from a single use
6001 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006002 *
6003 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01006004 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006005 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
6006 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00006007 */
Robin Lee25e26452015-06-02 09:56:29 -07006008 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006009 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00006010 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01006011 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00006012 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006013 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006014 }
6015 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006016
6017 /**
6018 * Callable by the system update service to notify device owners about pending updates.
6019 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6020 * permission.
6021 *
6022 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
6023 * when the current pending update was first available. -1 if no update is available.
6024 * @hide
6025 */
6026 @SystemApi
6027 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006028 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006029 if (mService != null) {
6030 try {
6031 mService.notifyPendingSystemUpdate(updateReceivedTime);
6032 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006033 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006034 }
6035 }
6036 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006037
6038 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006039 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006040 * requests by applications. The policy can allow for normal operation which prompts the user to
6041 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6042 * by an application. This also applies to new permissions declared by app updates. When a
6043 * permission is denied or granted this way, the effect is equivalent to setting the permission
6044 * grant state via {@link #setPermissionGrantState}.
6045 * <p/>
6046 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006047 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006048 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006049 * @param admin Which profile or device owner this request is associated with.
6050 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006051 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6052 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006053 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006054 */
Robin Lee25e26452015-06-02 09:56:29 -07006055 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006056 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006057 try {
6058 mService.setPermissionPolicy(admin, policy);
6059 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006060 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006061 }
6062 }
6063
6064 /**
6065 * Returns the current runtime permission policy set by the device or profile owner. The
6066 * default is {@link #PERMISSION_POLICY_PROMPT}.
6067 * @param admin Which profile or device owner this request is associated with.
6068 * @return the current policy for future permission requests.
6069 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006070 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006071 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006072 try {
6073 return mService.getPermissionPolicy(admin);
6074 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006075 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006076 }
6077 }
6078
6079 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006080 * Sets the grant state of a runtime permission for a specific application. The state can be
6081 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6082 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6083 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6084 * the permission is granted and the user cannot manage it through the UI. This might affect all
6085 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006086 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006087 * <p/>
6088 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6089 * the permission. It retains the previous grant, if any.
6090 * <p/>
6091 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006092 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006093 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006094 * @param admin Which profile or device owner this request is associated with.
6095 * @param packageName The application to grant or revoke a permission to.
6096 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006097 * @param grantState The permission grant state which is one of
6098 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6099 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006100 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006101 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006102 * @see #PERMISSION_GRANT_STATE_DENIED
6103 * @see #PERMISSION_GRANT_STATE_DEFAULT
6104 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006105 */
Robin Lee25e26452015-06-02 09:56:29 -07006106 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006107 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006108 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006109 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006110 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006111 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006112 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006113 }
6114 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006115
6116 /**
6117 * Returns the current grant state of a runtime permission for a specific application.
6118 *
6119 * @param admin Which profile or device owner this request is associated with.
6120 * @param packageName The application to check the grant state for.
6121 * @param permission The permission to check for.
6122 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006123 * has not set a grant state, the return value is
6124 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6125 * permission is currently granted for the package.
6126 * <p/>
6127 * If a grant state was set by the profile or device owner, then the return value will
6128 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6129 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6130 * currently denied or granted.
6131 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006132 * @see #setPermissionGrantState(ComponentName, String, String, int)
6133 * @see PackageManager#checkPermission(String, String)
6134 */
Robin Lee25e26452015-06-02 09:56:29 -07006135 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006136 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006137 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006138 try {
6139 return mService.getPermissionGrantState(admin, packageName, permission);
6140 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006141 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006142 }
6143 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006144
6145 /**
6146 * Returns if provisioning a managed profile or device is possible or not.
6147 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6148 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006149 * @return if provisioning a managed profile or device is possible or not.
6150 * @throws IllegalArgumentException if the supplied action is not valid.
6151 */
6152 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006153 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006154 try {
6155 return mService.isProvisioningAllowed(action);
6156 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006157 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006158 }
6159 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006160
6161 /**
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006162 * Checks if provisioning a managed profile or device is possible and returns one of the
6163 * {@link ProvisioningPreCondition}.
6164 *
6165 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6166 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6167 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6168 * {@link #ACTION_PROVISION_MANAGED_USER}
6169 * @hide
6170 */
6171 public @ProvisioningPreCondition int checkProvisioningPreCondition(String action) {
6172 try {
6173 return mService.checkProvisioningPreCondition(action);
6174 } catch (RemoteException re) {
6175 throw re.rethrowFromSystemServer();
6176 }
6177 }
6178
6179 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006180 * Return if this user is a managed profile of another user. An admin can become the profile
6181 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006182 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006183 * @param admin Which profile owner this request is associated with.
6184 * @return if this user is a managed profile of another user.
6185 */
6186 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006187 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006188 try {
6189 return mService.isManagedProfile(admin);
6190 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006191 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006192 }
6193 }
6194
6195 /**
6196 * @hide
6197 * Return if this user is a system-only user. An admin can manage a device from a system only
6198 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6199 * @param admin Which device owner this request is associated with.
6200 * @return if this user is a system-only user.
6201 */
6202 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6203 try {
6204 return mService.isSystemOnlyUser(admin);
6205 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006206 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006207 }
6208 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006209
6210 /**
6211 * Called by device owner to get the MAC address of the Wi-Fi device.
6212 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006213 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006214 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6215 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6216 * <p>
6217 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6218 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006219 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006220 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006221 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006222 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006223 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006224 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006225 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006226 }
6227 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006228
6229 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006230 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6231 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006232 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006233 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006234 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006235 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006236 */
6237 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006238 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006239 try {
6240 mService.reboot(admin);
6241 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006242 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006243 }
6244 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006245
6246 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006247 * Called by a device admin to set the short support message. This will be displayed to the user
6248 * in settings screens where funtionality has been disabled by the admin. The message should be
6249 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6250 * someone@example.com for support." If the message is longer than 200 characters it may be
6251 * truncated.
6252 * <p>
6253 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006254 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6255 * and set a new version of this string accordingly.
6256 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006257 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006258 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006259 * @param message Short message to be displayed to the user in settings or null to clear the
6260 * existing message.
6261 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006262 */
6263 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006264 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006265 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006266 if (mService != null) {
6267 try {
6268 mService.setShortSupportMessage(admin, message);
6269 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006270 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006271 }
6272 }
6273 }
6274
6275 /**
6276 * Called by a device admin to get the short support message.
6277 *
6278 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006279 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6280 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006281 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006282 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006283 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006284 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006285 if (mService != null) {
6286 try {
6287 return mService.getShortSupportMessage(admin);
6288 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006289 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006290 }
6291 }
6292 return null;
6293 }
6294
6295 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006296 * Called by a device admin to set the long support message. This will be displayed to the user
6297 * in the device administators settings screen.
6298 * <p>
6299 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006300 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6301 * and set a new version of this string accordingly.
6302 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006303 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006304 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006305 * @param message Long message to be displayed to the user in settings or null to clear the
6306 * existing message.
6307 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006308 */
6309 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006310 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006311 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006312 if (mService != null) {
6313 try {
6314 mService.setLongSupportMessage(admin, message);
6315 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006316 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006317 }
6318 }
6319 }
6320
6321 /**
6322 * Called by a device admin to get the long support message.
6323 *
6324 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006325 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6326 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006327 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006328 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006329 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006330 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006331 if (mService != null) {
6332 try {
6333 return mService.getLongSupportMessage(admin);
6334 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006335 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006336 }
6337 }
6338 return null;
6339 }
6340
6341 /**
6342 * Called by the system to get the short support message.
6343 *
6344 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6345 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006346 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006347 *
6348 * @hide
6349 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006350 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006351 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006352 if (mService != null) {
6353 try {
6354 return mService.getShortSupportMessageForUser(admin, userHandle);
6355 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006356 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006357 }
6358 }
6359 return null;
6360 }
6361
6362
6363 /**
6364 * Called by the system to get the long support message.
6365 *
6366 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6367 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006368 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006369 *
6370 * @hide
6371 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006372 public @Nullable CharSequence getLongSupportMessageForUser(
6373 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006374 if (mService != null) {
6375 try {
6376 return mService.getLongSupportMessageForUser(admin, userHandle);
6377 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006378 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006379 }
6380 }
6381 return null;
6382 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006383
6384 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006385 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6386 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006387 *
6388 * <p>The following methods are supported for the parent instance, all other methods will
6389 * throw a SecurityException when called on the parent instance:
6390 * <ul>
6391 * <li>{@link #getPasswordQuality}</li>
6392 * <li>{@link #setPasswordQuality}</li>
6393 * <li>{@link #getPasswordMinimumLength}</li>
6394 * <li>{@link #setPasswordMinimumLength}</li>
6395 * <li>{@link #getPasswordMinimumUpperCase}</li>
6396 * <li>{@link #setPasswordMinimumUpperCase}</li>
6397 * <li>{@link #getPasswordMinimumLowerCase}</li>
6398 * <li>{@link #setPasswordMinimumLowerCase}</li>
6399 * <li>{@link #getPasswordMinimumLetters}</li>
6400 * <li>{@link #setPasswordMinimumLetters}</li>
6401 * <li>{@link #getPasswordMinimumNumeric}</li>
6402 * <li>{@link #setPasswordMinimumNumeric}</li>
6403 * <li>{@link #getPasswordMinimumSymbols}</li>
6404 * <li>{@link #setPasswordMinimumSymbols}</li>
6405 * <li>{@link #getPasswordMinimumNonLetter}</li>
6406 * <li>{@link #setPasswordMinimumNonLetter}</li>
6407 * <li>{@link #getPasswordHistoryLength}</li>
6408 * <li>{@link #setPasswordHistoryLength}</li>
6409 * <li>{@link #getPasswordExpirationTimeout}</li>
6410 * <li>{@link #setPasswordExpirationTimeout}</li>
6411 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006412 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006413 * <li>{@link #isActivePasswordSufficient}</li>
6414 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6415 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6416 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6417 * <li>{@link #getMaximumTimeToLock}</li>
6418 * <li>{@link #setMaximumTimeToLock}</li>
6419 * <li>{@link #lockNow}</li>
6420 * <li>{@link #getKeyguardDisabledFeatures}</li>
6421 * <li>{@link #setKeyguardDisabledFeatures}</li>
6422 * <li>{@link #getTrustAgentConfiguration}</li>
6423 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006424 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6425 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006426 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006427 *
6428 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006429 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006430 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006431 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006432 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006433 try {
6434 if (!mService.isManagedProfile(admin)) {
6435 throw new SecurityException("The current user does not have a parent profile.");
6436 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006437 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006438 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006439 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006440 }
6441 }
6442
6443 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006444 * Called by device owner to control the security logging feature. Logging can only be
6445 * enabled on single user devices where the sole user is managed by the device owner.
6446 *
6447 * <p> Security logs contain various information intended for security auditing purposes.
6448 * See {@link SecurityEvent} for details.
6449 *
6450 * <p>There must be only one user on the device, managed by the device owner.
6451 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006452 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006453 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006454 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006455 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006456 * @see #retrieveSecurityLogs
6457 */
6458 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006459 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006460 try {
6461 mService.setSecurityLoggingEnabled(admin, enabled);
6462 } catch (RemoteException re) {
6463 throw re.rethrowFromSystemServer();
6464 }
6465 }
6466
6467 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006468 * Return whether security logging is enabled or not by the device owner.
6469 *
6470 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6471 * thrown.
6472 *
6473 * @param admin Which device owner this request is associated with.
6474 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6475 * @throws SecurityException if {@code admin} is not a device owner.
6476 */
6477 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006478 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006479 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006480 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006481 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006482 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006483 }
6484 }
6485
6486 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006487 * Called by device owner to retrieve all new security logging entries since the last call to
6488 * this API after device boots.
6489 *
6490 * <p> Access to the logs is rate limited and it will only return new logs after the device
6491 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6492 *
6493 * <p>There must be only one user on the device, managed by the device owner.
6494 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006495 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006496 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006497 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6498 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006499 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006500 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006501 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006502 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006503 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006504 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006505 if (list != null) {
6506 return list.getList();
6507 } else {
6508 // Rate limit exceeded.
6509 return null;
6510 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006511 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006512 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006513 }
6514 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006515
6516 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006517 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6518 * profile.
6519 *
6520 * @hide
6521 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006522 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006523 mContext.checkSelfPermission(
6524 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6525 if (!uInfo.isManagedProfile()) {
6526 throw new SecurityException("The user " + uInfo.id
6527 + " does not have a parent profile.");
6528 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006529 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006530 }
6531
6532 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006533 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006534 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006535 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6536 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6537 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6538 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006539 * <p>
6540 * There must be only one user on the device, managed by the device owner. Otherwise a
6541 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006542 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006543 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006544 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6545 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006546 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006547 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006548 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6549 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006550 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006551 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006552 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006553 if (list != null) {
6554 return list.getList();
6555 } else {
6556 return null;
6557 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006558 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006559 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006560 }
6561 }
6562
6563 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006564 * Called by a profile owner of a managed profile to set the color used for customization. This
6565 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006566 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006567 * <p>
6568 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006569 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6570 *
6571 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006572 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006573 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006574 */
6575 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006576 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006577 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006578 // always enforce alpha channel to have 100% opacity
6579 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006580 mService.setOrganizationColor(admin, color);
6581 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006582 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006583 }
6584 }
6585
6586 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006587 * @hide
6588 *
6589 * Sets the color used for customization.
6590 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006591 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006592 * @param userId which user to set the color to.
6593 * @RequiresPermission(allOf = {
6594 * Manifest.permission.MANAGE_USERS,
6595 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6596 */
6597 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6598 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006599 // always enforce alpha channel to have 100% opacity
6600 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006601 mService.setOrganizationColorForUser(color, userId);
6602 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006603 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006604 }
6605 }
6606
6607 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006608 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6609 * This color is used as background color of the confirm credentials screen for that user.
6610 *
6611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006612 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006613 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006614 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006615 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006616 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006617 try {
6618 return mService.getOrganizationColor(admin);
6619 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006620 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006621 }
6622 }
6623
6624 /**
6625 * @hide
6626 * Retrieve the customization color for a given user.
6627 *
6628 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006629 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006630 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006631 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006632 try {
6633 return mService.getOrganizationColorForUser(userHandle);
6634 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006635 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006636 }
6637 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006638
6639 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006640 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006641 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006642 * <p>
6643 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006644 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6645 * and set a new version of this string accordingly.
6646 *
6647 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6648 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006649 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006650 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006651 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006652 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006653 try {
6654 mService.setOrganizationName(admin, title);
6655 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006656 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006657 }
6658 }
6659
6660 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006661 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6662 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006663 *
6664 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6665 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006666 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006667 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006668 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006669 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006670 try {
6671 return mService.getOrganizationName(admin);
6672 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006673 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006674 }
6675 }
6676
6677 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006678 * Called by the system to retrieve the name of the organization managing the device.
6679 *
6680 * @return The organization name or {@code null} if none is set.
6681 * @throws SecurityException if the caller is not the device owner, does not hold the
6682 * MANAGE_USERS permission and is not the system.
6683 *
6684 * @hide
6685 */
6686 @SystemApi
6687 @TestApi
6688 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6689 try {
6690 return mService.getDeviceOwnerOrganizationName();
6691 } catch (RemoteException re) {
6692 throw re.rethrowFromSystemServer();
6693 }
6694 }
6695
6696 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006697 * Retrieve the default title message used in the confirm credentials screen for a given user.
6698 *
6699 * @param userHandle The user id of the user we're interested in.
6700 * @return The organization name or {@code null} if none is set.
6701 *
6702 * @hide
6703 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006704 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006705 try {
6706 return mService.getOrganizationNameForUser(userHandle);
6707 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006708 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006709 }
6710 }
6711
6712 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006713 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6714 * return {@link #STATE_USER_UNMANAGED}
6715 * @hide
6716 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006717 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006718 @UserProvisioningState
6719 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006720 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006721 if (mService != null) {
6722 try {
6723 return mService.getUserProvisioningState();
6724 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006725 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006726 }
6727 }
6728 return STATE_USER_UNMANAGED;
6729 }
6730
6731 /**
6732 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6733 *
6734 * @param state to store
6735 * @param userHandle for user
6736 * @hide
6737 */
6738 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6739 if (mService != null) {
6740 try {
6741 mService.setUserProvisioningState(state, userHandle);
6742 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006743 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006744 }
6745 }
6746 }
6747
6748 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006749 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6750 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006751 *
6752 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006753 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6754 *
6755 * @throws NullPointerException if {@code ids} is null or contains null elements.
6756 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006757 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006758 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006759 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006760 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006761 mService.setAffiliationIds(admin, ids);
6762 } catch (RemoteException e) {
6763 throw e.rethrowFromSystemServer();
6764 }
6765 }
6766
6767 /**
6768 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6769 * empty list if none have been set.
6770 */
6771 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6772 throwIfParentInstance("getAffiliationIds");
6773 try {
6774 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006775 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006776 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006777 }
6778 }
6779
6780 /**
6781 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006782 * Returns whether this user/profile is affiliated with the device.
6783 * <p>
6784 * By definition, the user that the device owner runs on is always affiliated with the device.
6785 * Any other user/profile is considered affiliated with the device if the set specified by its
6786 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006787 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006788 */
6789 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006790 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006791 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006792 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006793 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006794 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006795 }
6796 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006797
6798 /**
6799 * @hide
6800 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6801 * to be started
6802 * @param packageName the package to check for
6803 * @return whether the uninstall intent for {@code packageName} is pending
6804 */
6805 public boolean isUninstallInQueue(String packageName) {
6806 try {
6807 return mService.isUninstallInQueue(packageName);
6808 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006809 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006810 }
6811 }
6812
6813 /**
6814 * @hide
6815 * @param packageName the package containing active DAs to be uninstalled
6816 */
6817 public void uninstallPackageWithActiveAdmins(String packageName) {
6818 try {
6819 mService.uninstallPackageWithActiveAdmins(packageName);
6820 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006821 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006822 }
6823 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006824
Kenny Guy38dcca52016-04-19 13:09:18 +01006825 /**
6826 * @hide
6827 * Remove a test admin synchronously without sending it a broadcast about being removed.
6828 * If the admin is a profile owner or device owner it will still be removed.
6829 *
6830 * @param userHandle user id to remove the admin for.
6831 * @param admin The administration compononent to remove.
6832 * @throws SecurityException if the caller is not shell / root or the admin package
6833 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6834 */
6835 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6836 try {
6837 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6838 } catch (RemoteException re) {
6839 throw re.rethrowFromSystemServer();
6840 }
6841 }
6842
Mahaver Chopra790d1982016-07-07 16:06:49 +01006843 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006844 * Returns whether the device has been provisioned.
6845 *
6846 * <p>Not for use by third-party applications.
6847 *
Mahaver Chopra790d1982016-07-07 16:06:49 +01006848 * @hide
Mahaver Chopra790d1982016-07-07 16:06:49 +01006849 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006850 @SystemApi
Mahaver Chopra790d1982016-07-07 16:06:49 +01006851 public boolean isDeviceProvisioned() {
6852 try {
6853 return mService.isDeviceProvisioned();
6854 } catch (RemoteException re) {
6855 throw re.rethrowFromSystemServer();
6856 }
6857 }
6858
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006859 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006860 * Writes that the provisioning configuration has been applied.
6861 *
6862 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS}
6863 * permission.
6864 *
6865 * <p>Not for use by third-party applications.
6866 *
6867 * @hide
6868 */
6869 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006870 public void setDeviceProvisioningConfigApplied() {
6871 try {
6872 mService.setDeviceProvisioningConfigApplied();
6873 } catch (RemoteException re) {
6874 throw re.rethrowFromSystemServer();
6875 }
6876 }
6877
6878 /**
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006879 * Returns whether the provisioning configuration has been applied.
6880 *
6881 * <p>The caller must hold the {@link android.Manifest.permission#MANAGE_USERS} permission.
6882 *
6883 * <p>Not for use by third-party applications.
6884 *
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006885 * @return whether the provisioning configuration has been applied.
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006886 *
6887 * @hide
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006888 */
Lenka Trochtova5291ee72016-11-28 16:38:23 +01006889 @SystemApi
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006890 public boolean isDeviceProvisioningConfigApplied() {
6891 try {
6892 return mService.isDeviceProvisioningConfigApplied();
6893 } catch (RemoteException re) {
6894 throw re.rethrowFromSystemServer();
6895 }
6896 }
6897
Victor Chang9bfc65f2016-08-15 12:27:09 +01006898 /**
6899 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006900 * Force update user setup completed status. This API has no effect on user build.
6901 * @throws {@link SecurityException} if the caller has no
6902 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6903 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006904 */
6905 public void forceUpdateUserSetupComplete() {
6906 try {
6907 mService.forceUpdateUserSetupComplete();
6908 } catch (RemoteException re) {
6909 throw re.rethrowFromSystemServer();
6910 }
6911 }
6912
Benjamin Franzbc33c822016-04-15 08:57:52 +01006913 private void throwIfParentInstance(String functionName) {
6914 if (mParentInstance) {
6915 throw new SecurityException(functionName + " cannot be called on the parent instance");
6916 }
6917 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006918
6919 /**
6920 * @hide
6921 * Enable backup service.
6922 * <p>This includes all backup and restore mechanisms.
6923 * Setting this to {@code false} will make backup service no-op or return empty results.
6924 *
6925 * <p>There must be only one user on the device, managed by the device owner.
6926 * Otherwise a {@link SecurityException} will be thrown.
6927 *
6928 * <p>Backup service is off by default when device owner is present.
6929 */
6930 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6931 try {
6932 mService.setBackupServiceEnabled(admin, enabled);
6933 } catch (RemoteException re) {
6934 throw re.rethrowFromSystemServer();
6935 }
6936 }
6937
6938 /**
6939 * @hide
6940 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6941 */
6942 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6943 try {
6944 return mService.isBackupServiceEnabled(admin);
6945 } catch (RemoteException re) {
6946 throw re.rethrowFromSystemServer();
6947 }
6948 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006949
6950 /**
6951 * Called by a device owner to control the network logging feature. Logging can only be
6952 * enabled on single user devices where the sole user is managed by the device owner. If a new
6953 * user is added on the device, logging is disabled.
6954 *
6955 * <p> Network logs contain DNS lookup and connect() library call events.
6956 *
6957 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6958 * @param enabled whether network logging should be enabled or not.
6959 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006960 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006961 */
6962 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
6963 throwIfParentInstance("setNetworkLoggingEnabled");
6964 try {
6965 mService.setNetworkLoggingEnabled(admin, enabled);
6966 } catch (RemoteException re) {
6967 throw re.rethrowFromSystemServer();
6968 }
6969 }
6970
6971 /**
6972 * Return whether network logging is enabled by a device owner.
6973 *
phweissa4e169e2016-11-24 16:20:57 +01006974 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
6975 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006976 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
phweissa4e169e2016-11-24 16:20:57 +01006977 * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
6978 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006979 */
phweissa4e169e2016-11-24 16:20:57 +01006980 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006981 throwIfParentInstance("isNetworkLoggingEnabled");
6982 try {
6983 return mService.isNetworkLoggingEnabled(admin);
6984 } catch (RemoteException re) {
6985 throw re.rethrowFromSystemServer();
6986 }
6987 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006988
6989 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006990 * Called by device owner to retrieve the most recent batch of network logging events.
6991 * A device owner has to provide a batchToken provided as part of
6992 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
6993 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006994 *
6995 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
6996 *
6997 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
6998 *
6999 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
7000 * after the device device owner has been notified via
7001 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
7002 *
7003 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007004 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007005 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007006 * {@code null} if the batch represented by batchToken is no longer available or if
7007 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007008 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007009 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007010 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007011 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
7012 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007013 throwIfParentInstance("retrieveNetworkLogs");
7014 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00007015 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01007016 } catch (RemoteException re) {
7017 throw re.rethrowFromSystemServer();
7018 }
7019 }
Tony Mak46aabe52016-11-14 12:53:06 +00007020
7021 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007022 * Called by a device owner to bind to a service from a profile owner of a managed profile or
7023 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
7024 * device/profile owners are allowed to bind to services of another profile/device owner.
7025 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00007026 * The service must be unexported. Note that the {@link Context} used to obtain this
7027 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
7028 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007029 *
Tony Mak46aabe52016-11-14 12:53:06 +00007030 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7031 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7032 * explicit component name or a package name to match an
7033 * {@link IntentFilter} published by a service.
7034 * @param conn Receives information as the service is started and stopped. This must be a
7035 * valid {@link ServiceConnection} object; it must not be {@code null}.
7036 * @param flags Operation options for the binding operation. See
7037 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007038 * @param targetUser Which user to bind to. Must be one of the users returned by
7039 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7040 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007041 * @return If you have successfully bound to the service, {@code true} is returned;
7042 * {@code false} is returned if the connection is not made and you will not
7043 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007044 *
Tony Mak46aabe52016-11-14 12:53:06 +00007045 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007046 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007047 */
7048 public boolean bindDeviceAdminServiceAsUser(
7049 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7050 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7051 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7052 // Keep this in sync with ContextImpl.bindServiceCommon.
7053 try {
7054 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
7055 serviceIntent.prepareToLeaveProcess(mContext);
7056 return mService.bindDeviceAdminServiceAsUser(admin,
7057 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7058 sd, flags, targetUser.getIdentifier());
7059 } catch (RemoteException re) {
7060 throw re.rethrowFromSystemServer();
7061 }
7062 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007063
7064 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007065 * Returns the list of target users that the calling device or profile owner can use when
7066 * calling {@link #bindDeviceAdminServiceAsUser}.
7067 * <p>
7068 * A device owner can bind to a service from a profile owner of a managed profile and
7069 * vice versa, provided that:
7070 * <ul>
7071 * <li>Both belong to the same package name.
7072 * <li>The managed profile is a profile of the user where the device owner is set.
7073 * See {@link UserManager#getUserProfiles()}
7074 * <li>Both users are affiliated.
7075 * STOPSHIP(b/32326223) Add reference to setAffiliationIds here once public.
7076 * </ul>
7077 */
7078 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7079 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7080 try {
7081 return mService.getBindDeviceAdminTargetUsers(admin);
7082 } catch (RemoteException re) {
7083 throw re.rethrowFromSystemServer();
7084 }
7085 }
7086
7087 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007088 * Called by the system to get the time at which the device owner last retrieved security
7089 * logging entries.
7090 *
7091 * @return the time at which the device owner most recently retrieved security logging entries,
7092 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007093 * @throws SecurityException if the caller is not the device owner, does not hold the
7094 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007095 *
7096 * @hide
7097 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007098 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007099 public long getLastSecurityLogRetrievalTime() {
7100 try {
7101 return mService.getLastSecurityLogRetrievalTime();
7102 } catch (RemoteException re) {
7103 throw re.rethrowFromSystemServer();
7104 }
7105 }
7106
7107 /**
7108 * Called by the system to get the time at which the device owner last requested a bug report.
7109 *
7110 * @return the time at which the device owner most recently requested a bug report, in
7111 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007112 * @throws SecurityException if the caller is not the device owner, does not hold the
7113 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007114 *
7115 * @hide
7116 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007117 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007118 public long getLastBugReportRequestTime() {
7119 try {
7120 return mService.getLastBugReportRequestTime();
7121 } catch (RemoteException re) {
7122 throw re.rethrowFromSystemServer();
7123 }
7124 }
7125
7126 /**
7127 * Called by the system to get the time at which the device owner last retrieved network logging
7128 * events.
7129 *
7130 * @return the time at which the device owner most recently retrieved network logging events, in
7131 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007132 * @throws SecurityException if the caller is not the device owner, does not hold the
7133 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007134 *
7135 * @hide
7136 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007137 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007138 public long getLastNetworkLogRetrievalTime() {
7139 try {
7140 return mService.getLastNetworkLogRetrievalTime();
7141 } catch (RemoteException re) {
7142 throw re.rethrowFromSystemServer();
7143 }
7144 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007145}