blob: 32902297510e945967e01c069d081492faea6e18 [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
2242 * are not taken into account.
2243 * <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}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002255 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002256 public boolean isActivePasswordSufficient() {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002257 if (mService != null) {
2258 try {
Clara Bayarri3e826ef2015-12-14 17:51:22 +00002259 return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002260 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002261 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002262 }
2263 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002264 return false;
Dianne Hackbornd6847842010-01-12 18:14:19 -08002265 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002266
Dianne Hackbornd6847842010-01-12 18:14:19 -08002267 /**
Clara Bayarrid7693912016-01-22 17:26:31 +00002268 * Determine whether the current profile password the user has set is sufficient
Esteban Talaverac1c83592016-02-17 17:56:15 +00002269 * to meet the policy requirements (e.g. quality, minimum length) that have been
Clara Bayarrid7693912016-01-22 17:26:31 +00002270 * requested by the admins of the parent user and its profiles.
2271 *
2272 * @param userHandle the userId of the profile to check the password for.
2273 * @return Returns true if the password would meet the current requirements, else false.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002274 * @throws SecurityException if {@code userHandle} is not a managed profile.
Clara Bayarrid7693912016-01-22 17:26:31 +00002275 * @hide
2276 */
2277 public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
2278 if (mService != null) {
2279 try {
2280 return mService.isProfileActivePasswordSufficientForParent(userHandle);
2281 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002282 throw e.rethrowFromSystemServer();
Clara Bayarrid7693912016-01-22 17:26:31 +00002283 }
2284 }
2285 return false;
2286 }
2287
2288 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002289 * Retrieve the number of times the user has failed at entering a password since that last
2290 * successful password entry.
2291 * <p>
2292 * This method can be called on the {@link DevicePolicyManager} instance returned by
2293 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the number of failed
2294 * password attemts for the parent user.
2295 * <p>
2296 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
2297 * to be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002298 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002299 * @return The number of times user has entered an incorrect password since the last correct
2300 * password entry.
2301 * @throws SecurityException if the calling application does not own an active administrator
2302 * that uses {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002303 */
2304 public int getCurrentFailedPasswordAttempts() {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002305 return getCurrentFailedPasswordAttempts(myUserId());
2306 }
2307
2308 /**
2309 * Retrieve the number of times the given user has failed at entering a
2310 * password since that last successful password entry.
2311 *
2312 * <p>The calling device admin must have requested
2313 * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to be able to call this method; if it has
2314 * not and it is not the system uid, a security exception will be thrown.
2315 *
2316 * @hide
2317 */
2318 public int getCurrentFailedPasswordAttempts(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002319 if (mService != null) {
2320 try {
Clara Bayarri51e41ad2016-02-11 17:48:53 +00002321 return mService.getCurrentFailedPasswordAttempts(userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002322 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002323 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002324 }
2325 }
2326 return -1;
2327 }
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002328
2329 /**
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002330 * Queries whether {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT} flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002331 *
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002332 * @return true if RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT flag is set.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002333 * @hide
2334 */
2335 public boolean getDoNotAskCredentialsOnBoot() {
2336 if (mService != null) {
2337 try {
2338 return mService.getDoNotAskCredentialsOnBoot();
2339 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002340 throw e.rethrowFromSystemServer();
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002341 }
2342 }
2343 return false;
2344 }
2345
2346 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002347 * Setting this to a value greater than zero enables a built-in policy that will perform a
2348 * device or profile wipe after too many incorrect device-unlock passwords have been entered.
2349 * This built-in policy combines watching for failed passwords and wiping the device, and
2350 * requires that you request both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002351 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002352 * <p>
2353 * To implement any other policy (e.g. wiping data for a particular application only, erasing or
2354 * revoking credentials, or reporting the failure to a server), you should implement
2355 * {@link DeviceAdminReceiver#onPasswordFailed(Context, android.content.Intent)} instead. Do not
2356 * use this API, because if the maximum count is reached, the device or profile will be wiped
2357 * immediately, and your callback will not be invoked.
2358 * <p>
2359 * This method can be called on the {@link DevicePolicyManager} instance returned by
2360 * {@link #getParentProfileInstance(ComponentName)} in order to set a value on the parent
2361 * profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002362 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002364 * @param num The number of failed password attempts at which point the device or profile will
2365 * be wiped.
2366 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2367 * both {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} and
2368 * {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}.
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002369 */
Robin Lee25e26452015-06-02 09:56:29 -07002370 public void setMaximumFailedPasswordsForWipe(@NonNull ComponentName admin, int num) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002371 if (mService != null) {
2372 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002373 mService.setMaximumFailedPasswordsForWipe(admin, num, mParentInstance);
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002374 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002375 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002376 }
2377 }
2378 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002379
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08002380 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002381 * Retrieve the current maximum number of login attempts that are allowed before the device
Rubin Xud3609d42016-07-13 18:32:57 +01002382 * or profile is wiped, for a particular admin or all admins that set restrictions on this user
Esteban Talaverac1c83592016-02-17 17:56:15 +00002383 * and its participating profiles. Restrictions on profiles that have a separate challenge are
2384 * not taken into account.
2385 *
2386 * <p>This method can be called on the {@link DevicePolicyManager} instance
2387 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2388 * the value for the parent profile.
2389 *
Robin Lee25e26452015-06-02 09:56:29 -07002390 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002391 * all admins.
2392 */
Robin Lee25e26452015-06-02 09:56:29 -07002393 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002394 return getMaximumFailedPasswordsForWipe(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002395 }
2396
2397 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002398 public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
Dianne Hackborn254cb442010-01-27 19:23:59 -08002399 if (mService != null) {
2400 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002401 return mService.getMaximumFailedPasswordsForWipe(
2402 admin, userHandle, mParentInstance);
Dianne Hackborn254cb442010-01-27 19:23:59 -08002403 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002404 throw e.rethrowFromSystemServer();
Dianne Hackborn254cb442010-01-27 19:23:59 -08002405 }
2406 }
2407 return 0;
2408 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002409
Dianne Hackborn254cb442010-01-27 19:23:59 -08002410 /**
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002411 * Returns the profile with the smallest maximum failed passwords for wipe,
2412 * for the given user. So for primary user, it might return the primary or
2413 * a managed profile. For a secondary user, it would be the same as the
2414 * user passed in.
2415 * @hide Used only by Keyguard
2416 */
2417 public int getProfileWithMinimumFailedPasswordsForWipe(int userHandle) {
2418 if (mService != null) {
2419 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002420 return mService.getProfileWithMinimumFailedPasswordsForWipe(
2421 userHandle, mParentInstance);
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002422 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002423 throw e.rethrowFromSystemServer();
Amith Yamasani3a3d2122014-10-29 11:41:31 -07002424 }
2425 }
2426 return UserHandle.USER_NULL;
2427 }
2428
2429 /**
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002430 * Flag for {@link #resetPassword}: don't allow other admins to change
2431 * the password again until the user has entered it.
2432 */
2433 public static final int RESET_PASSWORD_REQUIRE_ENTRY = 0x0001;
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002434
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002435 /**
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002436 * Flag for {@link #resetPassword}: don't ask for user credentials on device boot.
2437 * If the flag is set, the device can be booted without asking for user password.
2438 * The absence of this flag does not change the current boot requirements. This flag
2439 * can be set by the device owner only. If the app is not the device owner, the flag
2440 * is ignored. Once the flag is set, it cannot be reverted back without resetting the
2441 * device to factory defaults.
2442 */
Craig Lafayette4e401fa2015-05-07 10:24:02 -04002443 public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 0x0002;
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002444
2445 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002446 * Force a new device unlock password (the password needed to access the entire device, not for
2447 * individual accounts) on the user. This takes effect immediately.
2448 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002449 * <em>Note: This API has been limited as of {@link android.os.Build.VERSION_CODES#N} for
Makoto Onuki70f929e2015-11-11 12:40:15 -08002450 * device admins that are not device owner and not profile owner.
2451 * The password can now only be changed if there is currently no password set. Device owner
Ricky Wai977ade22016-05-24 15:02:41 +01002452 * and profile owner can still do this when user is unlocked and does not have a managed
2453 * profile.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002454 * <p>
2455 * The given password must be sufficient for the current password quality and length constraints
2456 * as returned by {@link #getPasswordQuality(ComponentName)} and
2457 * {@link #getPasswordMinimumLength(ComponentName)}; if it does not meet these constraints, then
2458 * it will be rejected and false returned. Note that the password may be a stronger quality
2459 * (containing alphanumeric characters when the requested quality is only numeric), in which
2460 * case the currently active quality will be increased to match.
2461 * <p>
2462 * Calling with a null or empty password will clear any existing PIN, pattern or password if the
Robin Leece5c4002016-03-23 17:05:03 +00002463 * current password constraints allow it. <em>Note: This will not work in
2464 * {@link android.os.Build.VERSION_CODES#N} and later for managed profiles, or for device admins
2465 * that are not device owner or profile owner. Once set, the password cannot be changed to null
2466 * or empty except by these admins.</em>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002467 * <p>
2468 * The calling device admin must have requested
2469 * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call this method; if it has
2470 * not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002471 *
Adrian Roosf8f56bc2014-11-20 23:55:34 +01002472 * @param password The new password for the user. Null or empty clears the password.
Andrei Kapishnikov4eb6a362015-04-02 15:21:20 -04002473 * @param flags May be 0 or combination of {@link #RESET_PASSWORD_REQUIRE_ENTRY} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002474 * {@link #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}.
2475 * @return Returns true if the password was applied, or false if it is not acceptable for the
2476 * current constraints or if the user has not been decrypted yet.
2477 * @throws SecurityException if the calling application does not own an active administrator
2478 * that uses {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD}
Ricky Wai977ade22016-05-24 15:02:41 +01002479 * @throws IllegalStateException if the calling user is locked or has a managed profile.
Andrew Scull3f81f4e2016-07-29 16:29:58 +01002480 * @throws IllegalArgumentException if the password does not meet system requirements.
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002481 */
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002482 public boolean resetPassword(String password, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002483 throwIfParentInstance("resetPassword");
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002484 if (mService != null) {
2485 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002486 return mService.resetPassword(password, flags);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002487 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002488 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002489 }
2490 }
2491 return false;
2492 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002493
Dianne Hackbornd6847842010-01-12 18:14:19 -08002494 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002495 * Called by an application that is administering the device to set the maximum time for user
2496 * activity until the device will lock. This limits the length that the user can set. It takes
2497 * effect immediately.
2498 * <p>
2499 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2500 * to be able to call this method; if it has not, a security exception will be thrown.
2501 * <p>
2502 * This method can be called on the {@link DevicePolicyManager} instance returned by
2503 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2504 * profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00002505 *
Dianne Hackbornef6b22f2010-02-16 20:38:49 -08002506 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002507 * @param timeMs The new desired maximum time to lock in milliseconds. A value of 0 means there
2508 * is no restriction.
2509 * @throws SecurityException if {@code admin} is not an active administrator or it does not use
2510 * {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002511 */
Robin Lee25e26452015-06-02 09:56:29 -07002512 public void setMaximumTimeToLock(@NonNull ComponentName admin, long timeMs) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002513 if (mService != null) {
2514 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002515 mService.setMaximumTimeToLock(admin, timeMs, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002516 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002517 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002518 }
2519 }
2520 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002521
Dianne Hackbornd6847842010-01-12 18:14:19 -08002522 /**
Esteban Talaverac1c83592016-02-17 17:56:15 +00002523 * Retrieve the current maximum time to unlock for a particular admin or all admins that set
Rubin Xud3609d42016-07-13 18:32:57 +01002524 * restrictions on this user and its participating profiles. Restrictions on profiles that have
Esteban Talaverac1c83592016-02-17 17:56:15 +00002525 * a separate challenge are not taken into account.
2526 *
2527 * <p>This method can be called on the {@link DevicePolicyManager} instance
2528 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2529 * restrictions on the parent profile.
2530 *
Robin Lee25e26452015-06-02 09:56:29 -07002531 * @param admin The name of the admin component to check, or {@code null} to aggregate
Dianne Hackborn254cb442010-01-27 19:23:59 -08002532 * all admins.
Jim Millerd4efaac2014-08-14 18:02:45 -07002533 * @return time in milliseconds for the given admin or the minimum value (strictest) of
Jim Miller76b9b8b2014-08-22 17:04:57 -07002534 * all admins if admin is null. Returns 0 if there are no restrictions.
Dianne Hackbornd6847842010-01-12 18:14:19 -08002535 */
Robin Lee25e26452015-06-02 09:56:29 -07002536 public long getMaximumTimeToLock(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002537 return getMaximumTimeToLock(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07002538 }
2539
2540 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07002541 public long getMaximumTimeToLock(@Nullable ComponentName admin, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08002542 if (mService != null) {
2543 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002544 return mService.getMaximumTimeToLock(admin, userHandle, mParentInstance);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002545 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002546 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002547 }
2548 }
2549 return 0;
2550 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002551
Dianne Hackbornd6847842010-01-12 18:14:19 -08002552 /**
Ricky Wai035e9242016-03-18 16:43:31 +00002553 * Returns maximum time to lock that applied by all profiles in this user. We do this because we
2554 * do not have a separate timeout to lock for work challenge only.
2555 *
2556 * @hide
2557 */
2558 public long getMaximumTimeToLockForUserAndProfiles(int userHandle) {
2559 if (mService != null) {
2560 try {
2561 return mService.getMaximumTimeToLockForUserAndProfiles(userHandle);
2562 } catch (RemoteException e) {
2563 throw e.rethrowFromSystemServer();
2564 }
2565 }
2566 return 0;
2567 }
2568
2569 /**
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002570 * Called by a device/profile owner to set the timeout after which unlocking with secondary, non
2571 * strong auth (e.g. fingerprint, trust agents) times out, i.e. the user has to use a strong
2572 * authentication method like password, pin or pattern.
2573 *
2574 * <p>This timeout is used internally to reset the timer to require strong auth again after
2575 * specified timeout each time it has been successfully used.
2576 *
2577 * <p>Fingerprint can also be disabled altogether using {@link #KEYGUARD_DISABLE_FINGERPRINT}.
2578 *
2579 * <p>Trust agents can also be disabled altogether using {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
2580 *
2581 * <p>The calling device admin must be a device or profile owner. If it is not,
2582 * a {@link SecurityException} will be thrown.
2583 *
Michal Karpinski943aabd2016-10-06 11:09:25 +01002584 * <p>The calling device admin can verify the value it has set by calling
2585 * {@link #getRequiredStrongAuthTimeout(ComponentName)} and passing in its instance.
2586 *
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002587 * <p>This method can be called on the {@link DevicePolicyManager} instance returned by
2588 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
2589 * profile.
2590 *
2591 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2592 * @param timeoutMs The new timeout, after which the user will have to unlock with strong
Michal Karpinski943aabd2016-10-06 11:09:25 +01002593 * authentication method. A value of 0 means the admin is not participating in
2594 * controlling the timeout.
2595 * The minimum and maximum timeouts are platform-defined and are typically 1 hour and
2596 * 72 hours, respectively. Though discouraged, the admin may choose to require strong
2597 * auth at all times using {@link #KEYGUARD_DISABLE_FINGERPRINT} and/or
2598 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002599 *
2600 * @throws SecurityException if {@code admin} is not a device or profile owner.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002601 */
2602 public void setRequiredStrongAuthTimeout(@NonNull ComponentName admin,
2603 long timeoutMs) {
2604 if (mService != null) {
2605 try {
2606 mService.setRequiredStrongAuthTimeout(admin, timeoutMs, mParentInstance);
2607 } catch (RemoteException e) {
2608 throw e.rethrowFromSystemServer();
2609 }
2610 }
2611 }
2612
2613 /**
2614 * Determine for how long the user will be able to use secondary, non strong auth for
2615 * authentication, since last strong method authentication (password, pin or pattern) was used.
2616 * After the returned timeout the user is required to use strong authentication method.
2617 *
2618 * <p>This method can be called on the {@link DevicePolicyManager} instance
2619 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
2620 * restrictions on the parent profile.
2621 *
2622 * @param admin The name of the admin component to check, or {@code null} to aggregate
2623 * accross all participating admins.
Michal Karpinski943aabd2016-10-06 11:09:25 +01002624 * @return The timeout or 0 if not configured for the provided admin.
Michal Karpinski8f010dd2016-06-21 15:05:53 +01002625 */
2626 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin) {
2627 return getRequiredStrongAuthTimeout(admin, myUserId());
2628 }
2629
2630 /** @hide per-user version */
2631 public long getRequiredStrongAuthTimeout(@Nullable ComponentName admin, @UserIdInt int userId) {
2632 if (mService != null) {
2633 try {
2634 return mService.getRequiredStrongAuthTimeout(admin, userId, mParentInstance);
2635 } catch (RemoteException e) {
2636 throw e.rethrowFromSystemServer();
2637 }
2638 }
2639 return DEFAULT_STRONG_AUTH_TIMEOUT_MS;
2640 }
2641
2642 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002643 * Make the device lock immediately, as if the lock screen timeout has expired at the point of
2644 * this call.
2645 * <p>
2646 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
2647 * to be able to call this method; if it has not, a security exception will be thrown.
2648 * <p>
2649 * This method can be called on the {@link DevicePolicyManager} instance returned by
2650 * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002651 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002652 * @throws SecurityException if the calling application does not own an active administrator
2653 * that uses {@link DeviceAdminInfo#USES_POLICY_FORCE_LOCK}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002654 */
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002655 public void lockNow() {
2656 if (mService != null) {
2657 try {
Esteban Talavera62399912016-01-11 15:37:55 +00002658 mService.lockNow(mParentInstance);
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002659 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002660 throw e.rethrowFromSystemServer();
Dianne Hackborndf83afa2010-01-20 13:37:26 -08002661 }
2662 }
2663 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002664
Dianne Hackbornd6847842010-01-12 18:14:19 -08002665 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002666 * Flag for {@link #wipeData(int)}: also erase the device's external
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002667 * storage (such as SD cards).
Dianne Hackborn42499172010-10-15 18:45:07 -07002668 */
2669 public static final int WIPE_EXTERNAL_STORAGE = 0x0001;
2670
2671 /**
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002672 * Flag for {@link #wipeData(int)}: also erase the factory reset protection
2673 * data.
2674 *
Paul Crowley2934b262014-12-02 11:21:13 +00002675 * <p>This flag may only be set by device owner admins; if it is set by
2676 * other admins a {@link SecurityException} will be thrown.
Paul Crowleya7e87ac2014-11-18 13:50:19 +00002677 */
2678 public static final int WIPE_RESET_PROTECTION_DATA = 0x0002;
2679
2680 /**
Suprabh Shukla556b05a2016-08-10 15:49:24 -07002681 * Ask that all user data be wiped. If called as a secondary user, the user will be removed and
2682 * other users will remain unaffected. Calling from the primary user will cause the device to
2683 * reboot, erasing all device data - including all the secondary users and their data - while
2684 * booting up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002685 * <p>
2686 * The calling device admin must have requested {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA} to
2687 * be able to call this method; if it has not, a security exception will be thrown.
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002688 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002689 * @param flags Bit mask of additional options: currently supported flags are
2690 * {@link #WIPE_EXTERNAL_STORAGE} and {@link #WIPE_RESET_PROTECTION_DATA}.
2691 * @throws SecurityException if the calling application does not own an active administrator
2692 * that uses {@link DeviceAdminInfo#USES_POLICY_WIPE_DATA}
Dianne Hackbornd6847842010-01-12 18:14:19 -08002693 */
2694 public void wipeData(int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002695 throwIfParentInstance("wipeData");
Dianne Hackbornd6847842010-01-12 18:14:19 -08002696 if (mService != null) {
2697 try {
Makoto Onuki70f929e2015-11-11 12:40:15 -08002698 mService.wipeData(flags);
Dianne Hackbornd6847842010-01-12 18:14:19 -08002699 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002700 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08002701 }
2702 }
2703 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07002704
Dianne Hackbornd6847842010-01-12 18:14:19 -08002705 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002706 * Called by an application that is administering the device to set the
2707 * global proxy and exclusion list.
2708 * <p>
2709 * The calling device admin must have requested
2710 * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
2711 * this method; if it has not, a security exception will be thrown.
2712 * Only the first device admin can set the proxy. If a second admin attempts
2713 * to set the proxy, the {@link ComponentName} of the admin originally setting the
Robin Lee25e26452015-06-02 09:56:29 -07002714 * proxy will be returned. If successful in setting the proxy, {@code null} will
Oscar Montemayor69238c62010-08-03 10:51:06 -07002715 * be returned.
2716 * The method can be called repeatedly by the device admin alrady setting the
2717 * proxy to update the proxy and exclusion list.
2718 *
Robin Lee25e26452015-06-02 09:56:29 -07002719 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Oscar Montemayor69238c62010-08-03 10:51:06 -07002720 * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
2721 * Pass Proxy.NO_PROXY to reset the proxy.
2722 * @param exclusionList a list of domains to be excluded from the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002723 * @return {@code null} if the proxy was successfully set, or otherwise a {@link ComponentName}
2724 * of the device admin that sets the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002725 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002726 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002727 public @Nullable ComponentName setGlobalProxy(@NonNull ComponentName admin, Proxy proxySpec,
Oscar Montemayor69238c62010-08-03 10:51:06 -07002728 List<String> exclusionList ) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002729 throwIfParentInstance("setGlobalProxy");
Oscar Montemayor69238c62010-08-03 10:51:06 -07002730 if (proxySpec == null) {
2731 throw new NullPointerException();
2732 }
2733 if (mService != null) {
2734 try {
2735 String hostSpec;
2736 String exclSpec;
2737 if (proxySpec.equals(Proxy.NO_PROXY)) {
2738 hostSpec = null;
2739 exclSpec = null;
2740 } else {
2741 if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
2742 throw new IllegalArgumentException();
2743 }
2744 InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
2745 String hostName = sa.getHostName();
2746 int port = sa.getPort();
2747 StringBuilder hostBuilder = new StringBuilder();
2748 hostSpec = hostBuilder.append(hostName)
2749 .append(":").append(Integer.toString(port)).toString();
2750 if (exclusionList == null) {
2751 exclSpec = "";
2752 } else {
2753 StringBuilder listBuilder = new StringBuilder();
2754 boolean firstDomain = true;
2755 for (String exclDomain : exclusionList) {
2756 if (!firstDomain) {
2757 listBuilder = listBuilder.append(",");
2758 } else {
2759 firstDomain = false;
2760 }
2761 listBuilder = listBuilder.append(exclDomain.trim());
2762 }
2763 exclSpec = listBuilder.toString();
2764 }
Yuhao Zheng90704842014-02-28 17:22:45 -08002765 if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
2766 != android.net.Proxy.PROXY_VALID)
2767 throw new IllegalArgumentException();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002768 }
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002769 return mService.setGlobalProxy(admin, hostSpec, exclSpec);
Oscar Montemayor69238c62010-08-03 10:51:06 -07002770 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002771 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002772 }
2773 }
2774 return null;
2775 }
2776
2777 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002778 * Set a network-independent global HTTP proxy. This is not normally what you want for typical
2779 * HTTP proxies - they are generally network dependent. However if you're doing something
2780 * unusual like general internal filtering this may be useful. On a private network where the
2781 * proxy is not accessible, you may break HTTP using this.
2782 * <p>
2783 * This method requires the caller to be the device owner.
2784 * <p>
2785 * This proxy is only a recommendation and it is possible that some apps will ignore it.
Jason Monk03bc9912014-05-13 09:44:57 -04002786 *
Jason Monk03bc9912014-05-13 09:44:57 -04002787 * @see ProxyInfo
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002788 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2789 * @param proxyInfo The a {@link ProxyInfo} object defining the new global HTTP proxy. A
2790 * {@code null} value will clear the global HTTP proxy.
2791 * @throws SecurityException if {@code admin} is not the device owner.
Jason Monk03bc9912014-05-13 09:44:57 -04002792 */
Robin Lee25e26452015-06-02 09:56:29 -07002793 public void setRecommendedGlobalProxy(@NonNull ComponentName admin, @Nullable ProxyInfo
2794 proxyInfo) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002795 throwIfParentInstance("setRecommendedGlobalProxy");
Jason Monk03bc9912014-05-13 09:44:57 -04002796 if (mService != null) {
2797 try {
2798 mService.setRecommendedGlobalProxy(admin, proxyInfo);
2799 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002800 throw e.rethrowFromSystemServer();
Jason Monk03bc9912014-05-13 09:44:57 -04002801 }
2802 }
2803 }
2804
2805 /**
Oscar Montemayor69238c62010-08-03 10:51:06 -07002806 * Returns the component name setting the global proxy.
Robin Lee25e26452015-06-02 09:56:29 -07002807 * @return ComponentName object of the device admin that set the global proxy, or {@code null}
2808 * if no admin has set the proxy.
Andy Stadlerd2672722011-02-16 10:53:33 -08002809 * @hide
Oscar Montemayor69238c62010-08-03 10:51:06 -07002810 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07002811 public @Nullable ComponentName getGlobalProxyAdmin() {
Oscar Montemayor69238c62010-08-03 10:51:06 -07002812 if (mService != null) {
2813 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002814 return mService.getGlobalProxyAdmin(myUserId());
Oscar Montemayor69238c62010-08-03 10:51:06 -07002815 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002816 throw e.rethrowFromSystemServer();
Oscar Montemayor69238c62010-08-03 10:51:06 -07002817 }
2818 }
2819 return null;
2820 }
2821
2822 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002823 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002824 * indicating that encryption is not supported.
2825 */
2826 public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
2827
2828 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002829 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002830 * indicating that encryption is supported, but is not currently active.
2831 */
2832 public static final int ENCRYPTION_STATUS_INACTIVE = 1;
2833
2834 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002835 * Result code for {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002836 * indicating that encryption is not currently active, but is currently
2837 * being activated. This is only reported by devices that support
2838 * encryption of data and only when the storage is currently
2839 * undergoing a process of becoming encrypted. A device that must reboot and/or wipe data
2840 * to become encrypted will never return this value.
2841 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002842 public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002843
2844 /**
Andy Stadler22dbfda2011-01-17 12:47:31 -08002845 * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002846 * indicating that encryption is active.
Amith Yamasani75db1252016-07-11 14:41:01 -07002847 * <p>
2848 * Also see {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002849 */
Andy Stadler22dbfda2011-01-17 12:47:31 -08002850 public static final int ENCRYPTION_STATUS_ACTIVE = 3;
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002851
2852 /**
Robin Lee3795fb02015-02-16 14:17:23 +00002853 * Result code for {@link #getStorageEncryptionStatus}:
2854 * indicating that encryption is active, but an encryption key has not
2855 * been set by the user.
2856 */
2857 public static final int ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY = 4;
2858
2859 /**
Makoto Onukid4c9e542016-02-25 18:17:30 -08002860 * Result code for {@link #getStorageEncryptionStatus}:
Amith Yamasani75db1252016-07-11 14:41:01 -07002861 * indicating that encryption is active and the encryption key is tied to the user or profile.
2862 * <p>
2863 * This value is only returned to apps targeting API level 24 and above. For apps targeting
2864 * earlier API levels, {@link #ENCRYPTION_STATUS_ACTIVE} is returned, even if the
2865 * encryption key is specific to the user or profile.
Makoto Onukid4c9e542016-02-25 18:17:30 -08002866 */
2867 public static final int ENCRYPTION_STATUS_ACTIVE_PER_USER = 5;
2868
2869 /**
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002870 * Activity action: begin the process of encrypting data on the device. This activity should
2871 * be launched after using {@link #setStorageEncryption} to request encryption be activated.
2872 * After resuming from this activity, use {@link #getStorageEncryption}
2873 * to check encryption status. However, on some devices this activity may never return, as
2874 * it may trigger a reboot and in some cases a complete data wipe of the device.
2875 */
2876 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
2877 public static final String ACTION_START_ENCRYPTION
2878 = "android.app.action.START_ENCRYPTION";
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002879 /**
Jim Millerb8ec4702012-08-31 17:19:10 -07002880 * Widgets are enabled in keyguard
2881 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002882 public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;
Jim Millerb8ec4702012-08-31 17:19:10 -07002883
2884 /**
Jim Miller50e62182014-04-23 17:25:00 -07002885 * Disable all keyguard widgets. Has no effect.
Jim Millerb8ec4702012-08-31 17:19:10 -07002886 */
Jim Miller48b9b0d2012-09-19 23:16:50 -07002887 public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;
2888
2889 /**
2890 * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
2891 */
2892 public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;
2893
2894 /**
Jim Miller50e62182014-04-23 17:25:00 -07002895 * Disable showing all notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2896 */
2897 public static final int KEYGUARD_DISABLE_SECURE_NOTIFICATIONS = 1 << 2;
2898
2899 /**
2900 * Only allow redacted notifications on secure keyguard screens (e.g. PIN/Pattern/Password)
2901 */
2902 public static final int KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS = 1 << 3;
2903
2904 /**
Adrian Roosa06d5ca2014-07-28 15:14:21 +02002905 * Ignore trust agent state on secure keyguard screens
Jim Miller50e62182014-04-23 17:25:00 -07002906 * (e.g. PIN/Pattern/Password).
2907 */
2908 public static final int KEYGUARD_DISABLE_TRUST_AGENTS = 1 << 4;
2909
2910 /**
Jim Miller06e34502014-07-17 14:46:05 -07002911 * Disable fingerprint sensor on keyguard secure screens (e.g. PIN/Pattern/Password).
2912 */
2913 public static final int KEYGUARD_DISABLE_FINGERPRINT = 1 << 5;
2914
2915 /**
Adrian Roos7f06eed2016-02-05 15:21:02 -08002916 * Disable text entry into notifications on secure keyguard screens (e.g. PIN/Pattern/Password).
2917 */
2918 public static final int KEYGUARD_DISABLE_REMOTE_INPUT = 1 << 6;
2919
2920 /**
Jim Miller35207742012-11-02 15:33:20 -07002921 * Disable all current and future keyguard customizations.
Jim Miller48b9b0d2012-09-19 23:16:50 -07002922 */
2923 public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;
Jim Millerb8ec4702012-08-31 17:19:10 -07002924
2925 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002926 * Called by an application that is administering the device to request that the storage system
2927 * be encrypted.
2928 * <p>
2929 * When multiple device administrators attempt to control device encryption, the most secure,
2930 * supported setting will always be used. If any device administrator requests device
2931 * encryption, it will be enabled; Conversely, if a device administrator attempts to disable
2932 * device encryption while another device administrator has enabled it, the call to disable will
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002933 * fail (most commonly returning {@link #ENCRYPTION_STATUS_ACTIVE}).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002934 * <p>
2935 * This policy controls encryption of the secure (application data) storage area. Data written
2936 * to other storage areas may or may not be encrypted, and this policy does not require or
2937 * control the encryption of any other storage areas. There is one exception: If
2938 * {@link android.os.Environment#isExternalStorageEmulated()} is {@code true}, then the
2939 * directory returned by {@link android.os.Environment#getExternalStorageDirectory()} must be
2940 * written to disk within the encrypted storage area.
2941 * <p>
2942 * Important Note: On some devices, it is possible to encrypt storage without requiring the user
2943 * to create a device PIN or Password. In this case, the storage is encrypted, but the
2944 * encryption key may not be fully secured. For maximum security, the administrator should also
2945 * require (and check for) a pattern, PIN, or password.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002946 *
2947 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
2948 * @param encrypt true to request encryption, false to release any previous request
Andy Stadler22dbfda2011-01-17 12:47:31 -08002949 * @return the new request status (for all active admins) - will be one of
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07002950 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE}, or
2951 * {@link #ENCRYPTION_STATUS_ACTIVE}. This is the value of the requests; Use
2952 * {@link #getStorageEncryptionStatus()} to query the actual device state.
2953 * @throws SecurityException if {@code admin} is not an active administrator or does not use
2954 * {@link DeviceAdminInfo#USES_ENCRYPTED_STORAGE}
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002955 */
Robin Lee25e26452015-06-02 09:56:29 -07002956 public int setStorageEncryption(@NonNull ComponentName admin, boolean encrypt) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002957 throwIfParentInstance("setStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002958 if (mService != null) {
2959 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08002960 return mService.setStorageEncryption(admin, encrypt);
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002961 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002962 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002963 }
2964 }
2965 return ENCRYPTION_STATUS_UNSUPPORTED;
2966 }
2967
2968 /**
2969 * Called by an application that is administering the device to
Andy Stadler22dbfda2011-01-17 12:47:31 -08002970 * determine the requested setting for secure storage.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002971 *
Andy Stadler22dbfda2011-01-17 12:47:31 -08002972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
2973 * this will return the requested encryption setting as an aggregate of all active
2974 * administrators.
2975 * @return true if the admin(s) are requesting encryption, false if not.
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002976 */
Robin Lee25e26452015-06-02 09:56:29 -07002977 public boolean getStorageEncryption(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01002978 throwIfParentInstance("getStorageEncryption");
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002979 if (mService != null) {
2980 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07002981 return mService.getStorageEncryption(admin, myUserId());
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002982 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07002983 throw e.rethrowFromSystemServer();
Andy Stadler7b0f8f02011-01-12 14:59:52 -08002984 }
2985 }
Andy Stadler22dbfda2011-01-17 12:47:31 -08002986 return false;
2987 }
2988
2989 /**
2990 * Called by an application that is administering the device to
2991 * determine the current encryption status of the device.
Amith Yamasani75db1252016-07-11 14:41:01 -07002992 * <p>
Andy Stadler22dbfda2011-01-17 12:47:31 -08002993 * Depending on the returned status code, the caller may proceed in different
2994 * ways. If the result is {@link #ENCRYPTION_STATUS_UNSUPPORTED}, the
2995 * storage system does not support encryption. If the
2996 * result is {@link #ENCRYPTION_STATUS_INACTIVE}, use {@link
2997 * #ACTION_START_ENCRYPTION} to begin the process of encrypting or decrypting the
Robin Lee3795fb02015-02-16 14:17:23 +00002998 * storage. If the result is {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY}, the
2999 * storage system has enabled encryption but no password is set so further action
Amith Yamasani75db1252016-07-11 14:41:01 -07003000 * may be required. If the result is {@link #ENCRYPTION_STATUS_ACTIVATING},
3001 * {@link #ENCRYPTION_STATUS_ACTIVE} or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER},
3002 * no further action is required.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003003 *
Robin Lee7e678712014-07-24 16:41:31 +01003004 * @return current status of encryption. The value will be one of
Andy Stadler22dbfda2011-01-17 12:47:31 -08003005 * {@link #ENCRYPTION_STATUS_UNSUPPORTED}, {@link #ENCRYPTION_STATUS_INACTIVE},
Robin Lee3795fb02015-02-16 14:17:23 +00003006 * {@link #ENCRYPTION_STATUS_ACTIVATING}, {@link #ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY},
Amith Yamasani75db1252016-07-11 14:41:01 -07003007 * {@link #ENCRYPTION_STATUS_ACTIVE}, or {@link #ENCRYPTION_STATUS_ACTIVE_PER_USER}.
Andy Stadler22dbfda2011-01-17 12:47:31 -08003008 */
3009 public int getStorageEncryptionStatus() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003010 throwIfParentInstance("getStorageEncryptionStatus");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003011 return getStorageEncryptionStatus(myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003012 }
3013
3014 /** @hide per-user version */
3015 public int getStorageEncryptionStatus(int userHandle) {
Andy Stadler22dbfda2011-01-17 12:47:31 -08003016 if (mService != null) {
3017 try {
Makoto Onukid4c9e542016-02-25 18:17:30 -08003018 return mService.getStorageEncryptionStatus(mContext.getPackageName(), userHandle);
Andy Stadler22dbfda2011-01-17 12:47:31 -08003019 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003020 throw e.rethrowFromSystemServer();
Andy Stadler22dbfda2011-01-17 12:47:31 -08003021 }
3022 }
Andy Stadler7b0f8f02011-01-12 14:59:52 -08003023 return ENCRYPTION_STATUS_UNSUPPORTED;
3024 }
3025
3026 /**
Robin Lee2f7e1e42016-03-21 10:50:01 +00003027 * Mark a CA certificate as approved by the device user. This means that they have been notified
3028 * of the installation, were made aware of the risks, viewed the certificate and still wanted to
3029 * keep the certificate on the device.
3030 *
3031 * Calling with {@param approval} as {@code true} will cancel any ongoing warnings related to
3032 * this certificate.
3033 *
3034 * @hide
3035 */
3036 public boolean approveCaCert(String alias, int userHandle, boolean approval) {
3037 if (mService != null) {
3038 try {
3039 return mService.approveCaCert(alias, userHandle, approval);
3040 } catch (RemoteException e) {
3041 throw e.rethrowFromSystemServer();
3042 }
3043 }
3044 return false;
3045 }
3046
3047 /**
3048 * Check whether a CA certificate has been approved by the device user.
3049 *
3050 * @hide
3051 */
3052 public boolean isCaCertApproved(String alias, int userHandle) {
3053 if (mService != null) {
3054 try {
3055 return mService.isCaCertApproved(alias, userHandle);
3056 } catch (RemoteException e) {
3057 throw e.rethrowFromSystemServer();
3058 }
3059 }
3060 return false;
3061 }
3062
3063 /**
Robin Lee7e678712014-07-24 16:41:31 +01003064 * Installs the given certificate as a user CA.
3065 *
Robin Lee25e26452015-06-02 09:56:29 -07003066 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3067 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003068 * @param certBuffer encoded form of the certificate to install.
Maggie Benthallda51e682013-08-08 22:35:44 -04003069 *
3070 * @return false if the certBuffer cannot be parsed or installation is
Robin Lee7e678712014-07-24 16:41:31 +01003071 * interrupted, true otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003072 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3073 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003074 */
Robin Lee25e26452015-06-02 09:56:29 -07003075 public boolean installCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003076 throwIfParentInstance("installCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003077 if (mService != null) {
3078 try {
Robin Lee7e678712014-07-24 16:41:31 +01003079 return mService.installCaCert(admin, certBuffer);
Maggie Benthallda51e682013-08-08 22:35:44 -04003080 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003081 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003082 }
3083 }
3084 return false;
3085 }
3086
3087 /**
Robin Lee7e678712014-07-24 16:41:31 +01003088 * Uninstalls the given certificate from trusted user CAs, if present.
3089 *
Robin Lee25e26452015-06-02 09:56:29 -07003090 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3091 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003092 * @param certBuffer encoded form of the certificate to remove.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003093 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3094 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003095 */
Robin Lee25e26452015-06-02 09:56:29 -07003096 public void uninstallCaCert(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003097 throwIfParentInstance("uninstallCaCert");
Maggie Benthallda51e682013-08-08 22:35:44 -04003098 if (mService != null) {
3099 try {
Robin Lee306fe082014-06-19 14:04:24 +00003100 final String alias = getCaCertAlias(certBuffer);
Robin Lee83881bd2015-06-09 16:04:38 -07003101 mService.uninstallCaCerts(admin, new String[] {alias});
Robin Lee306fe082014-06-19 14:04:24 +00003102 } catch (CertificateException e) {
3103 Log.w(TAG, "Unable to parse certificate", e);
Maggie Benthallda51e682013-08-08 22:35:44 -04003104 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003105 throw e.rethrowFromSystemServer();
Maggie Benthallda51e682013-08-08 22:35:44 -04003106 }
3107 }
3108 }
3109
3110 /**
Robin Lee7e678712014-07-24 16:41:31 +01003111 * Returns all CA certificates that are currently trusted, excluding system CA certificates.
3112 * If a user has installed any certificates by other means than device policy these will be
3113 * included too.
3114 *
Robin Lee25e26452015-06-02 09:56:29 -07003115 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3116 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003117 * @return a List of byte[] arrays, each encoding one user CA certificate.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003118 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3119 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003120 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003121 public @NonNull List<byte[]> getInstalledCaCerts(@Nullable ComponentName admin) {
3122 final List<byte[]> certs = new ArrayList<byte[]>();
Benjamin Franzbc33c822016-04-15 08:57:52 +01003123 throwIfParentInstance("getInstalledCaCerts");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003124 if (mService != null) {
Robin Lee7e678712014-07-24 16:41:31 +01003125 try {
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003126 mService.enforceCanManageCaCerts(admin);
3127 final TrustedCertificateStore certStore = new TrustedCertificateStore();
3128 for (String alias : certStore.userAliases()) {
3129 try {
3130 certs.add(certStore.getCertificate(alias).getEncoded());
3131 } catch (CertificateException ce) {
3132 Log.w(TAG, "Could not encode certificate: " + alias, ce);
3133 }
3134 }
3135 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003136 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003137 }
3138 }
3139 return certs;
Maggie Benthallda51e682013-08-08 22:35:44 -04003140 }
3141
3142 /**
Robin Lee7e678712014-07-24 16:41:31 +01003143 * Uninstalls all custom trusted CA certificates from the profile. Certificates installed by
3144 * means other than device policy will also be removed, except for system CA certificates.
3145 *
Robin Lee25e26452015-06-02 09:56:29 -07003146 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3147 * {@code null} if calling from a delegated certificate installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003148 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3149 * owner.
Robin Lee7e678712014-07-24 16:41:31 +01003150 */
Robin Lee25e26452015-06-02 09:56:29 -07003151 public void uninstallAllUserCaCerts(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003152 throwIfParentInstance("uninstallAllUserCaCerts");
Robin Lee7e678712014-07-24 16:41:31 +01003153 if (mService != null) {
Robin Lee83881bd2015-06-09 16:04:38 -07003154 try {
3155 mService.uninstallCaCerts(admin, new TrustedCertificateStore().userAliases()
3156 .toArray(new String[0]));
3157 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003158 throw re.rethrowFromSystemServer();
Robin Lee7e678712014-07-24 16:41:31 +01003159 }
3160 }
3161 }
3162
3163 /**
3164 * Returns whether this certificate is installed as a trusted CA.
3165 *
Robin Lee25e26452015-06-02 09:56:29 -07003166 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3167 * {@code null} if calling from a delegated certificate installer.
Robin Lee7e678712014-07-24 16:41:31 +01003168 * @param certBuffer encoded form of the certificate to look up.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003169 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3170 * owner.
Maggie Benthallda51e682013-08-08 22:35:44 -04003171 */
Robin Lee25e26452015-06-02 09:56:29 -07003172 public boolean hasCaCertInstalled(@Nullable ComponentName admin, byte[] certBuffer) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003173 throwIfParentInstance("hasCaCertInstalled");
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003174 if (mService != null) {
3175 try {
3176 mService.enforceCanManageCaCerts(admin);
3177 return getCaCertAlias(certBuffer) != null;
3178 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003179 throw re.rethrowFromSystemServer();
Esteban Talavera808f6ef2014-08-28 17:15:54 +01003180 } catch (CertificateException ce) {
3181 Log.w(TAG, "Could not parse certificate", ce);
3182 }
Maggie Benthallda51e682013-08-08 22:35:44 -04003183 }
3184 return false;
3185 }
3186
3187 /**
Robin Leece3399f2016-02-24 12:08:32 +00003188 * Called by a device or profile owner, or delegated certificate installer, to install a
3189 * certificate and corresponding private key. All apps within the profile will be able to access
3190 * the certificate and use the private key, given direct user approval.
3191 *
3192 * <p>Access to the installed credentials will not be granted to the caller of this API without
3193 * direct user approval. This is for security - should a certificate installer become
3194 * compromised, certificates it had already installed will be protected.
3195 *
3196 * <p>If the installer must have access to the credentials, call
Rubin Xub4365912016-03-23 12:13:22 +00003197 * {@link #installKeyPair(ComponentName, PrivateKey, Certificate[], String, boolean)} instead.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003198 *
Robin Lee25e26452015-06-02 09:56:29 -07003199 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
3200 * {@code null} if calling from a delegated certificate installer.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003201 * @param privKey The private key to install.
3202 * @param cert The certificate to install.
3203 * @param alias The private key alias under which to install the certificate. If a certificate
3204 * with that alias already exists, it will be overwritten.
3205 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003206 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3207 * owner.
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003208 */
Robin Leefbc65642015-08-03 16:21:22 +01003209 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
3210 @NonNull Certificate cert, @NonNull String alias) {
Rubin Xub4365912016-03-23 12:13:22 +00003211 return installKeyPair(admin, privKey, new Certificate[] {cert}, alias, false);
Robin Leece3399f2016-02-24 12:08:32 +00003212 }
3213
3214 /**
3215 * Called by a device or profile owner, or delegated certificate installer, to install a
Rubin Xub4365912016-03-23 12:13:22 +00003216 * certificate chain and corresponding private key for the leaf certificate. All apps within the
3217 * profile will be able to access the certificate chain and use the private key, given direct
3218 * user approval.
Robin Leece3399f2016-02-24 12:08:32 +00003219 *
Robin Leea1b290e2016-03-09 14:38:36 +00003220 * <p>The caller of this API may grant itself access to the certificate and private key
3221 * immediately, without user approval. It is a best practice not to request this unless strictly
3222 * necessary since it opens up additional security vulnerabilities.
Robin Leece3399f2016-02-24 12:08:32 +00003223 *
3224 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003225 * {@code null} if calling from a delegated certificate installer.
Robin Leece3399f2016-02-24 12:08:32 +00003226 * @param privKey The private key to install.
Rubin Xub4365912016-03-23 12:13:22 +00003227 * @param certs The certificate chain to install. The chain should start with the leaf
3228 * certificate and include the chain of trust in order. This will be returned by
3229 * {@link android.security.KeyChain#getCertificateChain}.
Robin Leece3399f2016-02-24 12:08:32 +00003230 * @param alias The private key alias under which to install the certificate. If a certificate
Robin Leea1b290e2016-03-09 14:38:36 +00003231 * with that alias already exists, it will be overwritten.
Robin Leece3399f2016-02-24 12:08:32 +00003232 * @param requestAccess {@code true} to request that the calling app be granted access to the
Robin Leea1b290e2016-03-09 14:38:36 +00003233 * credentials immediately. Otherwise, access to the credentials will be gated by user
3234 * approval.
Robin Leece3399f2016-02-24 12:08:32 +00003235 * @return {@code true} if the keys were installed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003236 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3237 * owner.
Rubin Xub4365912016-03-23 12:13:22 +00003238 * @see android.security.KeyChain#getCertificateChain
Robin Leece3399f2016-02-24 12:08:32 +00003239 */
3240 public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
Rubin Xub4365912016-03-23 12:13:22 +00003241 @NonNull Certificate[] certs, @NonNull String alias, boolean requestAccess) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003242 throwIfParentInstance("installKeyPair");
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003243 try {
Rubin Xub4365912016-03-23 12:13:22 +00003244 final byte[] pemCert = Credentials.convertToPem(certs[0]);
3245 byte[] pemChain = null;
3246 if (certs.length > 1) {
3247 pemChain = Credentials.convertToPem(Arrays.copyOfRange(certs, 1, certs.length));
3248 }
Robin Lee0d5ccb72014-09-12 17:41:44 +01003249 final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
3250 .getKeySpec(privKey, PKCS8EncodedKeySpec.class).getEncoded();
Rubin Xub4365912016-03-23 12:13:22 +00003251 return mService.installKeyPair(admin, pkcs8Key, pemCert, pemChain, alias,
3252 requestAccess);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003253 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003254 throw e.rethrowFromSystemServer();
Robin Lee0d5ccb72014-09-12 17:41:44 +01003255 } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
3256 Log.w(TAG, "Failed to obtain private key material", e);
3257 } catch (CertificateException | IOException e) {
3258 Log.w(TAG, "Could not pem-encode certificate", e);
Bernhard Bauer26408cc2014-09-08 14:07:31 +01003259 }
3260 return false;
3261 }
3262
3263 /**
Robin Leea1b290e2016-03-09 14:38:36 +00003264 * Called by a device or profile owner, or delegated certificate installer, to remove a
3265 * certificate and private key pair installed under a given alias.
Robin Leefbc65642015-08-03 16:21:22 +01003266 *
3267 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Robin Leea1b290e2016-03-09 14:38:36 +00003268 * {@code null} if calling from a delegated certificate installer.
Robin Leefbc65642015-08-03 16:21:22 +01003269 * @param alias The private key alias under which the certificate is installed.
Robin Leea1b290e2016-03-09 14:38:36 +00003270 * @return {@code true} if the private key alias no longer exists, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003271 * @throws SecurityException if {@code admin} is not {@code null} and not a device or profile
3272 * owner.
Robin Leefbc65642015-08-03 16:21:22 +01003273 */
3274 public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003275 throwIfParentInstance("removeKeyPair");
Robin Leefbc65642015-08-03 16:21:22 +01003276 try {
3277 return mService.removeKeyPair(admin, alias);
3278 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003279 throw e.rethrowFromSystemServer();
Robin Leefbc65642015-08-03 16:21:22 +01003280 }
Robin Leefbc65642015-08-03 16:21:22 +01003281 }
3282
3283 /**
Robin Lee25e26452015-06-02 09:56:29 -07003284 * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
Robin Lee306fe082014-06-19 14:04:24 +00003285 * doesn't exist.
3286 */
3287 private static String getCaCertAlias(byte[] certBuffer) throws CertificateException {
3288 final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
3289 final X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
3290 new ByteArrayInputStream(certBuffer));
3291 return new TrustedCertificateStore().getCertificateAlias(cert);
3292 }
3293
3294 /**
Rubin Xuec32b562015-03-03 17:34:05 +00003295 * Called by a profile owner or device owner to grant access to privileged certificate
Rubin Xuacdc1832015-04-02 12:40:20 +01003296 * manipulation APIs to a third-party certificate installer app. Granted APIs include
Rubin Xuec32b562015-03-03 17:34:05 +00003297 * {@link #getInstalledCaCerts}, {@link #hasCaCertInstalled}, {@link #installCaCert},
Rubin Xuacdc1832015-04-02 12:40:20 +01003298 * {@link #uninstallCaCert}, {@link #uninstallAllUserCaCerts} and {@link #installKeyPair}.
Rubin Xuec32b562015-03-03 17:34:05 +00003299 * <p>
3300 * Delegated certificate installer is a per-user state. The delegated access is persistent until
3301 * it is later cleared by calling this method with a null value or uninstallling the certificate
3302 * installer.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003303 * <p>
Rubin Xuf03d0a62016-02-10 14:54:15 +00003304 * <b>Note:</b>Starting from {@link android.os.Build.VERSION_CODES#N}, if the caller
3305 * application's target SDK version is {@link android.os.Build.VERSION_CODES#N} or newer, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003306 * supplied certificate installer package must be installed when calling this API, otherwise an
3307 * {@link IllegalArgumentException} will be thrown.
Rubin Xuec32b562015-03-03 17:34:05 +00003308 *
Robin Lee25e26452015-06-02 09:56:29 -07003309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Rubin Xuec32b562015-03-03 17:34:05 +00003310 * @param installerPackage The package name of the certificate installer which will be given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003311 * access. If {@code null} is given the current package will be cleared.
3312 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003313 */
Robin Lee25e26452015-06-02 09:56:29 -07003314 public void setCertInstallerPackage(@NonNull ComponentName admin, @Nullable String
3315 installerPackage) throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003316 throwIfParentInstance("setCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003317 if (mService != null) {
3318 try {
Robin Lee25e26452015-06-02 09:56:29 -07003319 mService.setCertInstallerPackage(admin, installerPackage);
Rubin Xuec32b562015-03-03 17:34:05 +00003320 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003321 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003322 }
3323 }
3324 }
3325
3326 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003327 * Called by a profile owner or device owner to retrieve the certificate installer for the user.
3328 * null if none is set.
Rubin Xuec32b562015-03-03 17:34:05 +00003329 *
Robin Lee25e26452015-06-02 09:56:29 -07003330 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003331 * @return The package name of the current delegated certificate installer, or {@code null} if
3332 * none is set.
3333 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Rubin Xuec32b562015-03-03 17:34:05 +00003334 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003335 public @Nullable String getCertInstallerPackage(@NonNull ComponentName admin)
3336 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003337 throwIfParentInstance("getCertInstallerPackage");
Rubin Xuec32b562015-03-03 17:34:05 +00003338 if (mService != null) {
3339 try {
Robin Lee25e26452015-06-02 09:56:29 -07003340 return mService.getCertInstallerPackage(admin);
Rubin Xuec32b562015-03-03 17:34:05 +00003341 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003342 throw e.rethrowFromSystemServer();
Rubin Xuec32b562015-03-03 17:34:05 +00003343 }
3344 }
3345 return null;
3346 }
3347
3348 /**
Robin Lee244ce8e2016-01-05 18:03:46 +00003349 * Called by a device or profile owner to configure an always-on VPN connection through a
Robin Leedc679712016-05-03 13:23:03 +01003350 * specific application for the current user.
3351 *
3352 * @deprecated this version only exists for compability with previous developer preview builds.
3353 * TODO: delete once there are no longer any live references.
3354 * @hide
3355 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003356 @Deprecated
Robin Leedc679712016-05-03 13:23:03 +01003357 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage)
3358 throws NameNotFoundException, UnsupportedOperationException {
3359 setAlwaysOnVpnPackage(admin, vpnPackage, /* lockdownEnabled */ true);
3360 }
3361
3362 /**
3363 * Called by a device or profile owner to configure an always-on VPN connection through a
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003364 * specific application for the current user. This connection is automatically granted and
3365 * persisted after a reboot.
3366 * <p>
3367 * The designated package should declare a {@link android.net.VpnService} in its manifest
3368 * guarded by {@link android.Manifest.permission#BIND_VPN_SERVICE}, otherwise the call will
3369 * fail.
Robin Lee244ce8e2016-01-05 18:03:46 +00003370 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003371 * @param vpnPackage The package name for an installed VPN app on the device, or {@code null} to
Robin Leedc679712016-05-03 13:23:03 +01003372 * remove an existing always-on VPN configuration.
3373 * @param lockdownEnabled {@code true} to disallow networking when the VPN is not connected or
3374 * {@code false} otherwise. This carries the risk that any failure of the VPN provider
3375 * could break networking for all apps. This has no effect when clearing.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003376 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Leeee5eb932016-04-05 16:27:15 +01003377 * @throws NameNotFoundException if {@code vpnPackage} is not installed.
3378 * @throws UnsupportedOperationException if {@code vpnPackage} exists but does not support being
3379 * set as always-on, or if always-on VPN is not available.
Robin Lee244ce8e2016-01-05 18:03:46 +00003380 */
Robin Leedc679712016-05-03 13:23:03 +01003381 public void setAlwaysOnVpnPackage(@NonNull ComponentName admin, @Nullable String vpnPackage,
3382 boolean lockdownEnabled)
Robin Leeee5eb932016-04-05 16:27:15 +01003383 throws NameNotFoundException, UnsupportedOperationException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003384 throwIfParentInstance("setAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003385 if (mService != null) {
3386 try {
Robin Leedc679712016-05-03 13:23:03 +01003387 if (!mService.setAlwaysOnVpnPackage(admin, vpnPackage, lockdownEnabled)) {
Robin Leeee5eb932016-04-05 16:27:15 +01003388 throw new NameNotFoundException(vpnPackage);
3389 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003390 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003391 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003392 }
3393 }
Robin Lee244ce8e2016-01-05 18:03:46 +00003394 }
3395
3396 /**
3397 * Called by a device or profile owner to read the name of the package administering an
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003398 * always-on VPN connection for the current user. If there is no such package, or the always-on
3399 * VPN is provided by the system instead of by an application, {@code null} will be returned.
Robin Lee244ce8e2016-01-05 18:03:46 +00003400 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003401 * @return Package name of VPN controller responsible for always-on VPN, or {@code null} if none
3402 * is set.
3403 * @throws SecurityException if {@code admin} is not a device or a profile owner.
Robin Lee244ce8e2016-01-05 18:03:46 +00003404 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07003405 public @Nullable String getAlwaysOnVpnPackage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003406 throwIfParentInstance("getAlwaysOnVpnPackage");
Robin Lee244ce8e2016-01-05 18:03:46 +00003407 if (mService != null) {
3408 try {
3409 return mService.getAlwaysOnVpnPackage(admin);
3410 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003411 throw e.rethrowFromSystemServer();
Robin Lee244ce8e2016-01-05 18:03:46 +00003412 }
3413 }
3414 return null;
3415 }
3416
3417 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003418 * Called by an application that is administering the device to disable all cameras on the
3419 * device, for this user. After setting this, no applications running as this user will be able
3420 * to access any cameras on the device.
3421 * <p>
3422 * If the caller is device owner, then the restriction will be applied to all users.
3423 * <p>
3424 * The calling device admin must have requested
3425 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} to be able to call this method; if it has
3426 * not, a security exception will be thrown.
Ben Komalo2447edd2011-05-09 16:05:33 -07003427 *
3428 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3429 * @param disabled Whether or not the camera should be disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003430 * @throws SecurityException if {@code admin} is not an active administrator or does not use
3431 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA}.
Ben Komalo2447edd2011-05-09 16:05:33 -07003432 */
Robin Lee25e26452015-06-02 09:56:29 -07003433 public void setCameraDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003434 throwIfParentInstance("setCameraDisabled");
Ben Komalo2447edd2011-05-09 16:05:33 -07003435 if (mService != null) {
3436 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003437 mService.setCameraDisabled(admin, disabled);
Ben Komalo2447edd2011-05-09 16:05:33 -07003438 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003439 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003440 }
3441 }
3442 }
3443
3444 /**
Amith Yamasani242f4b12014-10-14 16:06:13 -07003445 * Determine whether or not the device's cameras have been disabled for this user,
Makoto Onuki32b30572015-12-11 14:29:51 -08003446 * either by the calling admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003447 * @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 -07003448 * have disabled the camera
3449 */
Robin Lee25e26452015-06-02 09:56:29 -07003450 public boolean getCameraDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003451 throwIfParentInstance("getCameraDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003452 return getCameraDisabled(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003453 }
3454
3455 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003456 public boolean getCameraDisabled(@Nullable ComponentName admin, int userHandle) {
Ben Komalo2447edd2011-05-09 16:05:33 -07003457 if (mService != null) {
3458 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003459 return mService.getCameraDisabled(admin, userHandle);
Ben Komalo2447edd2011-05-09 16:05:33 -07003460 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003461 throw e.rethrowFromSystemServer();
Ben Komalo2447edd2011-05-09 16:05:33 -07003462 }
3463 }
3464 return false;
3465 }
3466
3467 /**
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003468 * Called by a device owner to request a bugreport.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003469 * <p>
3470 * There must be only one user on the device, managed by the device owner. Otherwise a
3471 * {@link SecurityException} will be thrown.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003472 *
3473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003474 * @return {@code true} if the bugreport collection started successfully, or {@code false} if it
3475 * wasn't triggered because a previous bugreport operation is still active (either the
3476 * bugreport is still running or waiting for the user to share or decline)
3477 * @throws SecurityException if {@code admin} is not a device owner, or if there are users other
3478 * than the one managed by the device owner.
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003479 */
3480 public boolean requestBugreport(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003481 throwIfParentInstance("requestBugreport");
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003482 if (mService != null) {
3483 try {
3484 return mService.requestBugreport(admin);
3485 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003486 throw e.rethrowFromSystemServer();
Michal Karpinski3fc437e2015-12-15 10:09:00 +00003487 }
3488 }
3489 return false;
3490 }
3491
3492 /**
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07003493 * Determine whether or not creating a guest user has been disabled for the device
3494 *
3495 * @hide
3496 */
3497 public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
3498 // Currently guest users can always be created if multi-user is enabled
3499 // TODO introduce a policy for guest user creation
3500 return false;
3501 }
3502
3503 /**
Esteban Talavera1aee98f2014-08-21 14:03:55 +01003504 * Called by a device/profile owner to set whether the screen capture is disabled. Disabling
3505 * screen capture also prevents the content from being shown on display devices that do not have
3506 * a secure video output. See {@link android.view.Display#FLAG_SECURE} for more details about
3507 * secure surfaces and secure displays.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003508 * <p>
3509 * The calling device admin must be a device or profile owner. If it is not, a security
3510 * exception will be thrown.
3511 * <p>
3512 * From version {@link android.os.Build.VERSION_CODES#M} disabling screen capture also blocks
3513 * assist requests for all activities of the relevant user.
Benjamin Franzc200f442015-06-25 18:20:04 +01003514 *
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003515 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003516 * @param disabled Whether screen capture is disabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003517 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003518 */
Robin Lee25e26452015-06-02 09:56:29 -07003519 public void setScreenCaptureDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003520 throwIfParentInstance("setScreenCaptureDisabled");
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003521 if (mService != null) {
3522 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003523 mService.setScreenCaptureDisabled(admin, disabled);
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003524 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003525 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003526 }
3527 }
3528 }
3529
3530 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003531 * Determine whether or not screen capture has been disabled by the calling
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003532 * admin, if specified, or all admins.
Robin Lee25e26452015-06-02 09:56:29 -07003533 * @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 +01003534 * have disabled screen capture.
3535 */
Robin Lee25e26452015-06-02 09:56:29 -07003536 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003537 throwIfParentInstance("getScreenCaptureDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003538 return getScreenCaptureDisabled(admin, myUserId());
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003539 }
3540
3541 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003542 public boolean getScreenCaptureDisabled(@Nullable ComponentName admin, int userHandle) {
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003543 if (mService != null) {
3544 try {
3545 return mService.getScreenCaptureDisabled(admin, userHandle);
3546 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003547 throw e.rethrowFromSystemServer();
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +01003548 }
3549 }
3550 return false;
3551 }
3552
3553 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003554 * Called by a device owner to set whether auto time is required. If auto time is required the
3555 * user cannot set the date and time, but has to use network date and time.
3556 * <p>
3557 * Note: if auto time is required the user can still manually set the time zone.
3558 * <p>
3559 * The calling device admin must be a device owner. If it is not, a security exception will be
3560 * thrown.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003561 *
3562 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3563 * @param required Whether auto time is set required or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003564 * @throws SecurityException if {@code admin} is not a device owner.
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003565 */
Robin Lee25e26452015-06-02 09:56:29 -07003566 public void setAutoTimeRequired(@NonNull ComponentName admin, boolean required) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003567 throwIfParentInstance("setAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003568 if (mService != null) {
3569 try {
Fyodor Kupolovbdc58c62015-01-29 13:24:03 -08003570 mService.setAutoTimeRequired(admin, required);
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003571 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003572 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003573 }
3574 }
3575 }
3576
3577 /**
3578 * @return true if auto time is required.
3579 */
3580 public boolean getAutoTimeRequired() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003581 throwIfParentInstance("getAutoTimeRequired");
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003582 if (mService != null) {
3583 try {
3584 return mService.getAutoTimeRequired();
3585 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003586 throw e.rethrowFromSystemServer();
Sander Alewijnse0ced6272014-08-26 11:18:26 +01003587 }
3588 }
3589 return false;
3590 }
3591
3592 /**
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003593 * Called by a device owner to set whether all users created on the device should be ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003594 * <p>
3595 * The system user is exempt from this policy - it is never ephemeral.
3596 * <p>
3597 * The calling device admin must be the device owner. If it is not, a security exception will be
3598 * thrown.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003599 *
3600 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
3601 * @param forceEphemeralUsers If true, all the existing users will be deleted and all
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003602 * subsequently created users will be ephemeral.
3603 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003604 * @hide
3605 */
3606 public void setForceEphemeralUsers(
3607 @NonNull ComponentName admin, boolean forceEphemeralUsers) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003608 throwIfParentInstance("setForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003609 if (mService != null) {
3610 try {
3611 mService.setForceEphemeralUsers(admin, forceEphemeralUsers);
3612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003613 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003614 }
3615 }
3616 }
3617
3618 /**
3619 * @return true if all users are created ephemeral.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003620 * @throws SecurityException if {@code admin} is not a device owner.
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003621 * @hide
3622 */
3623 public boolean getForceEphemeralUsers(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003624 throwIfParentInstance("getForceEphemeralUsers");
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003625 if (mService != null) {
3626 try {
3627 return mService.getForceEphemeralUsers(admin);
3628 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003629 throw e.rethrowFromSystemServer();
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +01003630 }
3631 }
3632 return false;
3633 }
3634
3635 /**
Jim Miller48b9b0d2012-09-19 23:16:50 -07003636 * Called by an application that is administering the device to disable keyguard customizations,
3637 * such as widgets. After setting this, keyguard features will be disabled according to the
3638 * provided feature list.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003639 * <p>
3640 * The calling device admin must have requested
3641 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
3642 * if it has not, a security exception will be thrown.
3643 * <p>
3644 * Calling this from a managed profile before version {@link android.os.Build.VERSION_CODES#M}
3645 * will throw a security exception. From version {@link android.os.Build.VERSION_CODES#M} the
3646 * profile owner of a managed profile can set:
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003647 * <ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003648 * <li>{@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which affects the parent user, but only if there
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003649 * is no separate challenge set on the managed profile.
Esteban Talaverac1c83592016-02-17 17:56:15 +00003650 * <li>{@link #KEYGUARD_DISABLE_FINGERPRINT} which affects the managed profile challenge if
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003651 * there is one, or the parent user otherwise.
3652 * <li>{@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS} which affects notifications generated
3653 * by applications in the managed profile.
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003654 * </ul>
Esteban Talaverac1c83592016-02-17 17:56:15 +00003655 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} and {@link #KEYGUARD_DISABLE_FINGERPRINT} can also be
3656 * set on the {@link DevicePolicyManager} instance returned by
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003657 * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
3658 * profile.
3659 * <p>
3660 * Requests to disable other features on a managed profile will be ignored.
3661 * <p>
3662 * The admin can check which features have been disabled by calling
Kenny Guy0b7dd1e2015-03-12 17:14:38 +00003663 * {@link #getKeyguardDisabledFeatures(ComponentName)}
Amith Yamasani242f4b12014-10-14 16:06:13 -07003664 *
Jim Millerb8ec4702012-08-31 17:19:10 -07003665 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Miller35207742012-11-02 15:33:20 -07003666 * @param which {@link #KEYGUARD_DISABLE_FEATURES_NONE} (default),
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07003667 * {@link #KEYGUARD_DISABLE_WIDGETS_ALL}, {@link #KEYGUARD_DISABLE_SECURE_CAMERA},
3668 * {@link #KEYGUARD_DISABLE_SECURE_NOTIFICATIONS},
3669 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS},
3670 * {@link #KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS},
3671 * {@link #KEYGUARD_DISABLE_FINGERPRINT}, {@link #KEYGUARD_DISABLE_FEATURES_ALL}
3672 * @throws SecurityException if {@code admin} is not an active administrator or does not user
3673 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Millerb8ec4702012-08-31 17:19:10 -07003674 */
Robin Lee25e26452015-06-02 09:56:29 -07003675 public void setKeyguardDisabledFeatures(@NonNull ComponentName admin, int which) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003676 if (mService != null) {
3677 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003678 mService.setKeyguardDisabledFeatures(admin, which, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003679 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003680 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003681 }
3682 }
3683 }
3684
3685 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08003686 * Determine whether or not features have been disabled in keyguard either by the calling
Rubin Xud3609d42016-07-13 18:32:57 +01003687 * admin, if specified, or all admins that set restrictions on this user and its participating
Esteban Talaverac1c83592016-02-17 17:56:15 +00003688 * profiles. Restrictions on profiles that have a separate challenge are not taken into account.
3689 *
3690 * <p>This method can be called on the {@link DevicePolicyManager} instance
3691 * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
3692 * restrictions on the parent profile.
3693 *
Esteban Talavera62399912016-01-11 15:37:55 +00003694 * @param admin The name of the admin component to check, or {@code null} to check whether any
3695 * admins have disabled features in keyguard.
Jim Miller35207742012-11-02 15:33:20 -07003696 * @return bitfield of flags. See {@link #setKeyguardDisabledFeatures(ComponentName, int)}
3697 * for a list.
Jim Millerb8ec4702012-08-31 17:19:10 -07003698 */
Robin Lee25e26452015-06-02 09:56:29 -07003699 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003700 return getKeyguardDisabledFeatures(admin, myUserId());
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003701 }
3702
3703 /** @hide per-user version */
Robin Lee25e26452015-06-02 09:56:29 -07003704 public int getKeyguardDisabledFeatures(@Nullable ComponentName admin, int userHandle) {
Jim Millerb8ec4702012-08-31 17:19:10 -07003705 if (mService != null) {
3706 try {
Esteban Talavera62399912016-01-11 15:37:55 +00003707 return mService.getKeyguardDisabledFeatures(admin, userHandle, mParentInstance);
Jim Millerb8ec4702012-08-31 17:19:10 -07003708 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003709 throw e.rethrowFromSystemServer();
Jim Millerb8ec4702012-08-31 17:19:10 -07003710 }
3711 }
Jim Miller48b9b0d2012-09-19 23:16:50 -07003712 return KEYGUARD_DISABLE_FEATURES_NONE;
Jim Millerb8ec4702012-08-31 17:19:10 -07003713 }
3714
3715 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003716 * @hide
3717 */
Robin Lee25e26452015-06-02 09:56:29 -07003718 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
3719 int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003720 if (mService != null) {
3721 try {
Jessica Hummel6d36b602014-04-04 12:42:17 +01003722 mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003723 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003724 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003725 }
3726 }
3727 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003728
Dianne Hackbornd6847842010-01-12 18:14:19 -08003729 /**
Jessica Hummel6d36b602014-04-04 12:42:17 +01003730 * @hide
3731 */
Robin Lee25e26452015-06-02 09:56:29 -07003732 public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003733 setActiveAdmin(policyReceiver, refreshing, myUserId());
Jessica Hummel6d36b602014-04-04 12:42:17 +01003734 }
3735
3736 /**
Dianne Hackbornd6847842010-01-12 18:14:19 -08003737 * @hide
3738 */
Robin Lee25e26452015-06-02 09:56:29 -07003739 public void getRemoveWarning(@Nullable ComponentName admin, RemoteCallback result) {
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003740 if (mService != null) {
3741 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07003742 mService.getRemoveWarning(admin, result, myUserId());
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003743 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003744 throw e.rethrowFromSystemServer();
Dianne Hackborn8ea138c2010-01-26 18:01:04 -08003745 }
3746 }
3747 }
3748
3749 /**
3750 * @hide
3751 */
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003752 public void setActivePasswordState(PasswordMetrics metrics, int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003753 if (mService != null) {
3754 try {
Andrew Scull5f9e6f32016-08-02 14:22:17 +01003755 mService.setActivePasswordState(metrics, userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003756 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003757 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003758 }
3759 }
3760 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003761
Dianne Hackbornd6847842010-01-12 18:14:19 -08003762 /**
3763 * @hide
3764 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003765 public void reportFailedPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003766 if (mService != null) {
3767 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003768 mService.reportFailedPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003769 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003770 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003771 }
3772 }
3773 }
Konstantin Lopyrev32558232010-05-20 16:18:05 -07003774
Dianne Hackbornd6847842010-01-12 18:14:19 -08003775 /**
3776 * @hide
3777 */
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003778 public void reportSuccessfulPasswordAttempt(int userHandle) {
Dianne Hackbornd6847842010-01-12 18:14:19 -08003779 if (mService != null) {
3780 try {
Amith Yamasani599dd7c2012-09-14 23:20:08 -07003781 mService.reportSuccessfulPasswordAttempt(userHandle);
Dianne Hackbornd6847842010-01-12 18:14:19 -08003782 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003783 throw e.rethrowFromSystemServer();
Dianne Hackbornd6847842010-01-12 18:14:19 -08003784 }
3785 }
3786 }
Amith Yamasani71e6c692013-03-24 17:39:28 -07003787
3788 /**
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003789 * @hide
3790 */
3791 public void reportFailedFingerprintAttempt(int userHandle) {
3792 if (mService != null) {
3793 try {
3794 mService.reportFailedFingerprintAttempt(userHandle);
3795 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003796 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003797 }
3798 }
3799 }
3800
3801 /**
3802 * @hide
3803 */
3804 public void reportSuccessfulFingerprintAttempt(int userHandle) {
3805 if (mService != null) {
3806 try {
3807 mService.reportSuccessfulFingerprintAttempt(userHandle);
3808 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003809 throw e.rethrowFromSystemServer();
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003810 }
3811 }
3812 }
3813
3814 /**
Michal Karpinski31502d32016-01-25 16:43:07 +00003815 * Should be called when keyguard has been dismissed.
3816 * @hide
3817 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003818 public void reportKeyguardDismissed(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003819 if (mService != null) {
3820 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003821 mService.reportKeyguardDismissed(userHandle);
Michal Karpinski31502d32016-01-25 16:43:07 +00003822 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003823 throw e.rethrowFromSystemServer();
Michal Karpinski31502d32016-01-25 16:43:07 +00003824 }
3825 }
3826 }
3827
3828 /**
3829 * Should be called when keyguard view has been shown to the user.
3830 * @hide
3831 */
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003832 public void reportKeyguardSecured(int userHandle) {
Michal Karpinski31502d32016-01-25 16:43:07 +00003833 if (mService != null) {
3834 try {
Michal Karpinskied5c8f02016-02-09 15:43:41 +00003835 mService.reportKeyguardSecured(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 /**
Amith Yamasani71e6c692013-03-24 17:39:28 -07003843 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003844 * Sets the given package as the device owner.
Makoto Onukia52562c2015-10-01 16:12:31 -07003845 * Same as {@link #setDeviceOwner(ComponentName, String)} but without setting a device owner name.
3846 * @param who the component name to be registered as device owner.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003847 * @return whether the package was successfully registered as the device owner.
3848 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003849 * @throws IllegalStateException If the preconditions mentioned are not met.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003850 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003851 public boolean setDeviceOwner(ComponentName who) {
3852 return setDeviceOwner(who, null);
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003853 }
3854
3855 /**
3856 * @hide
Makoto Onuki58b684f2015-09-04 10:48:16 -07003857 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003858 public boolean setDeviceOwner(ComponentName who, int userId) {
3859 return setDeviceOwner(who, null, userId);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003860 }
3861
3862 /**
3863 * @hide
3864 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003865 public boolean setDeviceOwner(ComponentName who, String ownerName) {
3866 return setDeviceOwner(who, ownerName, UserHandle.USER_SYSTEM);
Makoto Onuki58b684f2015-09-04 10:48:16 -07003867 }
3868
3869 /**
3870 * @hide
Nicolas Prevot28063742015-01-08 15:37:12 +00003871 * Sets the given package as the device owner. The package must already be installed. There
3872 * must not already be a device owner.
3873 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
3874 * this method.
3875 * Calling this after the setup phase of the primary user has completed is allowed only if
3876 * the caller is the shell uid, and there are no additional users and no accounts.
Makoto Onukia52562c2015-10-01 16:12:31 -07003877 * @param who the component name to be registered as device owner.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003878 * @param ownerName the human readable name of the institution that owns this device.
Makoto Onuki58b684f2015-09-04 10:48:16 -07003879 * @param userId ID of the user on which the device owner runs.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003880 * @return whether the package was successfully registered as the device owner.
3881 * @throws IllegalArgumentException if the package name is null or invalid
Nicolas Prevot28063742015-01-08 15:37:12 +00003882 * @throws IllegalStateException If the preconditions mentioned are not met.
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003883 */
Makoto Onukia52562c2015-10-01 16:12:31 -07003884 public boolean setDeviceOwner(ComponentName who, String ownerName, int userId)
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04003885 throws IllegalArgumentException, IllegalStateException {
Amith Yamasani71e6c692013-03-24 17:39:28 -07003886 if (mService != null) {
3887 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07003888 return mService.setDeviceOwner(who, ownerName, userId);
Amith Yamasani71e6c692013-03-24 17:39:28 -07003889 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003890 throw re.rethrowFromSystemServer();
Amith Yamasani71e6c692013-03-24 17:39:28 -07003891 }
3892 }
3893 return false;
3894 }
3895
3896 /**
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003897 * Used to determine if a particular package has been registered as a Device Owner app.
3898 * A device owner app is a special device admin that cannot be deactivated by the user, once
Robin Lee25e26452015-06-02 09:56:29 -07003899 * activated as a device admin. It also cannot be uninstalled. To check whether a particular
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003900 * package is currently registered as the device owner app, pass in the package name from
3901 * {@link Context#getPackageName()} to this method.<p/>This is useful for device
Robin Lee25e26452015-06-02 09:56:29 -07003902 * admin apps that want to check whether they are also registered as the device owner app. The
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003903 * exact mechanism by which a device admin app is registered as a device owner app is defined by
3904 * the setup process.
3905 * @param packageName the package name of the app, to compare with the registered device owner
3906 * app, if any.
Makoto Onukic8a5a552015-11-19 14:29:12 -08003907 * @return whether or not the package is registered as the device owner app.
Amith Yamasani71e6c692013-03-24 17:39:28 -07003908 */
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003909 public boolean isDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01003910 throwIfParentInstance("isDeviceOwnerApp");
Makoto Onukic8a5a552015-11-19 14:29:12 -08003911 return isDeviceOwnerAppOnCallingUser(packageName);
3912 }
3913
3914 /**
3915 * @return true if a package is registered as device owner, only when it's running on the
3916 * calling user.
3917 *
3918 * <p>Same as {@link #isDeviceOwnerApp}, but bundled code should use it for clarity.
3919 * @hide
3920 */
3921 public boolean isDeviceOwnerAppOnCallingUser(String packageName) {
3922 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ true);
3923 }
3924
3925 /**
3926 * @return true if a package is registered as device owner, even if it's running on a different
3927 * user.
3928 *
3929 * <p>Requires the MANAGE_USERS permission.
3930 *
3931 * @hide
3932 */
3933 public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
3934 return isDeviceOwnerAppOnAnyUserInner(packageName, /* callingUserOnly =*/ false);
3935 }
3936
3937 /**
3938 * @return device owner component name, only when it's running on the calling user.
3939 *
3940 * @hide
3941 */
3942 public ComponentName getDeviceOwnerComponentOnCallingUser() {
3943 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ true);
3944 }
3945
3946 /**
3947 * @return device owner component name, even if it's running on a different user.
3948 *
3949 * <p>Requires the MANAGE_USERS permission.
3950 *
3951 * @hide
3952 */
Polina Bondarenko23561db2016-12-16 11:47:28 +01003953 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08003954 public ComponentName getDeviceOwnerComponentOnAnyUser() {
3955 return getDeviceOwnerComponentInner(/* callingUserOnly =*/ false);
3956 }
3957
3958 private boolean isDeviceOwnerAppOnAnyUserInner(String packageName, boolean callingUserOnly) {
Makoto Onuki70f929e2015-11-11 12:40:15 -08003959 if (packageName == null) {
3960 return false;
Amith Yamasani71e6c692013-03-24 17:39:28 -07003961 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08003962 final ComponentName deviceOwner = getDeviceOwnerComponentInner(callingUserOnly);
Makoto Onuki70f929e2015-11-11 12:40:15 -08003963 if (deviceOwner == null) {
3964 return false;
3965 }
3966 return packageName.equals(deviceOwner.getPackageName());
Amith Yamasani71e6c692013-03-24 17:39:28 -07003967 }
3968
Makoto Onukic8a5a552015-11-19 14:29:12 -08003969 private ComponentName getDeviceOwnerComponentInner(boolean callingUserOnly) {
3970 if (mService != null) {
3971 try {
3972 return mService.getDeviceOwnerComponent(callingUserOnly);
3973 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003974 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003975 }
3976 }
3977 return null;
Amith Yamasani3b458ad2013-04-18 18:40:07 -07003978 }
3979
Jason Monkb0dced82014-06-06 14:36:20 -04003980 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08003981 * @return ID of the user who runs device owner, or {@link UserHandle#USER_NULL} if there's
3982 * no device owner.
3983 *
3984 * <p>Requires the MANAGE_USERS permission.
Makoto Onukia52562c2015-10-01 16:12:31 -07003985 *
3986 * @hide
3987 */
Makoto Onukic8a5a552015-11-19 14:29:12 -08003988 public int getDeviceOwnerUserId() {
3989 if (mService != null) {
3990 try {
3991 return mService.getDeviceOwnerUserId();
3992 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07003993 throw re.rethrowFromSystemServer();
Makoto Onukic8a5a552015-11-19 14:29:12 -08003994 }
3995 }
3996 return UserHandle.USER_NULL;
Makoto Onukia52562c2015-10-01 16:12:31 -07003997 }
3998
3999 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004000 * Clears the current device owner. The caller must be the device owner. This function should be
4001 * used cautiously as once it is called it cannot be undone. The device owner can only be set as
4002 * a part of device setup before setup completes.
Jason Monk94d2cf92014-06-18 09:53:34 -04004003 *
4004 * @param packageName The package name of the device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004005 * @throws SecurityException if the caller is not in {@code packageName} or {@code packageName}
4006 * does not own the current device owner component.
Jason Monkb0dced82014-06-06 14:36:20 -04004007 */
Jason Monk94d2cf92014-06-18 09:53:34 -04004008 public void clearDeviceOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004009 throwIfParentInstance("clearDeviceOwnerApp");
Jason Monkb0dced82014-06-06 14:36:20 -04004010 if (mService != null) {
4011 try {
Jason Monk94d2cf92014-06-18 09:53:34 -04004012 mService.clearDeviceOwner(packageName);
Jason Monkb0dced82014-06-06 14:36:20 -04004013 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004014 throw re.rethrowFromSystemServer();
Jason Monkb0dced82014-06-06 14:36:20 -04004015 }
4016 }
4017 }
4018
Makoto Onukia52562c2015-10-01 16:12:31 -07004019 /**
Makoto Onukic8a5a552015-11-19 14:29:12 -08004020 * Returns the device owner package name, only if it's running on the calling user.
4021 *
4022 * <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
Makoto Onukia52562c2015-10-01 16:12:31 -07004023 *
4024 * @hide
4025 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004026 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004027 public @Nullable String getDeviceOwner() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004028 throwIfParentInstance("getDeviceOwner");
Makoto Onukic8a5a552015-11-19 14:29:12 -08004029 final ComponentName name = getDeviceOwnerComponentOnCallingUser();
4030 return name != null ? name.getPackageName() : null;
Makoto Onukia52562c2015-10-01 16:12:31 -07004031 }
4032
4033 /**
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004034 * Called by the system to find out whether the device is managed by a Device Owner.
Makoto Onukic8a5a552015-11-19 14:29:12 -08004035 *
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004036 * @return whether the device is managed by a Device Owner.
4037 * @throws SecurityException if the caller is not the device owner, does not hold the
4038 * MANAGE_USERS permission and is not the system.
Makoto Onukia52562c2015-10-01 16:12:31 -07004039 *
4040 * @hide
4041 */
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004042 @SystemApi
4043 @TestApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004044 public boolean isDeviceManaged() {
Bartosz Fabianowskidd7f8da2016-11-30 11:09:22 +01004045 try {
4046 return mService.hasDeviceOwner();
4047 } catch (RemoteException re) {
4048 throw re.rethrowFromSystemServer();
4049 }
Makoto Onukic8a5a552015-11-19 14:29:12 -08004050 }
4051
4052 /**
4053 * Returns the device owner name. Note this method *will* return the device owner
4054 * name when it's running on a different user.
4055 *
4056 * <p>Requires the MANAGE_USERS permission.
4057 *
4058 * @hide
4059 */
Makoto Onukia2b274b2016-01-19 13:26:02 -08004060 @SystemApi
Makoto Onukic8a5a552015-11-19 14:29:12 -08004061 public String getDeviceOwnerNameOnAnyUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004062 throwIfParentInstance("getDeviceOwnerNameOnAnyUser");
Amith Yamasani71e6c692013-03-24 17:39:28 -07004063 if (mService != null) {
4064 try {
Makoto Onukia52562c2015-10-01 16:12:31 -07004065 return mService.getDeviceOwnerName();
Amith Yamasani71e6c692013-03-24 17:39:28 -07004066 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004067 throw re.rethrowFromSystemServer();
Geoffrey Borggaard334c7e32013-08-08 14:31:36 -04004068 }
4069 }
4070 return null;
4071 }
Adam Connors776c5552014-01-09 10:42:56 +00004072
4073 /**
Julia Reynolds94e7bf62015-06-10 14:44:56 -04004074 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004075 * @deprecated Do not use
4076 * @removed
Julia Reynolds20118f12015-02-11 12:34:08 -05004077 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004078 @Deprecated
Julia Reynolds20118f12015-02-11 12:34:08 -05004079 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004080 public @Nullable String getDeviceInitializerApp() {
Julia Reynolds20118f12015-02-11 12:34:08 -05004081 return null;
4082 }
4083
4084 /**
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004085 * @hide
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004086 * @deprecated Do not use
4087 * @removed
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004088 */
Craig Lafayettee7ee54e2015-09-21 13:48:53 -04004089 @Deprecated
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004090 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004091 public @Nullable ComponentName getDeviceInitializerComponent() {
Julia Reynoldseaafdf722015-04-02 08:49:47 -04004092 return null;
4093 }
4094
Julia Reynolds20118f12015-02-11 12:34:08 -05004095 /**
Adam Connors776c5552014-01-09 10:42:56 +00004096 * @hide
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004097 * @deprecated Use #ACTION_SET_PROFILE_OWNER
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304098 * Sets the given component as an active admin and registers the package as the profile
4099 * owner for this user. The package must already be installed and there shouldn't be
4100 * an existing profile owner registered for this user. Also, this method must be called
4101 * before the user setup has been completed.
4102 * <p>
4103 * This method can only be called by system apps that hold MANAGE_USERS permission and
4104 * MANAGE_DEVICE_ADMINS permission.
4105 * @param admin The component to register as an active admin and profile owner.
4106 * @param ownerName The user-visible name of the entity that is managing this user.
4107 * @return whether the admin was successfully registered as the profile owner.
4108 * @throws IllegalArgumentException if packageName is null, the package isn't installed, or
4109 * the user has already been set up.
4110 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004111 @Deprecated
Justin Morey80440cc2014-07-24 09:16:35 -05004112 @SystemApi
Robin Lee25e26452015-06-02 09:56:29 -07004113 public boolean setActiveProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName)
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304114 throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004115 throwIfParentInstance("setActiveProfileOwner");
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304116 if (mService != null) {
4117 try {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004118 final int myUserId = myUserId();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304119 mService.setActiveAdmin(admin, false, myUserId);
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004120 return mService.setProfileOwner(admin, ownerName, myUserId);
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304121 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004122 throw re.rethrowFromSystemServer();
Amith Yamasaniaba4f1b2014-07-01 15:36:12 +05304123 }
4124 }
4125 return false;
4126 }
4127
4128 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004129 * Clears the active profile owner and removes all user restrictions. The caller must be from
4130 * the same package as the active profile owner for this user, otherwise a SecurityException
4131 * will be thrown.
4132 * <p>
4133 * This doesn't work for managed profile owners.
Makoto Onuki5bf68022016-01-27 13:49:19 -08004134 *
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004135 * @param admin The component to remove as the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004136 * @throws SecurityException if {@code admin} is not an active profile owner.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004137 */
Robin Lee25e26452015-06-02 09:56:29 -07004138 public void clearProfileOwner(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004139 throwIfParentInstance("clearProfileOwner");
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004140 if (mService != null) {
4141 try {
4142 mService.clearProfileOwner(admin);
4143 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004144 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004145 }
4146 }
4147 }
4148
4149 /**
Julia Reynoldse9254402015-02-11 12:34:08 -05004150 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004151 * Checks whether the user was already setup.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004152 */
4153 public boolean hasUserSetupCompleted() {
4154 if (mService != null) {
4155 try {
4156 return mService.hasUserSetupCompleted();
4157 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004158 throw re.rethrowFromSystemServer();
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004159 }
4160 }
4161 return true;
4162 }
4163
4164 /**
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004165 * @hide
4166 * Sets the given component as the profile owner of the given user profile. The package must
Nicolas Prevot28063742015-01-08 15:37:12 +00004167 * already be installed. There must not already be a profile owner for this user.
4168 * Only apps with the MANAGE_PROFILE_AND_DEVICE_OWNERS permission and the shell uid can call
4169 * this method.
4170 * Calling this after the setup phase of the specified user has completed is allowed only if:
4171 * - the caller is SYSTEM_UID.
4172 * - or the caller is the shell uid, and there are no accounts on the specified user.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004173 * @param admin the component name to be registered as profile owner.
4174 * @param ownerName the human readable name of the organisation associated with this DPM.
4175 * @param userHandle the userId to set the profile owner for.
4176 * @return whether the component was successfully registered as the profile owner.
Nicolas Prevot28063742015-01-08 15:37:12 +00004177 * @throws IllegalArgumentException if admin is null, the package isn't installed, or the
4178 * preconditions mentioned are not met.
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004179 */
Robin Lee25e26452015-06-02 09:56:29 -07004180 public boolean setProfileOwner(@NonNull ComponentName admin, @Deprecated String ownerName,
Robin Leeddd553f2015-04-30 14:18:22 +01004181 int userHandle) throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004182 if (mService != null) {
4183 try {
Amith Yamasanibf3a9462014-07-28 14:26:42 -07004184 if (ownerName == null) {
4185 ownerName = "";
4186 }
4187 return mService.setProfileOwner(admin, ownerName, userHandle);
Adam Connors776c5552014-01-09 10:42:56 +00004188 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004189 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004190 }
4191 }
4192 return false;
4193 }
4194
4195 /**
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004196 * Sets the device owner information to be shown on the lock screen.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004197 * <p>
4198 * If the device owner information is {@code null} or empty then the device owner info is
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004199 * cleared and the user owner info is shown on the lock screen if it is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004200 * <p>
4201 * If the device owner information contains only whitespaces then the message on the lock screen
4202 * will be blank and the user will not be allowed to change it.
4203 * <p>
4204 * If the device owner information needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00004205 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
4206 * and set a new version of this string accordingly.
4207 *
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004208 * @param admin The name of the admin component to check.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004209 * @param info Device owner information which will be displayed instead of the user owner info.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004210 * @throws SecurityException if {@code admin} is not a device owner.
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004211 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004212 public void setDeviceOwnerLockScreenInfo(@NonNull ComponentName admin, CharSequence info) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004213 throwIfParentInstance("setDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004214 if (mService != null) {
4215 try {
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004216 mService.setDeviceOwnerLockScreenInfo(admin, info);
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004217 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004218 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004219 }
4220 }
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004221 }
4222
4223 /**
4224 * @return The device owner information. If it is not set returns {@code null}.
4225 */
Andrei Stingaceanu16187902016-03-21 15:44:45 +00004226 public CharSequence getDeviceOwnerLockScreenInfo() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004227 throwIfParentInstance("getDeviceOwnerLockScreenInfo");
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004228 if (mService != null) {
4229 try {
4230 return mService.getDeviceOwnerLockScreenInfo();
4231 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004232 throw re.rethrowFromSystemServer();
Andrei Stingaceanu6644cd92015-11-10 13:03:31 +00004233 }
4234 }
4235 return null;
4236 }
4237
4238 /**
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004239 * Called by device or profile owners to suspend packages for this user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004240 * <p>
4241 * A suspended package will not be able to start activities. Its notifications will be hidden,
4242 * it will not show up in recents, will not be able to show toasts or dialogs or ring the
4243 * device.
4244 * <p>
4245 * The package must already be installed. If the package is uninstalled while suspended the
4246 * package will no longer be suspended. The admin can block this by using
Kenny Guy871f3eb2016-03-09 20:06:16 +00004247 * {@link #setUninstallBlocked}.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004248 *
4249 * @param admin The name of the admin component to check.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004250 * @param packageNames The package names to suspend or unsuspend.
4251 * @param suspended If set to {@code true} than the packages will be suspended, if set to
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004252 * {@code false} the packages will be unsuspended.
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004253 * @return an array of package names for which the suspended status is not set as requested in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004254 * this method.
4255 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004256 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004257 public @NonNull String[] setPackagesSuspended(@NonNull ComponentName admin,
4258 @NonNull String[] packageNames, boolean suspended) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004259 throwIfParentInstance("setPackagesSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004260 if (mService != null) {
4261 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004262 return mService.setPackagesSuspended(admin, packageNames, suspended);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004263 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004264 throw re.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004265 }
4266 }
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00004267 return packageNames;
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004268 }
4269
4270 /**
4271 * Called by device or profile owners to determine if a package is suspended.
4272 *
4273 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4274 * @param packageName The name of the package to retrieve the suspended status of.
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00004275 * @return {@code true} if the package is suspended or {@code false} if the package is not
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004276 * suspended, could not be found or an error occurred.
4277 * @throws SecurityException if {@code admin} is not a device or profile owner.
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004278 * @throws NameNotFoundException if the package could not be found.
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004279 */
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004280 public boolean isPackageSuspended(@NonNull ComponentName admin, String packageName)
4281 throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004282 throwIfParentInstance("isPackageSuspended");
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004283 if (mService != null) {
4284 try {
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004285 return mService.isPackageSuspended(admin, packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004286 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004287 throw e.rethrowFromSystemServer();
Andrei Stingaceanuefc4a342016-03-22 14:43:01 +00004288 } catch (IllegalArgumentException ex) {
4289 throw new NameNotFoundException(packageName);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00004290 }
4291 }
4292 return false;
4293 }
4294
4295 /**
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004296 * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
4297 * be used. Only the profile owner can call this.
4298 *
Alexandra Gherghinadf35d572014-04-09 13:54:39 +01004299 * @see #isProfileOwnerApp
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004300 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004301 * @throws SecurityException if {@code admin} is not a profile owner.
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004302 */
Robin Lee25e26452015-06-02 09:56:29 -07004303 public void setProfileEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004304 throwIfParentInstance("setProfileEnabled");
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004305 if (mService != null) {
4306 try {
4307 mService.setProfileEnabled(admin);
4308 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004309 throw e.rethrowFromSystemServer();
Alexandra Gherghina512675b2014-04-02 11:23:54 +01004310 }
4311 }
4312 }
4313
4314 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004315 * Sets the name of the profile. In the device owner case it sets the name of the user which it
4316 * is called from. Only a profile owner or device owner can call this. If this is never called
4317 * by the profile or device owner, the name will be set to default values.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004318 *
4319 * @see #isProfileOwnerApp
4320 * @see #isDeviceOwnerApp
Robin Lee25e26452015-06-02 09:56:29 -07004321 * @param admin Which {@link DeviceAdminReceiver} this request is associate with.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004322 * @param profileName The name of the profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004323 * @throws SecurityException if {@code admin} is not a device or profile owner.
Jessica Hummel1333ea12014-06-23 11:20:10 +01004324 */
Robin Lee25e26452015-06-02 09:56:29 -07004325 public void setProfileName(@NonNull ComponentName admin, String profileName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004326 throwIfParentInstance("setProfileName");
Jessica Hummel1333ea12014-06-23 11:20:10 +01004327 if (mService != null) {
4328 try {
Robin Lee25e26452015-06-02 09:56:29 -07004329 mService.setProfileName(admin, profileName);
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004330 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004331 throw e.rethrowFromSystemServer();
Fyodor Kupolov78f13142015-05-27 16:52:45 -07004332 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004333 }
4334 }
Jessica Hummel1333ea12014-06-23 11:20:10 +01004335
4336 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004337 * Used to determine if a particular package is registered as the profile owner for the
Makoto Onuki32b30572015-12-11 14:29:51 -08004338 * user. A profile owner is a special device admin that has additional privileges
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004339 * within the profile.
Adam Connors776c5552014-01-09 10:42:56 +00004340 *
4341 * @param packageName The package name of the app to compare with the registered profile owner.
4342 * @return Whether or not the package is registered as the profile owner.
4343 */
4344 public boolean isProfileOwnerApp(String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004345 throwIfParentInstance("isProfileOwnerApp");
Adam Connors776c5552014-01-09 10:42:56 +00004346 if (mService != null) {
4347 try {
Makoto Onuki90b89652016-01-28 14:44:18 -08004348 ComponentName profileOwner = mService.getProfileOwner(myUserId());
Nicolas Prevot90af6d72014-07-30 14:19:12 +01004349 return profileOwner != null
4350 && profileOwner.getPackageName().equals(packageName);
Adam Connors776c5552014-01-09 10:42:56 +00004351 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004352 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004353 }
4354 }
4355 return false;
4356 }
4357
4358 /**
4359 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004360 * @return the packageName of the owner of the given user profile or {@code null} if no profile
Adam Connors776c5552014-01-09 10:42:56 +00004361 * owner has been set for that user.
4362 * @throws IllegalArgumentException if the userId is invalid.
4363 */
Nicolas Prevot465acf32014-08-06 17:03:25 +01004364 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004365 public @Nullable ComponentName getProfileOwner() throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004366 throwIfParentInstance("getProfileOwner");
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004367 return getProfileOwnerAsUser(Process.myUserHandle().getIdentifier());
4368 }
4369
4370 /**
4371 * @see #getProfileOwner()
4372 * @hide
4373 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004374 public @Nullable ComponentName getProfileOwnerAsUser(final int userId)
4375 throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004376 if (mService != null) {
4377 try {
Zoltan Szatmary-Ban3f1ddf82014-07-02 16:42:05 +01004378 return mService.getProfileOwner(userId);
Adam Connors776c5552014-01-09 10:42:56 +00004379 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004380 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004381 }
4382 }
4383 return null;
4384 }
4385
4386 /**
4387 * @hide
Robin Lee25e26452015-06-02 09:56:29 -07004388 * @return the human readable name of the organisation associated with this DPM or {@code null}
4389 * if one is not set.
Adam Connors776c5552014-01-09 10:42:56 +00004390 * @throws IllegalArgumentException if the userId is invalid.
4391 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004392 public @Nullable String getProfileOwnerName() throws IllegalArgumentException {
Adam Connors776c5552014-01-09 10:42:56 +00004393 if (mService != null) {
4394 try {
4395 return mService.getProfileOwnerName(Process.myUserHandle().getIdentifier());
4396 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004397 throw re.rethrowFromSystemServer();
Adam Connors776c5552014-01-09 10:42:56 +00004398 }
4399 }
4400 return null;
4401 }
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004402
4403 /**
Amith Yamasani38f836b2014-08-20 14:51:15 -07004404 * @hide
Makoto Onukic8a5a552015-11-19 14:29:12 -08004405 * @param userId The user for whom to fetch the profile owner name, if any.
Amith Yamasani38f836b2014-08-20 14:51:15 -07004406 * @return the human readable name of the organisation associated with this profile owner or
4407 * null if one is not set.
4408 * @throws IllegalArgumentException if the userId is invalid.
4409 */
4410 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07004411 public @Nullable String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004412 throwIfParentInstance("getProfileOwnerNameAsUser");
Amith Yamasani38f836b2014-08-20 14:51:15 -07004413 if (mService != null) {
4414 try {
Selim Cinek24ac55e2014-08-27 12:51:45 +02004415 return mService.getProfileOwnerName(userId);
Amith Yamasani38f836b2014-08-20 14:51:15 -07004416 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004417 throw re.rethrowFromSystemServer();
Amith Yamasani38f836b2014-08-20 14:51:15 -07004418 }
4419 }
4420 return null;
4421 }
4422
4423 /**
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004424 * Called by a profile owner or device owner to add a default intent handler activity for
4425 * intents that match a certain intent filter. This activity will remain the default intent
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004426 * handler even if the set of potential event handlers for the intent filter changes and if the
4427 * intent preferences are reset.
4428 * <p>
4429 * The default disambiguation mechanism takes over if the activity is not installed (anymore).
4430 * When the activity is (re)installed, it is automatically reset as default intent handler for
4431 * the filter.
4432 * <p>
4433 * The calling device admin must be a profile owner or device owner. If it is not, a security
4434 * exception will be thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004435 *
4436 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4437 * @param filter The IntentFilter for which a default handler is added.
4438 * @param activity The Activity that is added as default intent handler.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004439 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004440 */
Robin Lee25e26452015-06-02 09:56:29 -07004441 public void addPersistentPreferredActivity(@NonNull ComponentName admin, IntentFilter filter,
4442 @NonNull ComponentName activity) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004443 throwIfParentInstance("addPersistentPreferredActivity");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004444 if (mService != null) {
4445 try {
4446 mService.addPersistentPreferredActivity(admin, filter, activity);
4447 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004448 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004449 }
4450 }
4451 }
4452
4453 /**
4454 * Called by a profile owner or device owner to remove all persistent intent handler preferences
Torne (Richard Coles)875e2102014-02-24 14:11:56 +00004455 * associated with the given package that were set by {@link #addPersistentPreferredActivity}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004456 * <p>
4457 * The calling device admin must be a profile owner. If it is not, a security exception will be
4458 * thrown.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004459 *
4460 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4461 * @param packageName The name of the package for which preferences are removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004462 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004463 */
Robin Lee25e26452015-06-02 09:56:29 -07004464 public void clearPackagePersistentPreferredActivities(@NonNull ComponentName admin,
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004465 String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004466 throwIfParentInstance("clearPackagePersistentPreferredActivities");
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004467 if (mService != null) {
4468 try {
4469 mService.clearPackagePersistentPreferredActivities(admin, packageName);
4470 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004471 throw e.rethrowFromSystemServer();
Sander Alewijnsef475ca32014-02-17 15:13:58 +00004472 }
4473 }
4474 }
Robin Lee66e5d962014-04-09 16:44:21 +01004475
4476 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00004477 * Called by a profile owner or device owner to grant permission to a package to manage
4478 * application restrictions for the calling user via {@link #setApplicationRestrictions} and
4479 * {@link #getApplicationRestrictions}.
4480 * <p>
4481 * This permission is persistent until it is later cleared by calling this method with a
4482 * {@code null} value or uninstalling the managing package.
Rubin Xuf03d0a62016-02-10 14:54:15 +00004483 * <p>
4484 * The supplied application restriction managing package must be installed when calling this
Victor Changcd14c0a2016-03-16 19:10:15 +00004485 * API, otherwise an {@link NameNotFoundException} will be thrown.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004486 *
4487 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4488 * @param packageName The package name which will be given access to application restrictions
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004489 * APIs. If {@code null} is given the current package will be cleared.
4490 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Changcd14c0a2016-03-16 19:10:15 +00004491 * @throws NameNotFoundException if {@code packageName} is not found
Esteban Talaverabf60f722015-12-10 16:26:44 +00004492 */
4493 public void setApplicationRestrictionsManagingPackage(@NonNull ComponentName admin,
Victor Changcd14c0a2016-03-16 19:10:15 +00004494 @Nullable String packageName) throws NameNotFoundException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004495 throwIfParentInstance("setApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004496 if (mService != null) {
4497 try {
Victor Changcd14c0a2016-03-16 19:10:15 +00004498 if (!mService.setApplicationRestrictionsManagingPackage(admin, packageName)) {
4499 throw new NameNotFoundException(packageName);
4500 }
Esteban Talaverabf60f722015-12-10 16:26:44 +00004501 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004502 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004503 }
4504 }
4505 }
4506
4507 /**
4508 * Called by a profile owner or device owner to retrieve the application restrictions managing
4509 * package for the current user, or {@code null} if none is set.
4510 *
4511 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4512 * @return The package name allowed to manage application restrictions on the current user, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004513 * {@code null} if none is set.
4514 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004515 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004516 public @Nullable String getApplicationRestrictionsManagingPackage(
4517 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004518 throwIfParentInstance("getApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004519 if (mService != null) {
4520 try {
4521 return mService.getApplicationRestrictionsManagingPackage(admin);
4522 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004523 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004524 }
4525 }
4526 return null;
4527 }
4528
4529 /**
Esteban Talavera96895ca2016-03-16 12:00:40 +00004530 * Called by any application to find out whether it has been granted permission via
4531 * {@link #setApplicationRestrictionsManagingPackage} to manage application restrictions
4532 * for the calling user.
4533 *
4534 * <p>This is done by comparing the calling Linux uid with the uid of the package specified by
4535 * that method.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004536 */
4537 public boolean isCallerApplicationRestrictionsManagingPackage() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004538 throwIfParentInstance("isCallerApplicationRestrictionsManagingPackage");
Esteban Talaverabf60f722015-12-10 16:26:44 +00004539 if (mService != null) {
4540 try {
4541 return mService.isCallerApplicationRestrictionsManagingPackage();
4542 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004543 throw e.rethrowFromSystemServer();
Esteban Talaverabf60f722015-12-10 16:26:44 +00004544 }
4545 }
4546 return false;
4547 }
4548
4549 /**
4550 * Sets the application restrictions for a given target application running in the calling user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004551 * <p>
4552 * The caller must be a profile or device owner on that user, or the package allowed to manage
4553 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
4554 * security exception will be thrown.
4555 * <p>
4556 * The provided {@link Bundle} consists of key-value pairs, where the types of values may be:
Esteban Talavera6b8e0642015-08-10 17:26:04 +01004557 * <ul>
4558 * <li>{@code boolean}
4559 * <li>{@code int}
4560 * <li>{@code String} or {@code String[]}
4561 * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
4562 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004563 * <p>
4564 * If the restrictions are not available yet, but may be applied in the near future, the caller
4565 * can notify the target application of that by adding
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004566 * {@link UserManager#KEY_RESTRICTIONS_PENDING} to the settings parameter.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004567 * <p>
4568 * The application restrictions are only made visible to the target application via
4569 * {@link UserManager#getApplicationRestrictions(String)}, in addition to the profile or device
4570 * owner, and the application restrictions managing package via
Esteban Talaverabf60f722015-12-10 16:26:44 +00004571 * {@link #getApplicationRestrictions}.
Robin Lee66e5d962014-04-09 16:44:21 +01004572 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004573 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
4574 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00004575 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004576 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01004577 * @param packageName The name of the package to update restricted settings for.
4578 * @param settings A {@link Bundle} to be parsed by the receiving application, conveying a new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004579 * set of active restrictions.
4580 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00004581 * @see #setApplicationRestrictionsManagingPackage
Sander Alewijnse53d63dc2014-11-07 21:43:00 +00004582 * @see UserManager#KEY_RESTRICTIONS_PENDING
Robin Lee66e5d962014-04-09 16:44:21 +01004583 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07004584 @WorkerThread
Esteban Talaverabf60f722015-12-10 16:26:44 +00004585 public void setApplicationRestrictions(@Nullable ComponentName admin, String packageName,
Robin Lee66e5d962014-04-09 16:44:21 +01004586 Bundle settings) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004587 throwIfParentInstance("setApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01004588 if (mService != null) {
4589 try {
4590 mService.setApplicationRestrictions(admin, packageName, settings);
4591 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004592 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01004593 }
4594 }
4595 }
4596
4597 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004598 * Sets a list of configuration features to enable for a TrustAgent component. This is meant to
4599 * be used in conjunction with {@link #KEYGUARD_DISABLE_TRUST_AGENTS}, which disables all trust
4600 * agents but those enabled by this function call. If flag
Jim Millere303bf42014-08-26 17:12:29 -07004601 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is not set, then this call has no effect.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004602 * <p>
4603 * The calling device admin must have requested
4604 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call this method;
4605 * if not, a security exception will be thrown.
Tony Mak089d8402016-04-05 17:42:55 +01004606 * <p>
4607 * This method can be called on the {@link DevicePolicyManager} instance returned by
4608 * {@link #getParentProfileInstance(ComponentName)} in order to set the configuration for
4609 * the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004610 *
4611 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Jim Millere303bf42014-08-26 17:12:29 -07004612 * @param target Component name of the agent to be enabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004613 * @param configuration TrustAgent-specific feature bundle. If null for any admin, agent will be
4614 * strictly disabled according to the state of the
4615 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} flag.
4616 * <p>
4617 * If {@link #KEYGUARD_DISABLE_TRUST_AGENTS} is set and options is not null for all
4618 * admins, then it's up to the TrustAgent itself to aggregate the values from all
4619 * device admins.
4620 * <p>
4621 * Consult documentation for the specific TrustAgent to determine legal options
4622 * parameters.
4623 * @throws SecurityException if {@code admin} is not an active administrator or does not use
4624 * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES}
Jim Miller604e7552014-07-18 19:00:02 -07004625 */
Robin Lee25e26452015-06-02 09:56:29 -07004626 public void setTrustAgentConfiguration(@NonNull ComponentName admin,
4627 @NonNull ComponentName target, PersistableBundle configuration) {
Jim Miller604e7552014-07-18 19:00:02 -07004628 if (mService != null) {
4629 try {
Tony Mak089d8402016-04-05 17:42:55 +01004630 mService.setTrustAgentConfiguration(admin, target, configuration, mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004631 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004632 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004633 }
4634 }
4635 }
4636
4637 /**
Jim Millere303bf42014-08-26 17:12:29 -07004638 * Gets configuration for the given trust agent based on aggregating all calls to
4639 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)} for
4640 * all device admins.
Tony Mak089d8402016-04-05 17:42:55 +01004641 * <p>
4642 * This method can be called on the {@link DevicePolicyManager} instance returned by
4643 * {@link #getParentProfileInstance(ComponentName)} in order to retrieve the configuration set
4644 * on the parent profile.
Jim Miller604e7552014-07-18 19:00:02 -07004645 *
Jim Millerb5db57a2015-01-14 18:17:19 -08004646 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. If null,
4647 * this function returns a list of configurations for all admins that declare
4648 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS}. If any admin declares
4649 * {@link #KEYGUARD_DISABLE_TRUST_AGENTS} but doesn't call
4650 * {@link #setTrustAgentConfiguration(ComponentName, ComponentName, PersistableBundle)}
4651 * for this {@param agent} or calls it with a null configuration, null is returned.
Jim Miller604e7552014-07-18 19:00:02 -07004652 * @param agent Which component to get enabled features for.
Jim Millere303bf42014-08-26 17:12:29 -07004653 * @return configuration for the given trust agent.
Jim Miller604e7552014-07-18 19:00:02 -07004654 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004655 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4656 @Nullable ComponentName admin, @NonNull ComponentName agent) {
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07004657 return getTrustAgentConfiguration(admin, agent, myUserId());
Jim Millere303bf42014-08-26 17:12:29 -07004658 }
4659
4660 /** @hide per-user version */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004661 public @Nullable List<PersistableBundle> getTrustAgentConfiguration(
4662 @Nullable ComponentName admin, @NonNull ComponentName agent, int userHandle) {
Jim Miller604e7552014-07-18 19:00:02 -07004663 if (mService != null) {
4664 try {
Tony Mak089d8402016-04-05 17:42:55 +01004665 return mService.getTrustAgentConfiguration(admin, agent, userHandle,
4666 mParentInstance);
Jim Miller604e7552014-07-18 19:00:02 -07004667 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004668 throw e.rethrowFromSystemServer();
Jim Miller604e7552014-07-18 19:00:02 -07004669 }
4670 }
Jim Millere303bf42014-08-26 17:12:29 -07004671 return new ArrayList<PersistableBundle>(); // empty list
Jim Miller604e7552014-07-18 19:00:02 -07004672 }
4673
4674 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004675 * Called by a profile owner of a managed profile to set whether caller-Id information from the
4676 * managed profile will be shown in the parent profile, for incoming calls.
4677 * <p>
4678 * The calling device admin must be a profile owner. If it is not, a security exception will be
4679 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004680 *
Robin Lee25e26452015-06-02 09:56:29 -07004681 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Adam Connors210fe212014-07-17 15:41:43 +01004682 * @param disabled If true caller-Id information in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004683 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004684 */
Robin Lee25e26452015-06-02 09:56:29 -07004685 public void setCrossProfileCallerIdDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004686 throwIfParentInstance("setCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004687 if (mService != null) {
4688 try {
Robin Lee25e26452015-06-02 09:56:29 -07004689 mService.setCrossProfileCallerIdDisabled(admin, disabled);
Adam Connors210fe212014-07-17 15:41:43 +01004690 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004691 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004692 }
4693 }
4694 }
4695
4696 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004697 * Called by a profile owner of a managed profile to determine whether or not caller-Id
4698 * information has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004699 * <p>
4700 * The calling device admin must be a profile owner. If it is not, a security exception will be
4701 * thrown.
Adam Connors210fe212014-07-17 15:41:43 +01004702 *
Robin Lee25e26452015-06-02 09:56:29 -07004703 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004704 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors210fe212014-07-17 15:41:43 +01004705 */
Robin Lee25e26452015-06-02 09:56:29 -07004706 public boolean getCrossProfileCallerIdDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004707 throwIfParentInstance("getCrossProfileCallerIdDisabled");
Adam Connors210fe212014-07-17 15:41:43 +01004708 if (mService != null) {
4709 try {
Robin Lee25e26452015-06-02 09:56:29 -07004710 return mService.getCrossProfileCallerIdDisabled(admin);
Adam Connors210fe212014-07-17 15:41:43 +01004711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004712 throw e.rethrowFromSystemServer();
Adam Connors210fe212014-07-17 15:41:43 +01004713 }
4714 }
4715 return false;
4716 }
4717
4718 /**
Amith Yamasani570002f2014-07-18 15:48:54 -07004719 * Determine whether or not caller-Id information has been disabled.
4720 *
4721 * @param userHandle The user for whom to check the caller-id permission
4722 * @hide
4723 */
4724 public boolean getCrossProfileCallerIdDisabled(UserHandle userHandle) {
4725 if (mService != null) {
4726 try {
4727 return mService.getCrossProfileCallerIdDisabledForUser(userHandle.getIdentifier());
4728 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004729 throw e.rethrowFromSystemServer();
Amith Yamasani570002f2014-07-18 15:48:54 -07004730 }
4731 }
4732 return false;
4733 }
4734
4735 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004736 * Called by a profile owner of a managed profile to set whether contacts search from the
4737 * managed profile will be shown in the parent profile, for incoming calls.
4738 * <p>
4739 * The calling device admin must be a profile owner. If it is not, a security exception will be
4740 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004741 *
4742 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4743 * @param disabled If true contacts search in the managed profile is not displayed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004744 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004745 */
4746 public void setCrossProfileContactsSearchDisabled(@NonNull ComponentName admin,
4747 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004748 throwIfParentInstance("setCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004749 if (mService != null) {
4750 try {
4751 mService.setCrossProfileContactsSearchDisabled(admin, disabled);
4752 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004753 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004754 }
4755 }
4756 }
4757
4758 /**
4759 * Called by a profile owner of a managed profile to determine whether or not contacts search
4760 * has been disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004761 * <p>
4762 * The calling device admin must be a profile owner. If it is not, a security exception will be
4763 * thrown.
Victor Chang1060c6182016-01-04 20:16:23 +00004764 *
4765 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004766 * @throws SecurityException if {@code admin} is not a device or profile owner.
Victor Chang1060c6182016-01-04 20:16:23 +00004767 */
4768 public boolean getCrossProfileContactsSearchDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004769 throwIfParentInstance("getCrossProfileContactsSearchDisabled");
Victor Chang1060c6182016-01-04 20:16:23 +00004770 if (mService != null) {
4771 try {
4772 return mService.getCrossProfileContactsSearchDisabled(admin);
4773 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004774 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004775 }
4776 }
4777 return false;
4778 }
4779
4780
4781 /**
4782 * Determine whether or not contacts search has been disabled.
4783 *
4784 * @param userHandle The user for whom to check the contacts search permission
4785 * @hide
4786 */
4787 public boolean getCrossProfileContactsSearchDisabled(@NonNull UserHandle userHandle) {
4788 if (mService != null) {
4789 try {
4790 return mService
4791 .getCrossProfileContactsSearchDisabledForUser(userHandle.getIdentifier());
4792 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004793 throw e.rethrowFromSystemServer();
Victor Chang1060c6182016-01-04 20:16:23 +00004794 }
4795 }
4796 return false;
4797 }
4798
4799 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004800 * Start Quick Contact on the managed profile for the user, if the policy allows.
Victor Chang97bdacc2016-01-21 22:24:11 +00004801 *
Makoto Onuki1040da12015-03-19 11:24:00 -07004802 * @hide
4803 */
4804 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
Victor Chang97bdacc2016-01-21 22:24:11 +00004805 boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
Makoto Onuki1040da12015-03-19 11:24:00 -07004806 if (mService != null) {
4807 try {
Victor Chang97bdacc2016-01-21 22:24:11 +00004808 mService.startManagedQuickContact(actualLookupKey, actualContactId,
4809 isContactIdIgnored, directoryId, originalIntent);
Makoto Onuki1040da12015-03-19 11:24:00 -07004810 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004811 throw e.rethrowFromSystemServer();
Makoto Onuki1040da12015-03-19 11:24:00 -07004812 }
4813 }
4814 }
4815
4816 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08004817 * Start Quick Contact on the managed profile for the user, if the policy allows.
Ricky Wai494b95d2015-11-20 16:07:15 +00004818 * @hide
4819 */
4820 public void startManagedQuickContact(String actualLookupKey, long actualContactId,
4821 Intent originalIntent) {
Victor Chang97bdacc2016-01-21 22:24:11 +00004822 startManagedQuickContact(actualLookupKey, actualContactId, false, Directory.DEFAULT,
Ricky Wai494b95d2015-11-20 16:07:15 +00004823 originalIntent);
4824 }
4825
4826 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004827 * Called by a profile owner of a managed profile to set whether bluetooth devices can access
4828 * enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004829 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004830 * The calling device admin must be a profile owner. If it is not, a security exception will be
4831 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004832 * <p>
4833 * This API works on managed profile only.
4834 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4836 * @param disabled If true, bluetooth devices cannot access enterprise contacts.
4837 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004838 */
Robin Lee25e26452015-06-02 09:56:29 -07004839 public void setBluetoothContactSharingDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004840 throwIfParentInstance("setBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004841 if (mService != null) {
4842 try {
Robin Lee25e26452015-06-02 09:56:29 -07004843 mService.setBluetoothContactSharingDisabled(admin, disabled);
Ricky Wai778ba132015-03-31 14:21:22 +01004844 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004845 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004846 }
4847 }
4848 }
4849
4850 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004851 * Called by a profile owner of a managed profile to determine whether or not Bluetooth devices
4852 * cannot access enterprise contacts.
Ricky Wai778ba132015-03-31 14:21:22 +01004853 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004854 * The calling device admin must be a profile owner. If it is not, a security exception will be
4855 * thrown.
Ricky Wai778ba132015-03-31 14:21:22 +01004856 * <p>
4857 * This API works on managed profile only.
4858 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004859 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4860 * @throws SecurityException if {@code admin} is not a device or profile owner.
Ricky Wai778ba132015-03-31 14:21:22 +01004861 */
Robin Lee25e26452015-06-02 09:56:29 -07004862 public boolean getBluetoothContactSharingDisabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004863 throwIfParentInstance("getBluetoothContactSharingDisabled");
Ricky Wai778ba132015-03-31 14:21:22 +01004864 if (mService != null) {
4865 try {
Robin Lee25e26452015-06-02 09:56:29 -07004866 return mService.getBluetoothContactSharingDisabled(admin);
Ricky Wai778ba132015-03-31 14:21:22 +01004867 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004868 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004869 }
4870 }
4871 return true;
4872 }
4873
4874 /**
4875 * Determine whether or not Bluetooth devices cannot access contacts.
4876 * <p>
4877 * This API works on managed profile UserHandle only.
4878 *
4879 * @param userHandle The user for whom to check the caller-id permission
4880 * @hide
4881 */
4882 public boolean getBluetoothContactSharingDisabled(UserHandle userHandle) {
4883 if (mService != null) {
4884 try {
4885 return mService.getBluetoothContactSharingDisabledForUser(userHandle
4886 .getIdentifier());
4887 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004888 throw e.rethrowFromSystemServer();
Ricky Wai778ba132015-03-31 14:21:22 +01004889 }
4890 }
4891 return true;
4892 }
4893
4894 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004895 * Called by the profile owner of a managed profile so that some intents sent in the managed
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004896 * profile can also be resolved in the parent, or vice versa. Only activity intents are
4897 * supported.
Nicolas Prevotfc7b4442014-12-17 15:28:29 +00004898 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004899 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Nicolas Prevot81948992014-05-16 18:25:26 +01004900 * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004901 * other profile
Nicolas Prevot41d926e2014-06-09 11:48:56 +01004902 * @param flags {@link DevicePolicyManager#FLAG_MANAGED_CAN_ACCESS_PARENT} and
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004903 * {@link DevicePolicyManager#FLAG_PARENT_CAN_ACCESS_MANAGED} are supported.
4904 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004905 */
Robin Lee25e26452015-06-02 09:56:29 -07004906 public void addCrossProfileIntentFilter(@NonNull ComponentName admin, IntentFilter filter, int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004907 throwIfParentInstance("addCrossProfileIntentFilter");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004908 if (mService != null) {
4909 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004910 mService.addCrossProfileIntentFilter(admin, filter, flags);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004911 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004912 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004913 }
4914 }
4915 }
4916
4917 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07004918 * Called by a profile owner of a managed profile to remove the cross-profile intent filters
4919 * that go from the managed profile to the parent, or from the parent to the managed profile.
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01004920 * Only removes those that have been set by the profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004921 *
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004922 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004923 * @throws SecurityException if {@code admin} is not a device or profile owner.
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004924 */
Robin Lee25e26452015-06-02 09:56:29 -07004925 public void clearCrossProfileIntentFilters(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004926 throwIfParentInstance("clearCrossProfileIntentFilters");
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004927 if (mService != null) {
4928 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01004929 mService.clearCrossProfileIntentFilters(admin);
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004930 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004931 throw e.rethrowFromSystemServer();
Nicolas Prevot10fa67c2014-03-24 13:44:38 +00004932 }
4933 }
4934 }
4935
4936 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004937 * Called by a profile or device owner to set the permitted accessibility services. When set by
4938 * a device owner or profile owner the restriction applies to all profiles of the user the
4939 * device owner or profile owner is an admin for. By default the user can use any accessiblity
4940 * service. When zero or more packages have been added, accessiblity services that are not in
4941 * the list and not part of the system can not be enabled by the user.
4942 * <p>
4943 * Calling with a null value for the list disables the restriction so that all services can be
4944 * used, calling with an empty list only allows the builtin system's services.
4945 * <p>
4946 * System accesibility services are always available to the user the list can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004947 *
4948 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4949 * @param packageNames List of accessibility service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004950 * @return true if setting the restriction succeeded. It fail if there is one or more non-system
4951 * accessibility services enabled, that are not in the list.
4952 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004953 */
Robin Lee25e26452015-06-02 09:56:29 -07004954 public boolean setPermittedAccessibilityServices(@NonNull ComponentName admin,
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004955 List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004956 throwIfParentInstance("setPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004957 if (mService != null) {
4958 try {
4959 return mService.setPermittedAccessibilityServices(admin, packageNames);
4960 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004961 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004962 }
4963 }
4964 return false;
4965 }
4966
4967 /**
4968 * Returns the list of permitted accessibility services set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004969 * <p>
4970 * An empty list means no accessibility services except system services are allowed. Null means
4971 * all accessibility services are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004972 *
4973 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4974 * @return List of accessiblity service package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07004975 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004976 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07004977 public @Nullable List<String> getPermittedAccessibilityServices(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01004978 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004979 if (mService != null) {
4980 try {
4981 return mService.getPermittedAccessibilityServices(admin);
4982 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07004983 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01004984 }
4985 }
4986 return null;
4987 }
4988
4989 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00004990 * Called by the system to check if a specific accessibility service is disabled by admin.
4991 *
4992 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
4993 * @param packageName Accessibility service package name that needs to be checked.
4994 * @param userHandle user id the admin is running as.
4995 * @return true if the accessibility service is permitted, otherwise false.
4996 *
4997 * @hide
4998 */
4999 public boolean isAccessibilityServicePermittedByAdmin(@NonNull ComponentName admin,
5000 @NonNull String packageName, int userHandle) {
5001 if (mService != null) {
5002 try {
5003 return mService.isAccessibilityServicePermittedByAdmin(admin, packageName,
5004 userHandle);
5005 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005006 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005007 }
5008 }
5009 return false;
5010 }
5011
5012 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005013 * Returns the list of accessibility services permitted by the device or profiles
5014 * owners of this user.
5015 *
5016 * <p>Null means all accessibility services are allowed, if a non-null list is returned
5017 * it will contain the intersection of the permitted lists for any device or profile
5018 * owners that apply to this user. It will also include any system accessibility services.
5019 *
5020 * @param userId which user to check for.
5021 * @return List of accessiblity service package names.
5022 * @hide
5023 */
5024 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005025 public @Nullable List<String> getPermittedAccessibilityServices(int userId) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005026 throwIfParentInstance("getPermittedAccessibilityServices");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005027 if (mService != null) {
5028 try {
5029 return mService.getPermittedAccessibilityServicesForUser(userId);
5030 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005031 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005032 }
5033 }
5034 return null;
5035 }
5036
5037 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005038 * Called by a profile or device owner to set the permitted input methods services. When set by
5039 * a device owner or profile owner the restriction applies to all profiles of the user the
5040 * device owner or profile owner is an admin for. By default the user can use any input method.
5041 * When zero or more packages have been added, input method that are not in the list and not
5042 * part of the system can not be enabled by the user. This method will fail if it is called for
5043 * a admin that is not for the foreground user or a profile of the foreground user.
5044 * <p>
5045 * Calling with a null value for the list disables the restriction so that all input methods can
5046 * be used, calling with an empty list disables all but the system's own input methods.
5047 * <p>
5048 * System input methods are always available to the user this method can't modify this.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005049 *
5050 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5051 * @param packageNames List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005052 * @return true if setting the restriction succeeded. It will fail if there are one or more
5053 * non-system input methods currently enabled that are not in the packageNames list.
5054 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005055 */
Robin Lee25e26452015-06-02 09:56:29 -07005056 public boolean setPermittedInputMethods(@NonNull ComponentName admin, List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005057 throwIfParentInstance("setPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005058 if (mService != null) {
5059 try {
5060 return mService.setPermittedInputMethods(admin, packageNames);
5061 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005062 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005063 }
5064 }
5065 return false;
5066 }
5067
5068
5069 /**
5070 * Returns the list of permitted input methods set by this device or profile owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005071 * <p>
5072 * An empty list means no input methods except system input methods are allowed. Null means all
5073 * input methods are allowed.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005074 *
5075 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5076 * @return List of input method package names.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005077 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005078 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005079 public @Nullable List<String> getPermittedInputMethods(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005080 throwIfParentInstance("getPermittedInputMethods");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005081 if (mService != null) {
5082 try {
5083 return mService.getPermittedInputMethods(admin);
5084 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005085 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005086 }
5087 }
5088 return null;
5089 }
5090
5091 /**
Sudheer Shanka56925862016-01-28 19:43:59 +00005092 * Called by the system to check if a specific input method is disabled by admin.
5093 *
5094 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5095 * @param packageName Input method package name that needs to be checked.
5096 * @param userHandle user id the admin is running as.
5097 * @return true if the input method is permitted, otherwise false.
5098 *
5099 * @hide
5100 */
5101 public boolean isInputMethodPermittedByAdmin(@NonNull ComponentName admin,
5102 @NonNull String packageName, int userHandle) {
5103 if (mService != null) {
5104 try {
5105 return mService.isInputMethodPermittedByAdmin(admin, packageName, userHandle);
5106 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005107 throw e.rethrowFromSystemServer();
Sudheer Shanka56925862016-01-28 19:43:59 +00005108 }
5109 }
5110 return false;
5111 }
5112
5113 /**
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005114 * Returns the list of input methods permitted by the device or profiles
Makoto Onuki32b30572015-12-11 14:29:51 -08005115 * owners of the current user. (*Not* calling user, due to a limitation in InputMethodManager.)
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005116 *
5117 * <p>Null means all input methods are allowed, if a non-null list is returned
5118 * it will contain the intersection of the permitted lists for any device or profile
5119 * owners that apply to this user. It will also include any system input methods.
5120 *
5121 * @return List of input method package names.
5122 * @hide
5123 */
5124 @SystemApi
Makoto Onuki408e8e42016-10-25 12:10:27 -07005125 public @Nullable List<String> getPermittedInputMethodsForCurrentUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005126 throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005127 if (mService != null) {
5128 try {
5129 return mService.getPermittedInputMethodsForCurrentUser();
5130 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005131 throw e.rethrowFromSystemServer();
Kenny Guyfa80a4f2014-08-20 19:40:59 +01005132 }
5133 }
5134 return null;
5135 }
5136
5137 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005138 * Called by a device owner to get the list of apps to keep around as APKs even if no user has
5139 * currently installed it.
5140 *
5141 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5142 *
5143 * @return List of package names to keep cached.
5144 * @hide
5145 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005146 public @Nullable List<String> getKeepUninstalledPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005147 throwIfParentInstance("getKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005148 if (mService != null) {
5149 try {
5150 return mService.getKeepUninstalledPackages(admin);
5151 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005152 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005153 }
5154 }
5155 return null;
5156 }
5157
5158 /**
5159 * Called by a device owner to set a list of apps to keep around as APKs even if no user has
5160 * currently installed it.
5161 *
5162 * <p>Please note that setting this policy does not imply that specified apps will be
5163 * automatically pre-cached.</p>
5164 *
5165 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5166 * @param packageNames List of package names to keep cached.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005167 * @throws SecurityException if {@code admin} is not a device owner.
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005168 * @hide
5169 */
5170 public void setKeepUninstalledPackages(@NonNull ComponentName admin,
5171 @NonNull List<String> packageNames) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005172 throwIfParentInstance("setKeepUninstalledPackages");
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005173 if (mService != null) {
5174 try {
5175 mService.setKeepUninstalledPackages(admin, packageNames);
5176 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005177 throw e.rethrowFromSystemServer();
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -08005178 }
5179 }
5180 }
5181
5182 /**
Julia Reynolds1e958392014-05-16 14:25:21 -04005183 * Called by a device owner to create a user with the specified name. The UserHandle returned
5184 * by this method should not be persisted as user handles are recycled as users are removed and
5185 * created. If you need to persist an identifier for this user, use
5186 * {@link UserManager#getSerialNumberForUser}.
5187 *
5188 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5189 * @param name the user's name
5190 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005191 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5192 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005193 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005194 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005195 * @removed From {@link android.os.Build.VERSION_CODES#N}
Julia Reynolds1e958392014-05-16 14:25:21 -04005196 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005197 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005198 public @Nullable UserHandle createUser(@NonNull ComponentName admin, String name) {
Julia Reynolds1e958392014-05-16 14:25:21 -04005199 return null;
5200 }
5201
5202 /**
Jason Monk03978a42014-06-10 15:05:30 -04005203 * Called by a device owner to create a user with the specified name. The UserHandle returned
5204 * by this method should not be persisted as user handles are recycled as users are removed and
5205 * created. If you need to persist an identifier for this user, use
5206 * {@link UserManager#getSerialNumberForUser}. The new user will be started in the background
5207 * immediately.
5208 *
5209 * <p> profileOwnerComponent is the {@link DeviceAdminReceiver} to be the profile owner as well
5210 * as registered as an active admin on the new user. The profile owner package will be
5211 * installed on the new user if it already is installed on the device.
5212 *
5213 * <p>If the optionalInitializeData is not null, then the extras will be passed to the
5214 * profileOwnerComponent when onEnable is called.
5215 *
5216 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5217 * @param name the user's name
5218 * @param ownerName the human readable name of the organisation associated with this DPM.
5219 * @param profileOwnerComponent The {@link DeviceAdminReceiver} that will be an active admin on
5220 * the user.
5221 * @param adminExtras Extras that will be passed to onEnable of the admin receiver
5222 * on the new user.
5223 * @see UserHandle
Robin Lee25e26452015-06-02 09:56:29 -07005224 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5225 * user could not be created.
Kenny Guy14f48e52015-06-29 15:12:36 +01005226 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07005227 * @deprecated From {@link android.os.Build.VERSION_CODES#M}
phweiss27ee3342016-02-08 16:40:45 +01005228 * @removed From {@link android.os.Build.VERSION_CODES#N}
Jason Monk03978a42014-06-10 15:05:30 -04005229 */
Kenny Guy14f48e52015-06-29 15:12:36 +01005230 @Deprecated
Makoto Onuki408e8e42016-10-25 12:10:27 -07005231 public @Nullable UserHandle createAndInitializeUser(@NonNull ComponentName admin, String name,
Robin Lee25e26452015-06-02 09:56:29 -07005232 String ownerName, @NonNull ComponentName profileOwnerComponent, Bundle adminExtras) {
Jason Monk03978a42014-06-10 15:05:30 -04005233 return null;
5234 }
5235
5236 /**
phweissa92e1212016-01-25 17:14:10 +01005237 * Flag used by {@link #createAndManageUser} to skip setup wizard after creating a new user.
phweiss343fb332016-01-25 14:48:59 +01005238 */
5239 public static final int SKIP_SETUP_WIZARD = 0x0001;
5240
5241 /**
Lenka Trochtovac8202c82016-01-26 15:11:09 +01005242 * Flag used by {@link #createAndManageUser} to specify that the user should be created
5243 * ephemeral.
5244 * @hide
5245 */
5246 public static final int MAKE_USER_EPHEMERAL = 0x0002;
5247
5248 /**
phweissa92e1212016-01-25 17:14:10 +01005249 * Called by a device owner to create a user with the specified name and a given component of
5250 * the calling package as profile owner. The UserHandle returned by this method should not be
5251 * persisted as user handles are recycled as users are removed and created. If you need to
5252 * persist an identifier for this user, use {@link UserManager#getSerialNumberForUser}. The new
5253 * user will not be started in the background.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005254 * <p>
5255 * admin is the {@link DeviceAdminReceiver} which is the device owner. profileOwner is also a
5256 * DeviceAdminReceiver in the same package as admin, and will become the profile owner and will
5257 * be registered as an active admin on the new user. The profile owner package will be installed
5258 * on the new user.
5259 * <p>
5260 * If the adminExtras are not null, they will be stored on the device until the user is started
5261 * for the first time. Then the extras will be passed to the admin when onEnable is called.
phweiss343fb332016-01-25 14:48:59 +01005262 *
5263 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5264 * @param name The user's name.
phweissa92e1212016-01-25 17:14:10 +01005265 * @param profileOwner Which {@link DeviceAdminReceiver} will be profile owner. Has to be in the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005266 * same package as admin, otherwise no user is created and an
5267 * IllegalArgumentException is thrown.
phweiss343fb332016-01-25 14:48:59 +01005268 * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005269 * user.
phweissa92e1212016-01-25 17:14:10 +01005270 * @param flags {@link #SKIP_SETUP_WIZARD} is supported.
phweiss343fb332016-01-25 14:48:59 +01005271 * @see UserHandle
5272 * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
5273 * user could not be created.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005274 * @throws SecurityException if {@code admin} is not a device owner.
phweiss343fb332016-01-25 14:48:59 +01005275 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005276 public @Nullable UserHandle createAndManageUser(@NonNull ComponentName admin,
5277 @NonNull String name,
phweissa92e1212016-01-25 17:14:10 +01005278 @NonNull ComponentName profileOwner, @Nullable PersistableBundle adminExtras,
5279 int flags) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005280 throwIfParentInstance("createAndManageUser");
phweiss343fb332016-01-25 14:48:59 +01005281 try {
phweissa92e1212016-01-25 17:14:10 +01005282 return mService.createAndManageUser(admin, name, profileOwner, adminExtras, flags);
phweiss343fb332016-01-25 14:48:59 +01005283 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005284 throw re.rethrowFromSystemServer();
phweiss343fb332016-01-25 14:48:59 +01005285 }
phweiss343fb332016-01-25 14:48:59 +01005286 }
5287
5288 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005289 * Called by a device owner to remove a user and all associated data. The primary user can not
5290 * be removed.
Julia Reynolds1e958392014-05-16 14:25:21 -04005291 *
5292 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5293 * @param userHandle the user to remove.
5294 * @return {@code true} if the user was removed, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005295 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynolds1e958392014-05-16 14:25:21 -04005296 */
Robin Lee25e26452015-06-02 09:56:29 -07005297 public boolean removeUser(@NonNull ComponentName admin, UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005298 throwIfParentInstance("removeUser");
Julia Reynolds1e958392014-05-16 14:25:21 -04005299 try {
5300 return mService.removeUser(admin, userHandle);
5301 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005302 throw re.rethrowFromSystemServer();
Julia Reynolds1e958392014-05-16 14:25:21 -04005303 }
5304 }
5305
5306 /**
Jason Monk582d9112014-07-09 19:57:08 -04005307 * Called by a device owner to switch the specified user to the foreground.
5308 *
5309 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5310 * @param userHandle the user to switch to; null will switch to primary.
5311 * @return {@code true} if the switch was successful, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005312 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monk582d9112014-07-09 19:57:08 -04005313 * @see Intent#ACTION_USER_FOREGROUND
5314 */
Robin Lee25e26452015-06-02 09:56:29 -07005315 public boolean switchUser(@NonNull ComponentName admin, @Nullable UserHandle userHandle) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005316 throwIfParentInstance("switchUser");
Jason Monk582d9112014-07-09 19:57:08 -04005317 try {
5318 return mService.switchUser(admin, userHandle);
5319 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005320 throw re.rethrowFromSystemServer();
Jason Monk582d9112014-07-09 19:57:08 -04005321 }
5322 }
5323
5324 /**
Esteban Talaverabf60f722015-12-10 16:26:44 +00005325 * Retrieves the application restrictions for a given target application running in the calling
5326 * user.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005327 * <p>
5328 * The caller must be a profile or device owner on that user, or the package allowed to manage
5329 * application restrictions via {@link #setApplicationRestrictionsManagingPackage}; otherwise a
5330 * security exception will be thrown.
Robin Lee66e5d962014-04-09 16:44:21 +01005331 *
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005332 * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
5333 *
Esteban Talaverabf60f722015-12-10 16:26:44 +00005334 * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005335 * {@code null} if called by the application restrictions managing package.
Robin Lee66e5d962014-04-09 16:44:21 +01005336 * @param packageName The name of the package to fetch restricted settings of.
5337 * @return {@link Bundle} of settings corresponding to what was set last time
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005338 * {@link DevicePolicyManager#setApplicationRestrictions} was called, or an empty
5339 * {@link Bundle} if no restrictions have been set.
5340 * @throws SecurityException if {@code admin} is not a device or profile owner.
Esteban Talaverabf60f722015-12-10 16:26:44 +00005341 * @see {@link #setApplicationRestrictionsManagingPackage}
Robin Lee66e5d962014-04-09 16:44:21 +01005342 */
Fyodor Kupolov4e9af062016-07-18 16:59:11 -07005343 @WorkerThread
Makoto Onuki408e8e42016-10-25 12:10:27 -07005344 public @NonNull Bundle getApplicationRestrictions(
5345 @Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005346 throwIfParentInstance("getApplicationRestrictions");
Robin Lee66e5d962014-04-09 16:44:21 +01005347 if (mService != null) {
5348 try {
5349 return mService.getApplicationRestrictions(admin, packageName);
5350 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005351 throw e.rethrowFromSystemServer();
Robin Lee66e5d962014-04-09 16:44:21 +01005352 }
5353 }
5354 return null;
5355 }
Amith Yamasanibe465322014-04-24 13:45:17 -07005356
5357 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005358 * Called by a profile or device owner to set a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005359 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005360 * The calling device admin must be a profile or device owner; if it is not, a security
5361 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005362 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005363 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5364 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5365 * for the list of keys.
5366 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005367 */
Robin Lee25e26452015-06-02 09:56:29 -07005368 public void addUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005369 throwIfParentInstance("addUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005370 if (mService != null) {
5371 try {
5372 mService.setUserRestriction(admin, key, true);
5373 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005374 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005375 }
5376 }
5377 }
5378
5379 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005380 * Called by a profile or device owner to clear a user restriction specified by the key.
Amith Yamasanibe465322014-04-24 13:45:17 -07005381 * <p>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005382 * The calling device admin must be a profile or device owner; if it is not, a security
5383 * exception will be thrown.
Jim Millerdf2258b2014-04-27 20:10:26 -07005384 *
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005385 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5386 * @param key The key of the restriction. See the constants in {@link android.os.UserManager}
5387 * for the list of keys.
5388 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanibe465322014-04-24 13:45:17 -07005389 */
Robin Lee25e26452015-06-02 09:56:29 -07005390 public void clearUserRestriction(@NonNull ComponentName admin, String key) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005391 throwIfParentInstance("clearUserRestriction");
Amith Yamasanibe465322014-04-24 13:45:17 -07005392 if (mService != null) {
5393 try {
5394 mService.setUserRestriction(admin, key, false);
5395 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005396 throw e.rethrowFromSystemServer();
Amith Yamasanibe465322014-04-24 13:45:17 -07005397 }
5398 }
5399 }
Adam Connors010cfd42014-04-16 12:48:13 +01005400
5401 /**
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005402 * Called by a profile or device owner to get user restrictions set with
5403 * {@link #addUserRestriction(ComponentName, String)}.
5404 * <p>
5405 * The target user may have more restrictions set by the system or other device owner / profile
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005406 * owner. To get all the user restrictions currently set, use
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005407 * {@link UserManager#getUserRestrictions()}.
5408 *
5409 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005410 * @throws SecurityException if {@code admin} is not a device or profile owner.
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005411 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005412 public @NonNull Bundle getUserRestrictions(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005413 throwIfParentInstance("getUserRestrictions");
Makoto Onuki3a3092f2015-10-30 11:07:51 -07005414 Bundle ret = null;
5415 if (mService != null) {
5416 try {
Sudheer Shanka549b9692016-03-30 17:12:07 -07005417 ret = mService.getUserRestrictions(admin);
5418 } catch (RemoteException e) {
5419 throw e.rethrowFromSystemServer();
5420 }
5421 }
5422 return ret == null ? new Bundle() : ret;
5423 }
5424
5425 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005426 * Called by profile or device owners to hide or unhide packages. When a package is hidden it is
5427 * unavailable for use, but the data and actual package file remain.
Julia Reynolds966881e2014-05-14 12:23:08 -04005428 *
5429 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005430 * @param packageName The name of the package to hide or unhide.
5431 * @param hidden {@code true} if the package should be hidden, {@code false} if it should be
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005432 * unhidden.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005433 * @return boolean Whether the hidden setting of the package was successfully updated.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005434 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005435 */
Robin Lee25e26452015-06-02 09:56:29 -07005436 public boolean setApplicationHidden(@NonNull ComponentName admin, String packageName,
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005437 boolean hidden) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005438 throwIfParentInstance("setApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005439 if (mService != null) {
5440 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005441 return mService.setApplicationHidden(admin, packageName, hidden);
Julia Reynolds966881e2014-05-14 12:23:08 -04005442 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005443 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005444 }
5445 }
5446 return false;
5447 }
5448
5449 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005450 * Called by profile or device owners to determine if a package is hidden.
Julia Reynolds966881e2014-05-14 12:23:08 -04005451 *
5452 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005453 * @param packageName The name of the package to retrieve the hidden status of.
5454 * @return boolean {@code true} if the package is hidden, {@code false} otherwise.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005455 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds966881e2014-05-14 12:23:08 -04005456 */
Robin Lee25e26452015-06-02 09:56:29 -07005457 public boolean isApplicationHidden(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005458 throwIfParentInstance("isApplicationHidden");
Julia Reynolds966881e2014-05-14 12:23:08 -04005459 if (mService != null) {
5460 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07005461 return mService.isApplicationHidden(admin, packageName);
Julia Reynolds966881e2014-05-14 12:23:08 -04005462 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005463 throw e.rethrowFromSystemServer();
Julia Reynolds966881e2014-05-14 12:23:08 -04005464 }
5465 }
5466 return false;
5467 }
5468
5469 /**
Julia Reynolds20118f12015-02-11 12:34:08 -05005470 * Called by profile or device owners to re-enable a system app that was disabled by default
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005471 * when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005472 *
5473 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Makoto Onuki32b30572015-12-11 14:29:51 -08005474 * @param packageName The package to be re-enabled in the calling profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005475 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005476 */
Robin Lee25e26452015-06-02 09:56:29 -07005477 public void enableSystemApp(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005478 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005479 if (mService != null) {
5480 try {
5481 mService.enableSystemApp(admin, packageName);
5482 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005483 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005484 }
5485 }
5486 }
5487
5488 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005489 * Called by profile or device owners to re-enable system apps by intent that were disabled by
5490 * default when the user was initialized.
Adam Connors655be2a2014-07-14 09:01:25 +00005491 *
5492 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5493 * @param intent An intent matching the app(s) to be installed. All apps that resolve for this
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005494 * intent will be re-enabled in the calling profile.
Adam Connors655be2a2014-07-14 09:01:25 +00005495 * @return int The number of activities that matched the intent and were installed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005496 * @throws SecurityException if {@code admin} is not a device or profile owner.
Adam Connors655be2a2014-07-14 09:01:25 +00005497 */
Robin Lee25e26452015-06-02 09:56:29 -07005498 public int enableSystemApp(@NonNull ComponentName admin, Intent intent) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005499 throwIfParentInstance("enableSystemApp");
Adam Connors655be2a2014-07-14 09:01:25 +00005500 if (mService != null) {
5501 try {
5502 return mService.enableSystemAppWithIntent(admin, intent);
5503 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005504 throw e.rethrowFromSystemServer();
Adam Connors655be2a2014-07-14 09:01:25 +00005505 }
5506 }
5507 return 0;
5508 }
5509
5510 /**
Sander Alewijnse112e0532014-10-29 13:28:49 +00005511 * Called by a device owner or profile owner to disable account management for a specific type
5512 * of account.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005513 * <p>
5514 * The calling device admin must be a device owner or profile owner. If it is not, a security
5515 * exception will be thrown.
5516 * <p>
5517 * When account management is disabled for an account type, adding or removing an account of
5518 * that type will not be possible.
5519 * <p>
5520 * From {@link android.os.Build.VERSION_CODES#N} the profile or device owner can still use
Benjamin Franzb6c0ce42015-11-05 10:06:51 +00005521 * {@link android.accounts.AccountManager} APIs to add or remove accounts when account
5522 * management for a specific type is disabled.
5523 *
Sander Alewijnse650c3342014-05-08 18:00:50 +01005524 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5525 * @param accountType For which account management is disabled or enabled.
5526 * @param disabled The boolean indicating that account management will be disabled (true) or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005527 * enabled (false).
5528 * @throws SecurityException if {@code admin} is not a device or profile owner.
Sander Alewijnse650c3342014-05-08 18:00:50 +01005529 */
Robin Lee25e26452015-06-02 09:56:29 -07005530 public void setAccountManagementDisabled(@NonNull ComponentName admin, String accountType,
Sander Alewijnse650c3342014-05-08 18:00:50 +01005531 boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005532 throwIfParentInstance("setAccountManagementDisabled");
Sander Alewijnse650c3342014-05-08 18:00:50 +01005533 if (mService != null) {
5534 try {
5535 mService.setAccountManagementDisabled(admin, accountType, disabled);
5536 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005537 throw e.rethrowFromSystemServer();
Sander Alewijnse650c3342014-05-08 18:00:50 +01005538 }
5539 }
5540 }
5541
5542 /**
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005543 * Gets the array of accounts for which account management is disabled by the profile owner.
5544 *
5545 * <p> Account management can be disabled/enabled by calling
5546 * {@link #setAccountManagementDisabled}.
5547 *
5548 * @return a list of account types for which account management has been disabled.
5549 *
5550 * @see #setAccountManagementDisabled
5551 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005552 public @Nullable String[] getAccountTypesWithManagementDisabled() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005553 throwIfParentInstance("getAccountTypesWithManagementDisabled");
Makoto Onukicc4bbeb2015-09-17 10:28:24 -07005554 return getAccountTypesWithManagementDisabledAsUser(myUserId());
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005555 }
5556
5557 /**
5558 * @see #getAccountTypesWithManagementDisabled()
5559 * @hide
5560 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005561 public @Nullable String[] getAccountTypesWithManagementDisabledAsUser(int userId) {
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005562 if (mService != null) {
5563 try {
Alexandra Gherghina999d3942014-07-03 11:40:08 +01005564 return mService.getAccountTypesWithManagementDisabledAsUser(userId);
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005565 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005566 throw e.rethrowFromSystemServer();
Sander Alewijnse5c02db62014-05-07 10:46:57 +01005567 }
5568 }
5569
5570 return null;
5571 }
justinzhang511e0d82014-03-24 16:09:24 -04005572
5573 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005574 * Sets which packages may enter lock task mode.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005575 * <p>
5576 * Any packages that shares uid with an allowed package will also be allowed to activate lock
5577 * task. From {@link android.os.Build.VERSION_CODES#M} removing packages from the lock task
5578 * package list results in locked tasks belonging to those packages to be finished. This
5579 * function can only be called by the device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005580 *
Jason Monkd7b86212014-06-16 13:15:38 -04005581 * @param packages The list of packages allowed to enter lock task mode
Jason Monk48aacba2014-08-13 16:29:08 -04005582 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005583 * @throws SecurityException if {@code admin} is not a device owner.
Jason Monkd7b86212014-06-16 13:15:38 -04005584 * @see Activity#startLockTask()
Benjamin Franz6cdb27e2015-02-26 12:26:53 +00005585 * @see DeviceAdminReceiver#onLockTaskModeEntering(Context, Intent, String)
5586 * @see DeviceAdminReceiver#onLockTaskModeExiting(Context, Intent)
Jason Monk1c7c3192014-06-26 12:52:18 -04005587 * @see UserManager#DISALLOW_CREATE_WINDOWS
justinzhang511e0d82014-03-24 16:09:24 -04005588 */
Robin Lee25e26452015-06-02 09:56:29 -07005589 public void setLockTaskPackages(@NonNull ComponentName admin, String[] packages)
Jason Monk48aacba2014-08-13 16:29:08 -04005590 throws SecurityException {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005591 throwIfParentInstance("setLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005592 if (mService != null) {
5593 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005594 mService.setLockTaskPackages(admin, packages);
justinzhang511e0d82014-03-24 16:09:24 -04005595 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005596 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005597 }
5598 }
5599 }
5600
5601 /**
Jason Monkd7b86212014-06-16 13:15:38 -04005602 * This function returns the list of packages allowed to start the lock task mode.
Jason Monk48aacba2014-08-13 16:29:08 -04005603 *
5604 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
justinzhang511e0d82014-03-24 16:09:24 -04005605 * @hide
5606 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005607 public @NonNull String[] getLockTaskPackages(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005608 throwIfParentInstance("getLockTaskPackages");
justinzhang511e0d82014-03-24 16:09:24 -04005609 if (mService != null) {
5610 try {
Jason Monk48aacba2014-08-13 16:29:08 -04005611 return mService.getLockTaskPackages(admin);
justinzhang511e0d82014-03-24 16:09:24 -04005612 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005613 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005614 }
5615 }
5616 return null;
5617 }
5618
5619 /**
5620 * This function lets the caller know whether the given component is allowed to start the
5621 * lock task mode.
Jason Monkd7b86212014-06-16 13:15:38 -04005622 * @param pkg The package to check
justinzhang511e0d82014-03-24 16:09:24 -04005623 */
Jason Monkd7b86212014-06-16 13:15:38 -04005624 public boolean isLockTaskPermitted(String pkg) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005625 throwIfParentInstance("isLockTaskPermitted");
justinzhang511e0d82014-03-24 16:09:24 -04005626 if (mService != null) {
5627 try {
Jason Monkd7b86212014-06-16 13:15:38 -04005628 return mService.isLockTaskPermitted(pkg);
justinzhang511e0d82014-03-24 16:09:24 -04005629 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005630 throw e.rethrowFromSystemServer();
justinzhang511e0d82014-03-24 16:09:24 -04005631 }
5632 }
5633 return false;
5634 }
Julia Reynoldsda551652014-05-14 17:15:16 -04005635
5636 /**
5637 * Called by device owners to update {@link Settings.Global} settings. Validation that the value
5638 * 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 -07005639 * <p>
5640 * The settings that can be updated with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005641 * <ul>
5642 * <li>{@link Settings.Global#ADB_ENABLED}</li>
5643 * <li>{@link Settings.Global#AUTO_TIME}</li>
5644 * <li>{@link Settings.Global#AUTO_TIME_ZONE}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005645 * <li>{@link Settings.Global#DATA_ROAMING}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005646 * <li>{@link Settings.Global#USB_MASS_STORAGE_ENABLED}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005647 * <li>{@link Settings.Global#WIFI_SLEEP_POLICY}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005648 * <li>{@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} This setting is only available from
5649 * {@link android.os.Build.VERSION_CODES#M} onwards and can only be set if
5650 * {@link #setMaximumTimeToLock} is not used to set a timeout.</li>
5651 * <li>{@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}</li> This setting is only
5652 * available from {@link android.os.Build.VERSION_CODES#M} onwards.</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005653 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005654 * <p>
5655 * Changing the following settings has no effect as of {@link android.os.Build.VERSION_CODES#M}:
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005656 * <ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005657 * <li>{@link Settings.Global#BLUETOOTH_ON}. Use
5658 * {@link android.bluetooth.BluetoothAdapter#enable()} and
5659 * {@link android.bluetooth.BluetoothAdapter#disable()} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005660 * <li>{@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005661 * <li>{@link Settings.Global#MODE_RINGER}. Use
5662 * {@link android.media.AudioManager#setRingerMode(int)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005663 * <li>{@link Settings.Global#NETWORK_PREFERENCE}</li>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005664 * <li>{@link Settings.Global#WIFI_ON}. Use
5665 * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead.</li>
Esteban Talavera656fa7f2015-06-29 17:41:39 +01005666 * </ul>
Julia Reynoldsda551652014-05-14 17:15:16 -04005667 *
5668 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5669 * @param setting The name of the setting to update.
5670 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005671 * @throws SecurityException if {@code admin} is not a device owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005672 */
Robin Lee25e26452015-06-02 09:56:29 -07005673 public void setGlobalSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005674 throwIfParentInstance("setGlobalSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005675 if (mService != null) {
5676 try {
5677 mService.setGlobalSetting(admin, setting, value);
5678 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005679 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005680 }
5681 }
5682 }
5683
5684 /**
5685 * Called by profile or device owners to update {@link Settings.Secure} settings. Validation
5686 * that the value of the setting is in the correct form for the setting type should be performed
5687 * by the caller.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005688 * <p>
5689 * The settings that can be updated by a profile or device owner with this method are:
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005690 * <ul>
5691 * <li>{@link Settings.Secure#DEFAULT_INPUT_METHOD}</li>
Amith Yamasani52c39a12014-10-21 11:14:04 -07005692 * <li>{@link Settings.Secure#INSTALL_NON_MARKET_APPS}</li>
Julia Reynolds9ed66da2014-08-26 15:42:03 -04005693 * <li>{@link Settings.Secure#SKIP_FIRST_USE_HINTS}</li>
5694 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005695 * <p>
5696 * A device owner can additionally update the following settings:
Julia Reynolds82735bc2014-09-04 16:43:30 -04005697 * <ul>
5698 * <li>{@link Settings.Secure#LOCATION_MODE}</li>
5699 * </ul>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005700 *
Julia Reynoldsda551652014-05-14 17:15:16 -04005701 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5702 * @param setting The name of the setting to update.
5703 * @param value The value to update the setting to.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005704 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsda551652014-05-14 17:15:16 -04005705 */
Robin Lee25e26452015-06-02 09:56:29 -07005706 public void setSecureSetting(@NonNull ComponentName admin, String setting, String value) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005707 throwIfParentInstance("setSecureSetting");
Julia Reynoldsda551652014-05-14 17:15:16 -04005708 if (mService != null) {
5709 try {
5710 mService.setSecureSetting(admin, setting, value);
5711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005712 throw e.rethrowFromSystemServer();
Julia Reynoldsda551652014-05-14 17:15:16 -04005713 }
5714 }
5715 }
5716
Amith Yamasanif20d6402014-05-24 15:34:37 -07005717 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005718 * Designates a specific service component as the provider for making permission requests of a
5719 * local or remote administrator of the user.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005720 * <p/>
5721 * Only a profile owner can designate the restrictions provider.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005722 *
Amith Yamasanif20d6402014-05-24 15:34:37 -07005723 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005724 * @param provider The component name of the service that implements
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005725 * {@link RestrictionsReceiver}. If this param is null, it removes the restrictions
5726 * provider previously assigned.
5727 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasanif20d6402014-05-24 15:34:37 -07005728 */
Robin Lee25e26452015-06-02 09:56:29 -07005729 public void setRestrictionsProvider(@NonNull ComponentName admin,
5730 @Nullable ComponentName provider) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005731 throwIfParentInstance("setRestrictionsProvider");
Amith Yamasanif20d6402014-05-24 15:34:37 -07005732 if (mService != null) {
5733 try {
Amith Yamasanif6e2fcc2014-07-10 13:41:55 -07005734 mService.setRestrictionsProvider(admin, provider);
Amith Yamasanif20d6402014-05-24 15:34:37 -07005735 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005736 throw re.rethrowFromSystemServer();
Amith Yamasanif20d6402014-05-24 15:34:37 -07005737 }
5738 }
5739 }
Julia Reynolds4a21b252014-06-04 11:11:43 -04005740
5741 /**
5742 * Called by profile or device owners to set the master volume mute on or off.
Nicolas Prevotaef3ce22016-09-22 12:00:25 +01005743 * This has no effect when set on a managed profile.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005744 *
5745 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5746 * @param on {@code true} to mute master volume, {@code false} to turn mute off.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005747 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005748 */
Robin Lee25e26452015-06-02 09:56:29 -07005749 public void setMasterVolumeMuted(@NonNull ComponentName admin, boolean on) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005750 throwIfParentInstance("setMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005751 if (mService != null) {
5752 try {
5753 mService.setMasterVolumeMuted(admin, on);
5754 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005755 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005756 }
5757 }
5758 }
5759
5760 /**
5761 * Called by profile or device owners to check whether the master volume mute is on or off.
5762 *
5763 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5764 * @return {@code true} if master volume is muted, {@code false} if it's not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005765 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynolds4a21b252014-06-04 11:11:43 -04005766 */
Robin Lee25e26452015-06-02 09:56:29 -07005767 public boolean isMasterVolumeMuted(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005768 throwIfParentInstance("isMasterVolumeMuted");
Julia Reynolds4a21b252014-06-04 11:11:43 -04005769 if (mService != null) {
5770 try {
5771 return mService.isMasterVolumeMuted(admin);
5772 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005773 throw re.rethrowFromSystemServer();
Julia Reynolds4a21b252014-06-04 11:11:43 -04005774 }
5775 }
5776 return false;
5777 }
Kenny Guyc13053b2014-05-29 14:17:17 +01005778
5779 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005780 * Called by profile or device owners to change whether a user can uninstall a package.
Kenny Guyc13053b2014-05-29 14:17:17 +01005781 *
5782 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5783 * @param packageName package to change.
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005784 * @param uninstallBlocked true if the user shouldn't be able to uninstall the package.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005785 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005786 */
Robin Lee25e26452015-06-02 09:56:29 -07005787 public void setUninstallBlocked(@NonNull ComponentName admin, String packageName,
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005788 boolean uninstallBlocked) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005789 throwIfParentInstance("setUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005790 if (mService != null) {
5791 try {
Esteban Talaverad5c5c132014-08-20 11:35:57 +01005792 mService.setUninstallBlocked(admin, packageName, uninstallBlocked);
Kenny Guyc13053b2014-05-29 14:17:17 +01005793 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005794 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005795 }
5796 }
5797 }
5798
5799 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005800 * Check whether the user has been blocked by device policy from uninstalling a package.
Rubin Xua97855b2014-11-07 05:41:00 +00005801 * Requires the caller to be the profile owner if checking a specific admin's policy.
Rubin Xue1e6faa2015-03-10 10:51:59 +00005802 * <p>
5803 * <strong>Note:</strong> Starting from {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}, the
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005804 * behavior of this API is changed such that passing {@code null} as the {@code admin} parameter
5805 * will return if any admin has blocked the uninstallation. Before L MR1, passing {@code null}
5806 * will cause a NullPointerException to be raised.
Kenny Guyc13053b2014-05-29 14:17:17 +01005807 *
Robin Lee25e26452015-06-02 09:56:29 -07005808 * @param admin The name of the admin component whose blocking policy will be checked, or
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005809 * {@code null} to check whether any admin has blocked the uninstallation.
Kenny Guyc13053b2014-05-29 14:17:17 +01005810 * @param packageName package to check.
Rubin Xua97855b2014-11-07 05:41:00 +00005811 * @return true if uninstallation is blocked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005812 * @throws SecurityException if {@code admin} is not a device or profile owner.
Kenny Guyc13053b2014-05-29 14:17:17 +01005813 */
Robin Lee25e26452015-06-02 09:56:29 -07005814 public boolean isUninstallBlocked(@Nullable ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005815 throwIfParentInstance("isUninstallBlocked");
Kenny Guyc13053b2014-05-29 14:17:17 +01005816 if (mService != null) {
5817 try {
Esteban Talavera729b2a62014-08-27 18:01:58 +01005818 return mService.isUninstallBlocked(admin, packageName);
Kenny Guyc13053b2014-05-29 14:17:17 +01005819 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005820 throw re.rethrowFromSystemServer();
Kenny Guyc13053b2014-05-29 14:17:17 +01005821 }
5822 }
5823 return false;
5824 }
Svetoslav976e8bd2014-07-16 15:12:03 -07005825
5826 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005827 * Called by the profile owner of a managed profile to enable widget providers from a given
5828 * package to be available in the parent profile. As a result the user will be able to add
5829 * widgets from the white-listed package running under the profile to a widget host which runs
5830 * under the parent profile, for example the home screen. Note that a package may have zero or
5831 * more provider components, where each component provides a different widget type.
Svetoslav976e8bd2014-07-16 15:12:03 -07005832 * <p>
5833 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005834 *
5835 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5836 * @param packageName The package from which widget providers are white-listed.
5837 * @return Whether the package was added.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005838 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005839 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
5840 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5841 */
Robin Lee25e26452015-06-02 09:56:29 -07005842 public boolean addCrossProfileWidgetProvider(@NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005843 throwIfParentInstance("addCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005844 if (mService != null) {
5845 try {
5846 return mService.addCrossProfileWidgetProvider(admin, packageName);
5847 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005848 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005849 }
5850 }
5851 return false;
5852 }
5853
5854 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005855 * Called by the profile owner of a managed profile to disable widget providers from a given
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005856 * package to be available in the parent profile. For this method to take effect the package
5857 * should have been added via
5858 * {@link #addCrossProfileWidgetProvider( android.content.ComponentName, String)}.
Svetoslav976e8bd2014-07-16 15:12:03 -07005859 * <p>
5860 * <strong>Note:</strong> By default no widget provider package is white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005861 *
5862 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005863 * @param packageName The package from which widget providers are no longer white-listed.
Svetoslav976e8bd2014-07-16 15:12:03 -07005864 * @return Whether the package was removed.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005865 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005866 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5867 * @see #getCrossProfileWidgetProviders(android.content.ComponentName)
5868 */
Esteban Talavera62399912016-01-11 15:37:55 +00005869 public boolean removeCrossProfileWidgetProvider(
5870 @NonNull ComponentName admin, String packageName) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005871 throwIfParentInstance("removeCrossProfileWidgetProvider");
Svetoslav976e8bd2014-07-16 15:12:03 -07005872 if (mService != null) {
5873 try {
5874 return mService.removeCrossProfileWidgetProvider(admin, packageName);
5875 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005876 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005877 }
5878 }
5879 return false;
5880 }
5881
5882 /**
Amith Yamasanic34dc7c2014-09-18 09:42:42 -07005883 * Called by the profile owner of a managed profile to query providers from which packages are
Svetoslav976e8bd2014-07-16 15:12:03 -07005884 * available in the parent profile.
5885 *
5886 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5887 * @return The white-listed package list.
Svetoslav976e8bd2014-07-16 15:12:03 -07005888 * @see #addCrossProfileWidgetProvider(android.content.ComponentName, String)
5889 * @see #removeCrossProfileWidgetProvider(android.content.ComponentName, String)
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005890 * @throws SecurityException if {@code admin} is not a profile owner.
Svetoslav976e8bd2014-07-16 15:12:03 -07005891 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005892 public @NonNull List<String> getCrossProfileWidgetProviders(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005893 throwIfParentInstance("getCrossProfileWidgetProviders");
Svetoslav976e8bd2014-07-16 15:12:03 -07005894 if (mService != null) {
5895 try {
5896 List<String> providers = mService.getCrossProfileWidgetProviders(admin);
5897 if (providers != null) {
5898 return providers;
5899 }
5900 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005901 throw re.rethrowFromSystemServer();
Svetoslav976e8bd2014-07-16 15:12:03 -07005902 }
5903 }
5904 return Collections.emptyList();
5905 }
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005906
5907 /**
Makoto Onuki32b30572015-12-11 14:29:51 -08005908 * Called by profile or device owners to set the user's photo.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005909 *
5910 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
5911 * @param icon the bitmap to set as the photo.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005912 * @throws SecurityException if {@code admin} is not a device or profile owner.
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005913 */
Robin Lee25e26452015-06-02 09:56:29 -07005914 public void setUserIcon(@NonNull ComponentName admin, Bitmap icon) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005915 throwIfParentInstance("setUserIcon");
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005916 try {
5917 mService.setUserIcon(admin, icon);
5918 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005919 throw re.rethrowFromSystemServer();
Julia Reynoldsfca04ca2015-02-17 13:39:12 -05005920 }
5921 }
Craig Lafayettedbe31a62015-04-02 13:14:39 -04005922
5923 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005924 * Called by device owners to set a local system update policy. When a new policy is set,
5925 * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005926 *
Robin Lee25e26452015-06-02 09:56:29 -07005927 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. All
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005928 * components in the device owner package can set system update policies and the most
5929 * recent policy takes effect.
Robin Lee25e26452015-06-02 09:56:29 -07005930 * @param policy the new policy, or {@code null} to clear the current policy.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005931 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xu5faad8e2015-04-20 17:43:48 +01005932 * @see SystemUpdatePolicy
Rubin Xu8027a4f2015-03-10 17:52:37 +00005933 */
Robin Lee25e26452015-06-02 09:56:29 -07005934 public void setSystemUpdatePolicy(@NonNull ComponentName admin, SystemUpdatePolicy policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005935 throwIfParentInstance("setSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005936 if (mService != null) {
5937 try {
Robin Lee25e26452015-06-02 09:56:29 -07005938 mService.setSystemUpdatePolicy(admin, policy);
Rubin Xu8027a4f2015-03-10 17:52:37 +00005939 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005940 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005941 }
5942 }
5943 }
5944
5945 /**
Rubin Xu5faad8e2015-04-20 17:43:48 +01005946 * Retrieve a local system update policy set previously by {@link #setSystemUpdatePolicy}.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005947 *
Robin Lee25e26452015-06-02 09:56:29 -07005948 * @return The current policy object, or {@code null} if no policy is set.
Rubin Xu8027a4f2015-03-10 17:52:37 +00005949 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07005950 public @Nullable SystemUpdatePolicy getSystemUpdatePolicy() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005951 throwIfParentInstance("getSystemUpdatePolicy");
Rubin Xu8027a4f2015-03-10 17:52:37 +00005952 if (mService != null) {
5953 try {
Rubin Xud86d58c2015-05-05 16:57:37 +01005954 return mService.getSystemUpdatePolicy();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005955 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005956 throw re.rethrowFromSystemServer();
Rubin Xu8027a4f2015-03-10 17:52:37 +00005957 }
5958 }
5959 return null;
5960 }
Benjamin Franze36087e2015-04-07 16:40:34 +01005961
5962 /**
5963 * Called by a device owner to disable the keyguard altogether.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005964 * <p>
5965 * Setting the keyguard to disabled has the same effect as choosing "None" as the screen lock
5966 * type. However, this call has no effect if a password, pin or pattern is currently set. If a
5967 * password, pin or pattern is set after the keyguard was disabled, the keyguard stops being
5968 * disabled.
Benjamin Franze36087e2015-04-07 16:40:34 +01005969 *
5970 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005971 * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
Benjamin Franze36087e2015-04-07 16:40:34 +01005972 * @return {@code false} if attempting to disable the keyguard while a lock password was in
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005973 * place. {@code true} otherwise.
5974 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franze36087e2015-04-07 16:40:34 +01005975 */
Robin Lee25e26452015-06-02 09:56:29 -07005976 public boolean setKeyguardDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005977 throwIfParentInstance("setKeyguardDisabled");
Benjamin Franze36087e2015-04-07 16:40:34 +01005978 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005979 return mService.setKeyguardDisabled(admin, disabled);
Benjamin Franze36087e2015-04-07 16:40:34 +01005980 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07005981 throw re.rethrowFromSystemServer();
Benjamin Franze36087e2015-04-07 16:40:34 +01005982 }
5983 }
Benjamin Franzea2ec972015-03-16 17:18:09 +00005984
5985 /**
Benjamin Franzbece8062015-05-06 12:14:31 +01005986 * Called by device owner to disable the status bar. Disabling the status bar blocks
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005987 * notifications, quick settings and other screen overlays that allow escaping from a single use
5988 * device.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005989 *
5990 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Benjamin Franzbece8062015-05-06 12:14:31 +01005991 * @param disabled {@code true} disables the status bar, {@code false} reenables it.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07005992 * @return {@code false} if attempting to disable the status bar failed. {@code true} otherwise.
5993 * @throws SecurityException if {@code admin} is not a device owner.
Benjamin Franzea2ec972015-03-16 17:18:09 +00005994 */
Robin Lee25e26452015-06-02 09:56:29 -07005995 public boolean setStatusBarDisabled(@NonNull ComponentName admin, boolean disabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01005996 throwIfParentInstance("setStatusBarDisabled");
Benjamin Franzea2ec972015-03-16 17:18:09 +00005997 try {
Benjamin Franzbece8062015-05-06 12:14:31 +01005998 return mService.setStatusBarDisabled(admin, disabled);
Benjamin Franzea2ec972015-03-16 17:18:09 +00005999 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006000 throw re.rethrowFromSystemServer();
Benjamin Franzea2ec972015-03-16 17:18:09 +00006001 }
6002 }
Rubin Xudc105cc2015-04-14 23:38:01 +01006003
6004 /**
6005 * Callable by the system update service to notify device owners about pending updates.
6006 * The caller must hold {@link android.Manifest.permission#NOTIFY_PENDING_SYSTEM_UPDATE}
6007 * permission.
6008 *
6009 * @param updateReceivedTime The time as given by {@link System#currentTimeMillis()} indicating
6010 * when the current pending update was first available. -1 if no update is available.
6011 * @hide
6012 */
6013 @SystemApi
6014 public void notifyPendingSystemUpdate(long updateReceivedTime) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006015 throwIfParentInstance("notifyPendingSystemUpdate");
Rubin Xudc105cc2015-04-14 23:38:01 +01006016 if (mService != null) {
6017 try {
6018 mService.notifyPendingSystemUpdate(updateReceivedTime);
6019 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006020 throw re.rethrowFromSystemServer();
Rubin Xudc105cc2015-04-14 23:38:01 +01006021 }
6022 }
6023 }
Julia Reynolds13c58ba2015-04-20 16:42:54 -04006024
6025 /**
Amith Yamasanid49489b2015-04-28 14:00:26 -07006026 * Called by profile or device owners to set the default response for future runtime permission
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006027 * requests by applications. The policy can allow for normal operation which prompts the user to
6028 * grant a permission, or can allow automatic granting or denying of runtime permission requests
6029 * by an application. This also applies to new permissions declared by app updates. When a
6030 * permission is denied or granted this way, the effect is equivalent to setting the permission
6031 * grant state via {@link #setPermissionGrantState}.
6032 * <p/>
6033 * As this policy only acts on runtime permission requests, it only applies to applications
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006034 * built with a {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006035 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006036 * @param admin Which profile or device owner this request is associated with.
6037 * @param policy One of the policy constants {@link #PERMISSION_POLICY_PROMPT},
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006038 * {@link #PERMISSION_POLICY_AUTO_GRANT} and {@link #PERMISSION_POLICY_AUTO_DENY}.
6039 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz45dd6662015-07-08 14:24:14 +01006040 * @see #setPermissionGrantState
Amith Yamasanid49489b2015-04-28 14:00:26 -07006041 */
Robin Lee25e26452015-06-02 09:56:29 -07006042 public void setPermissionPolicy(@NonNull ComponentName admin, int policy) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006043 throwIfParentInstance("setPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006044 try {
6045 mService.setPermissionPolicy(admin, policy);
6046 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006047 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006048 }
6049 }
6050
6051 /**
6052 * Returns the current runtime permission policy set by the device or profile owner. The
6053 * default is {@link #PERMISSION_POLICY_PROMPT}.
6054 * @param admin Which profile or device owner this request is associated with.
6055 * @return the current policy for future permission requests.
6056 */
Esteban Talavera28b95702015-06-24 15:23:42 +01006057 public int getPermissionPolicy(ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006058 throwIfParentInstance("getPermissionPolicy");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006059 try {
6060 return mService.getPermissionPolicy(admin);
6061 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006062 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006063 }
6064 }
6065
6066 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006067 * Sets the grant state of a runtime permission for a specific application. The state can be
6068 * {@link #PERMISSION_GRANT_STATE_DEFAULT default} in which a user can manage it through the UI,
6069 * {@link #PERMISSION_GRANT_STATE_DENIED denied}, in which the permission is denied and the user
6070 * cannot manage it through the UI, and {@link #PERMISSION_GRANT_STATE_GRANTED granted} in which
6071 * the permission is granted and the user cannot manage it through the UI. This might affect all
6072 * permissions in a group that the runtime permission belongs to. This method can only be called
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006073 * by a profile or device owner.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006074 * <p/>
6075 * Setting the grant state to {@link #PERMISSION_GRANT_STATE_DEFAULT default} does not revoke
6076 * the permission. It retains the previous grant, if any.
6077 * <p/>
6078 * Permissions can be granted or revoked only for applications built with a
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -07006079 * {@code targetSdkVersion} of {@link android.os.Build.VERSION_CODES#M} or later.
Amith Yamasani0bf8f7c2015-06-22 13:00:32 -07006080 *
Amith Yamasanid49489b2015-04-28 14:00:26 -07006081 * @param admin Which profile or device owner this request is associated with.
6082 * @param packageName The application to grant or revoke a permission to.
6083 * @param permission The permission to grant or revoke.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006084 * @param grantState The permission grant state which is one of
6085 * {@link #PERMISSION_GRANT_STATE_DENIED}, {@link #PERMISSION_GRANT_STATE_DEFAULT},
6086 * {@link #PERMISSION_GRANT_STATE_GRANTED},
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006087 * @return whether the permission was successfully granted or revoked.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006088 * @throws SecurityException if {@code admin} is not a device or profile owner.
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006089 * @see #PERMISSION_GRANT_STATE_DENIED
6090 * @see #PERMISSION_GRANT_STATE_DEFAULT
6091 * @see #PERMISSION_GRANT_STATE_GRANTED
Amith Yamasanid49489b2015-04-28 14:00:26 -07006092 */
Robin Lee25e26452015-06-02 09:56:29 -07006093 public boolean setPermissionGrantState(@NonNull ComponentName admin, String packageName,
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006094 String permission, int grantState) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006095 throwIfParentInstance("setPermissionGrantState");
Amith Yamasanid49489b2015-04-28 14:00:26 -07006096 try {
Svet Ganovd8ecc5a2015-05-20 10:45:43 -07006097 return mService.setPermissionGrantState(admin, packageName, permission, grantState);
Amith Yamasanid49489b2015-04-28 14:00:26 -07006098 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006099 throw re.rethrowFromSystemServer();
Amith Yamasanid49489b2015-04-28 14:00:26 -07006100 }
6101 }
Amith Yamasani184b3752015-05-22 13:00:51 -07006102
6103 /**
6104 * Returns the current grant state of a runtime permission for a specific application.
6105 *
6106 * @param admin Which profile or device owner this request is associated with.
6107 * @param packageName The application to check the grant state for.
6108 * @param permission The permission to check for.
6109 * @return the current grant state specified by device policy. If the profile or device owner
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006110 * has not set a grant state, the return value is
6111 * {@link #PERMISSION_GRANT_STATE_DEFAULT}. This does not indicate whether or not the
6112 * permission is currently granted for the package.
6113 * <p/>
6114 * If a grant state was set by the profile or device owner, then the return value will
6115 * be one of {@link #PERMISSION_GRANT_STATE_DENIED} or
6116 * {@link #PERMISSION_GRANT_STATE_GRANTED}, which indicates if the permission is
6117 * currently denied or granted.
6118 * @throws SecurityException if {@code admin} is not a device or profile owner.
Amith Yamasani184b3752015-05-22 13:00:51 -07006119 * @see #setPermissionGrantState(ComponentName, String, String, int)
6120 * @see PackageManager#checkPermission(String, String)
6121 */
Robin Lee25e26452015-06-02 09:56:29 -07006122 public int getPermissionGrantState(@NonNull ComponentName admin, String packageName,
Amith Yamasani184b3752015-05-22 13:00:51 -07006123 String permission) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006124 throwIfParentInstance("getPermissionGrantState");
Amith Yamasani184b3752015-05-22 13:00:51 -07006125 try {
6126 return mService.getPermissionGrantState(admin, packageName, permission);
6127 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006128 throw re.rethrowFromSystemServer();
Amith Yamasani184b3752015-05-22 13:00:51 -07006129 }
6130 }
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006131
6132 /**
6133 * Returns if provisioning a managed profile or device is possible or not.
6134 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6135 * {@link #ACTION_PROVISION_MANAGED_PROFILE}.
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006136 * @return if provisioning a managed profile or device is possible or not.
6137 * @throws IllegalArgumentException if the supplied action is not valid.
6138 */
6139 public boolean isProvisioningAllowed(String action) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006140 throwIfParentInstance("isProvisioningAllowed");
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006141 try {
6142 return mService.isProvisioningAllowed(action);
6143 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006144 throw re.rethrowFromSystemServer();
Nicolas Prevot07387fe2015-10-30 17:53:30 +00006145 }
6146 }
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006147
6148 /**
Mahaver Chopra849fd6f2016-11-03 20:28:10 +00006149 * Checks if provisioning a managed profile or device is possible and returns one of the
6150 * {@link ProvisioningPreCondition}.
6151 *
6152 * @param action One of {@link #ACTION_PROVISION_MANAGED_DEVICE},
6153 * {@link #ACTION_PROVISION_MANAGED_PROFILE},
6154 * {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE},
6155 * {@link #ACTION_PROVISION_MANAGED_USER}
6156 * @hide
6157 */
6158 public @ProvisioningPreCondition int checkProvisioningPreCondition(String action) {
6159 try {
6160 return mService.checkProvisioningPreCondition(action);
6161 } catch (RemoteException re) {
6162 throw re.rethrowFromSystemServer();
6163 }
6164 }
6165
6166 /**
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006167 * Return if this user is a managed profile of another user. An admin can become the profile
6168 * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
Kenny Guyffa38402016-03-31 16:40:57 +01006169 * user with {@link #createAndManageUser}
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006170 * @param admin Which profile owner this request is associated with.
6171 * @return if this user is a managed profile of another user.
6172 */
6173 public boolean isManagedProfile(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006174 throwIfParentInstance("isManagedProfile");
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006175 try {
6176 return mService.isManagedProfile(admin);
6177 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006178 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006179 }
6180 }
6181
6182 /**
6183 * @hide
6184 * Return if this user is a system-only user. An admin can manage a device from a system only
6185 * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
6186 * @param admin Which device owner this request is associated with.
6187 * @return if this user is a system-only user.
6188 */
6189 public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
6190 try {
6191 return mService.isSystemOnlyUser(admin);
6192 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006193 throw re.rethrowFromSystemServer();
Mahaver Chopra15a46b02015-11-11 14:54:35 +00006194 }
6195 }
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006196
6197 /**
6198 * Called by device owner to get the MAC address of the Wi-Fi device.
6199 *
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006200 * @param admin Which device owner this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006201 * @return the MAC address of the Wi-Fi device, or null when the information is not available.
6202 * (For example, Wi-Fi hasn't been enabled, or the device doesn't support Wi-Fi.)
6203 * <p>
6204 * The address will be in the {@code XX:XX:XX:XX:XX:XX} format.
6205 * @throws SecurityException if {@code admin} is not a device owner.
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006206 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006207 public @Nullable String getWifiMacAddress(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006208 throwIfParentInstance("getWifiMacAddress");
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006209 try {
Sudheer Shanka3cb4da12016-03-07 18:51:49 -08006210 return mService.getWifiMacAddress(admin);
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006211 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006212 throw re.rethrowFromSystemServer();
Makoto Onukia31ebbc2015-11-23 17:15:21 -08006213 }
6214 }
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006215
6216 /**
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006217 * Called by device owner to reboot the device. If there is an ongoing call on the device,
6218 * throws an {@link IllegalStateException}.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006219 * @param admin Which device owner the request is associated with.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006220 * @throws IllegalStateException if device has an ongoing call.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006221 * @throws SecurityException if {@code admin} is not a device owner.
Mahaver Chopra1216ae52016-03-11 15:39:48 +00006222 * @see TelephonyManager#CALL_STATE_IDLE
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006223 */
6224 public void reboot(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006225 throwIfParentInstance("reboot");
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006226 try {
6227 mService.reboot(admin);
6228 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006229 throw re.rethrowFromSystemServer();
Mahaver Chopra1ce53bc2015-12-14 13:35:14 +00006230 }
6231 }
Kenny Guy06de4e72015-12-22 12:07:39 +00006232
6233 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006234 * Called by a device admin to set the short support message. This will be displayed to the user
6235 * in settings screens where funtionality has been disabled by the admin. The message should be
6236 * limited to a short statement such as "This setting is disabled by your administrator. Contact
6237 * someone@example.com for support." If the message is longer than 200 characters it may be
6238 * truncated.
6239 * <p>
6240 * If the short support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006241 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6242 * and set a new version of this string accordingly.
6243 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006244 * @see #setLongSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006245 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006246 * @param message Short message to be displayed to the user in settings or null to clear the
6247 * existing message.
6248 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006249 */
6250 public void setShortSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006251 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006252 throwIfParentInstance("setShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006253 if (mService != null) {
6254 try {
6255 mService.setShortSupportMessage(admin, message);
6256 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006257 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006258 }
6259 }
6260 }
6261
6262 /**
6263 * Called by a device admin to get the short support message.
6264 *
6265 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006266 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)} or
6267 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006268 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006269 */
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006270 public CharSequence getShortSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006271 throwIfParentInstance("getShortSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006272 if (mService != null) {
6273 try {
6274 return mService.getShortSupportMessage(admin);
6275 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006276 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006277 }
6278 }
6279 return null;
6280 }
6281
6282 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006283 * Called by a device admin to set the long support message. This will be displayed to the user
6284 * in the device administators settings screen.
6285 * <p>
6286 * If the long support message needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006287 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6288 * and set a new version of this string accordingly.
6289 *
Kenny Guy06de4e72015-12-22 12:07:39 +00006290 * @see #setShortSupportMessage
Kenny Guy06de4e72015-12-22 12:07:39 +00006291 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006292 * @param message Long message to be displayed to the user in settings or null to clear the
6293 * existing message.
6294 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006295 */
6296 public void setLongSupportMessage(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006297 @Nullable CharSequence message) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006298 throwIfParentInstance("setLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006299 if (mService != null) {
6300 try {
6301 mService.setLongSupportMessage(admin, message);
6302 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006303 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006304 }
6305 }
6306 }
6307
6308 /**
6309 * Called by a device admin to get the long support message.
6310 *
6311 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006312 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)} or
6313 * null if no message has been set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006314 * @throws SecurityException if {@code admin} is not an active administrator.
Kenny Guy06de4e72015-12-22 12:07:39 +00006315 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006316 public @Nullable CharSequence getLongSupportMessage(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006317 throwIfParentInstance("getLongSupportMessage");
Kenny Guy06de4e72015-12-22 12:07:39 +00006318 if (mService != null) {
6319 try {
6320 return mService.getLongSupportMessage(admin);
6321 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006322 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006323 }
6324 }
6325 return null;
6326 }
6327
6328 /**
6329 * Called by the system to get the short support message.
6330 *
6331 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6332 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006333 * @return The message set by {@link #setShortSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006334 *
6335 * @hide
6336 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006337 public @Nullable CharSequence getShortSupportMessageForUser(@NonNull ComponentName admin,
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006338 int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006339 if (mService != null) {
6340 try {
6341 return mService.getShortSupportMessageForUser(admin, userHandle);
6342 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006343 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006344 }
6345 }
6346 return null;
6347 }
6348
6349
6350 /**
6351 * Called by the system to get the long support message.
6352 *
6353 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6354 * @param userHandle user id the admin is running as.
Sudheer Shanka3ccca91e2016-04-11 21:36:17 -07006355 * @return The message set by {@link #setLongSupportMessage(ComponentName, CharSequence)}
Kenny Guy06de4e72015-12-22 12:07:39 +00006356 *
6357 * @hide
6358 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006359 public @Nullable CharSequence getLongSupportMessageForUser(
6360 @NonNull ComponentName admin, int userHandle) {
Kenny Guy06de4e72015-12-22 12:07:39 +00006361 if (mService != null) {
6362 try {
6363 return mService.getLongSupportMessageForUser(admin, userHandle);
6364 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006365 throw e.rethrowFromSystemServer();
Kenny Guy06de4e72015-12-22 12:07:39 +00006366 }
6367 }
6368 return null;
6369 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006370
6371 /**
Esteban Talavera62399912016-01-11 15:37:55 +00006372 * Called by the profile owner of a managed profile to obtain a {@link DevicePolicyManager}
6373 * whose calls act on the parent profile.
Benjamin Franz66b45f02016-04-05 19:12:39 +01006374 *
6375 * <p>The following methods are supported for the parent instance, all other methods will
6376 * throw a SecurityException when called on the parent instance:
6377 * <ul>
6378 * <li>{@link #getPasswordQuality}</li>
6379 * <li>{@link #setPasswordQuality}</li>
6380 * <li>{@link #getPasswordMinimumLength}</li>
6381 * <li>{@link #setPasswordMinimumLength}</li>
6382 * <li>{@link #getPasswordMinimumUpperCase}</li>
6383 * <li>{@link #setPasswordMinimumUpperCase}</li>
6384 * <li>{@link #getPasswordMinimumLowerCase}</li>
6385 * <li>{@link #setPasswordMinimumLowerCase}</li>
6386 * <li>{@link #getPasswordMinimumLetters}</li>
6387 * <li>{@link #setPasswordMinimumLetters}</li>
6388 * <li>{@link #getPasswordMinimumNumeric}</li>
6389 * <li>{@link #setPasswordMinimumNumeric}</li>
6390 * <li>{@link #getPasswordMinimumSymbols}</li>
6391 * <li>{@link #setPasswordMinimumSymbols}</li>
6392 * <li>{@link #getPasswordMinimumNonLetter}</li>
6393 * <li>{@link #setPasswordMinimumNonLetter}</li>
6394 * <li>{@link #getPasswordHistoryLength}</li>
6395 * <li>{@link #setPasswordHistoryLength}</li>
6396 * <li>{@link #getPasswordExpirationTimeout}</li>
6397 * <li>{@link #setPasswordExpirationTimeout}</li>
6398 * <li>{@link #getPasswordExpiration}</li>
Charles He8c760562016-10-25 16:36:53 +01006399 * <li>{@link #getPasswordMaximumLength}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006400 * <li>{@link #isActivePasswordSufficient}</li>
6401 * <li>{@link #getCurrentFailedPasswordAttempts}</li>
6402 * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
6403 * <li>{@link #setMaximumFailedPasswordsForWipe}</li>
6404 * <li>{@link #getMaximumTimeToLock}</li>
6405 * <li>{@link #setMaximumTimeToLock}</li>
6406 * <li>{@link #lockNow}</li>
6407 * <li>{@link #getKeyguardDisabledFeatures}</li>
6408 * <li>{@link #setKeyguardDisabledFeatures}</li>
6409 * <li>{@link #getTrustAgentConfiguration}</li>
6410 * <li>{@link #setTrustAgentConfiguration}</li>
Michal Karpinskia20d8bb2016-11-23 12:09:08 +00006411 * <li>{@link #getRequiredStrongAuthTimeout}</li>
6412 * <li>{@link #setRequiredStrongAuthTimeout}</li>
Benjamin Franz66b45f02016-04-05 19:12:39 +01006413 * </ul>
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006414 *
6415 * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006416 * @throws SecurityException if {@code admin} is not a profile owner.
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006417 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006418 public @NonNull DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006419 throwIfParentInstance("getParentProfileInstance");
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006420 try {
6421 if (!mService.isManagedProfile(admin)) {
6422 throw new SecurityException("The current user does not have a parent profile.");
6423 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006424 return new DevicePolicyManager(mContext, mService, true);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006425 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006426 throw e.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006427 }
6428 }
6429
6430 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006431 * Called by device owner to control the security logging feature. Logging can only be
6432 * enabled on single user devices where the sole user is managed by the device owner.
6433 *
6434 * <p> Security logs contain various information intended for security auditing purposes.
6435 * See {@link SecurityEvent} for details.
6436 *
6437 * <p>There must be only one user on the device, managed by the device owner.
6438 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006439 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006440 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006441 * @param enabled whether security logging should be enabled or not.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006442 * @throws SecurityException if {@code admin} is not a device owner.
Michal Karpinski6235a942016-03-15 12:07:23 +00006443 * @see #retrieveSecurityLogs
6444 */
6445 public void setSecurityLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006446 throwIfParentInstance("setSecurityLoggingEnabled");
Michal Karpinski6235a942016-03-15 12:07:23 +00006447 try {
6448 mService.setSecurityLoggingEnabled(admin, enabled);
6449 } catch (RemoteException re) {
6450 throw re.rethrowFromSystemServer();
6451 }
6452 }
6453
6454 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006455 * Return whether security logging is enabled or not by the device owner.
6456 *
6457 * <p>Can only be called by the device owner, otherwise a {@link SecurityException} will be
6458 * thrown.
6459 *
6460 * @param admin Which device owner this request is associated with.
6461 * @return {@code true} if security logging is enabled by device owner, {@code false} otherwise.
6462 * @throws SecurityException if {@code admin} is not a device owner.
6463 */
6464 public boolean isSecurityLoggingEnabled(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006465 throwIfParentInstance("isSecurityLoggingEnabled");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006466 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006467 return mService.isSecurityLoggingEnabled(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006468 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006469 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006470 }
6471 }
6472
6473 /**
Michal Karpinski6235a942016-03-15 12:07:23 +00006474 * Called by device owner to retrieve all new security logging entries since the last call to
6475 * this API after device boots.
6476 *
6477 * <p> Access to the logs is rate limited and it will only return new logs after the device
6478 * owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
6479 *
6480 * <p>There must be only one user on the device, managed by the device owner.
6481 * Otherwise a {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006482 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006483 * @param admin Which device owner this request is associated with.
Michal Karpinski6235a942016-03-15 12:07:23 +00006484 * @return the new batch of security logs which is a list of {@link SecurityEvent},
6485 * or {@code null} if rate limitation is exceeded or if logging is currently disabled.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006486 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006487 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006488 public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006489 throwIfParentInstance("retrieveSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006490 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006491 ParceledListSlice<SecurityEvent> list = mService.retrieveSecurityLogs(admin);
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006492 if (list != null) {
6493 return list.getList();
6494 } else {
6495 // Rate limit exceeded.
6496 return null;
6497 }
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006498 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006499 throw re.rethrowFromSystemServer();
Clara Bayarri3e826ef2015-12-14 17:51:22 +00006500 }
6501 }
Benjamin Franz59720bb2016-01-18 15:26:11 +00006502
6503 /**
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006504 * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
6505 * profile.
6506 *
6507 * @hide
6508 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006509 public @NonNull DevicePolicyManager getParentProfileInstance(UserInfo uInfo) {
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006510 mContext.checkSelfPermission(
6511 android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
6512 if (!uInfo.isManagedProfile()) {
6513 throw new SecurityException("The user " + uInfo.id
6514 + " does not have a parent profile.");
6515 }
Jeff Sharkey49ca5292016-05-10 12:54:45 -06006516 return new DevicePolicyManager(mContext, mService, true);
Sudheer Shanka978fc0d2016-01-28 13:51:10 +00006517 }
6518
6519 /**
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006520 * Called by device owners to retrieve device logs from before the device's last reboot.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006521 * <p>
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006522 * <strong> This API is not supported on all devices. Calling this API on unsupported devices
6523 * will result in {@code null} being returned. The device logs are retrieved from a RAM region
6524 * which is not guaranteed to be corruption-free during power cycles, as a result be cautious
6525 * about data corruption when parsing. </strong>
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006526 * <p>
6527 * There must be only one user on the device, managed by the device owner. Otherwise a
6528 * {@link SecurityException} will be thrown.
Michal Karpinskib58e4962016-03-01 14:55:10 +00006529 *
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006530 * @param admin Which device owner this request is associated with.
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006531 * @return Device logs from before the latest reboot of the system, or {@code null} if this API
6532 * is not supported on the device.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006533 * @throws SecurityException if {@code admin} is not a device owner.
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006534 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006535 public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
6536 @NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006537 throwIfParentInstance("retrievePreRebootSecurityLogs");
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006538 try {
Michal Karpinski6235a942016-03-15 12:07:23 +00006539 ParceledListSlice<SecurityEvent> list = mService.retrievePreRebootSecurityLogs(admin);
Rubin Xu0fb6b9e2016-05-04 19:01:07 +01006540 if (list != null) {
6541 return list.getList();
6542 } else {
6543 return null;
6544 }
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006545 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006546 throw re.rethrowFromSystemServer();
Rubin Xuc3cd05f2016-01-11 12:11:35 +00006547 }
6548 }
6549
6550 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006551 * Called by a profile owner of a managed profile to set the color used for customization. This
6552 * color is used as background color of the confirm credentials screen for that user. The
Clara Bayarri8d0bd7fa2016-03-30 14:59:58 +01006553 * default color is teal (#00796B).
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006554 * <p>
6555 * The confirm credentials screen can be created using
Benjamin Franz59720bb2016-01-18 15:26:11 +00006556 * {@link android.app.KeyguardManager#createConfirmDeviceCredentialIntent}.
6557 *
6558 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006559 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006560 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006561 */
6562 public void setOrganizationColor(@NonNull ComponentName admin, int color) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006563 throwIfParentInstance("setOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006564 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006565 // always enforce alpha channel to have 100% opacity
6566 color |= 0xFF000000;
Benjamin Franz59720bb2016-01-18 15:26:11 +00006567 mService.setOrganizationColor(admin, color);
6568 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006569 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006570 }
6571 }
6572
6573 /**
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006574 * @hide
6575 *
6576 * Sets the color used for customization.
6577 *
Michal Karpinski74cd7302016-04-12 15:17:36 +01006578 * @param color The 24bit (0xRRGGBB) representation of the color to be used.
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006579 * @param userId which user to set the color to.
6580 * @RequiresPermission(allOf = {
6581 * Manifest.permission.MANAGE_USERS,
6582 * Manifest.permission.INTERACT_ACROSS_USERS_FULL})
6583 */
6584 public void setOrganizationColorForUser(@ColorInt int color, @UserIdInt int userId) {
6585 try {
Michal Karpinski74cd7302016-04-12 15:17:36 +01006586 // always enforce alpha channel to have 100% opacity
6587 color |= 0xFF000000;
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006588 mService.setOrganizationColorForUser(color, userId);
6589 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006590 throw re.rethrowFromSystemServer();
Nicolas Prevot8f7698a2016-02-11 16:05:33 +00006591 }
6592 }
6593
6594 /**
Benjamin Franz59720bb2016-01-18 15:26:11 +00006595 * Called by a profile owner of a managed profile to retrieve the color used for customization.
6596 * This color is used as background color of the confirm credentials screen for that user.
6597 *
6598 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006599 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006600 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006601 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006602 public @ColorInt int getOrganizationColor(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006603 throwIfParentInstance("getOrganizationColor");
Benjamin Franz59720bb2016-01-18 15:26:11 +00006604 try {
6605 return mService.getOrganizationColor(admin);
6606 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006607 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006608 }
6609 }
6610
6611 /**
6612 * @hide
6613 * Retrieve the customization color for a given user.
6614 *
6615 * @param userHandle The user id of the user we're interested in.
Michal Karpinski74cd7302016-04-12 15:17:36 +01006616 * @return The 24bit (0xRRGGBB) representation of the color to be used.
Benjamin Franz59720bb2016-01-18 15:26:11 +00006617 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006618 public @ColorInt int getOrganizationColorForUser(int userHandle) {
Benjamin Franz59720bb2016-01-18 15:26:11 +00006619 try {
6620 return mService.getOrganizationColorForUser(userHandle);
6621 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006622 throw re.rethrowFromSystemServer();
Benjamin Franz59720bb2016-01-18 15:26:11 +00006623 }
6624 }
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006625
6626 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006627 * Called by the device owner or profile owner to set the name of the organization under
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006628 * management.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006629 * <p>
6630 * If the organization name needs to be localized, it is the responsibility of the
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006631 * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
6632 * and set a new version of this string accordingly.
6633 *
6634 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6635 * @param title The organization name or {@code null} to clear a previously set name.
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006636 * @throws SecurityException if {@code admin} is not a device or profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006637 */
Michal Karpinski74cd7302016-04-12 15:17:36 +01006638 public void setOrganizationName(@NonNull ComponentName admin, @Nullable CharSequence title) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006639 throwIfParentInstance("setOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006640 try {
6641 mService.setOrganizationName(admin, title);
6642 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006643 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006644 }
6645 }
6646
6647 /**
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006648 * Called by a profile owner of a managed profile to retrieve the name of the organization under
6649 * management.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006650 *
6651 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6652 * @return The organization name or {@code null} if none is set.
Suprabh Shukla34d92ef2016-03-14 13:49:37 -07006653 * @throws SecurityException if {@code admin} is not a profile owner.
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006654 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006655 public @Nullable CharSequence getOrganizationName(@NonNull ComponentName admin) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006656 throwIfParentInstance("getOrganizationName");
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006657 try {
6658 return mService.getOrganizationName(admin);
6659 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006660 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006661 }
6662 }
6663
6664 /**
Bartosz Fabianowski365a3db2016-11-30 18:28:10 +01006665 * Called by the system to retrieve the name of the organization managing the device.
6666 *
6667 * @return The organization name or {@code null} if none is set.
6668 * @throws SecurityException if the caller is not the device owner, does not hold the
6669 * MANAGE_USERS permission and is not the system.
6670 *
6671 * @hide
6672 */
6673 @SystemApi
6674 @TestApi
6675 public @Nullable CharSequence getDeviceOwnerOrganizationName() {
6676 try {
6677 return mService.getDeviceOwnerOrganizationName();
6678 } catch (RemoteException re) {
6679 throw re.rethrowFromSystemServer();
6680 }
6681 }
6682
6683 /**
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006684 * Retrieve the default title message used in the confirm credentials screen for a given user.
6685 *
6686 * @param userHandle The user id of the user we're interested in.
6687 * @return The organization name or {@code null} if none is set.
6688 *
6689 * @hide
6690 */
Makoto Onuki408e8e42016-10-25 12:10:27 -07006691 public @Nullable CharSequence getOrganizationNameForUser(int userHandle) {
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006692 try {
6693 return mService.getOrganizationNameForUser(userHandle);
6694 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006695 throw re.rethrowFromSystemServer();
Benjamin Franz3e8a7092016-01-25 16:19:08 +00006696 }
6697 }
6698
6699 /**
Alan Treadwayafad8782016-01-19 15:15:08 +00006700 * @return the {@link UserProvisioningState} for the current user - for unmanaged users will
6701 * return {@link #STATE_USER_UNMANAGED}
6702 * @hide
6703 */
Benjamin Franzeed2a8e2016-02-19 14:19:05 +00006704 @SystemApi
Alan Treadwayafad8782016-01-19 15:15:08 +00006705 @UserProvisioningState
6706 public int getUserProvisioningState() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006707 throwIfParentInstance("getUserProvisioningState");
Alan Treadwayafad8782016-01-19 15:15:08 +00006708 if (mService != null) {
6709 try {
6710 return mService.getUserProvisioningState();
6711 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006712 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006713 }
6714 }
6715 return STATE_USER_UNMANAGED;
6716 }
6717
6718 /**
6719 * Set the {@link UserProvisioningState} for the supplied user, if they are managed.
6720 *
6721 * @param state to store
6722 * @param userHandle for user
6723 * @hide
6724 */
6725 public void setUserProvisioningState(@UserProvisioningState int state, int userHandle) {
6726 if (mService != null) {
6727 try {
6728 mService.setUserProvisioningState(state, userHandle);
6729 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006730 throw e.rethrowFromSystemServer();
Alan Treadwayafad8782016-01-19 15:15:08 +00006731 }
6732 }
6733 }
6734
6735 /**
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006736 * Indicates the entity that controls the device or profile owner. Two users/profiles are
6737 * affiliated if the set of ids set by their device or profile owners intersect.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006738 *
6739 * @param admin Which profile or device owner this request is associated with.
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006740 * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
6741 *
6742 * @throws NullPointerException if {@code ids} is null or contains null elements.
6743 * @throws IllegalArgumentException if {@code ids} contains an empty string.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006744 */
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006745 public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006746 throwIfParentInstance("setAffiliationIds");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006747 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006748 mService.setAffiliationIds(admin, ids);
6749 } catch (RemoteException e) {
6750 throw e.rethrowFromSystemServer();
6751 }
6752 }
6753
6754 /**
6755 * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
6756 * empty list if none have been set.
6757 */
6758 public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
6759 throwIfParentInstance("getAffiliationIds");
6760 try {
6761 return mService.getAffiliationIds(admin);
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006762 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006763 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006764 }
6765 }
6766
6767 /**
6768 * @hide
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006769 * Returns whether this user/profile is affiliated with the device.
6770 * <p>
6771 * By definition, the user that the device owner runs on is always affiliated with the device.
6772 * Any other user/profile is considered affiliated with the device if the set specified by its
6773 * profile owner via {@link #setAffiliationIds} intersects with the device owner's.
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006774 *
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006775 */
6776 public boolean isAffiliatedUser() {
Benjamin Franzbc33c822016-04-15 08:57:52 +01006777 throwIfParentInstance("isAffiliatedUser");
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006778 try {
Esteban Talaverac9bb3782016-11-11 15:41:14 +00006779 return mService.isAffiliatedUser();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006780 } catch (RemoteException e) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006781 throw e.rethrowFromSystemServer();
Bartosz Fabianowski4c052f22016-01-25 14:18:43 +01006782 }
6783 }
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006784
6785 /**
6786 * @hide
6787 * Returns whether the uninstall for {@code packageName} for the current user is in queue
6788 * to be started
6789 * @param packageName the package to check for
6790 * @return whether the uninstall intent for {@code packageName} is pending
6791 */
6792 public boolean isUninstallInQueue(String packageName) {
6793 try {
6794 return mService.isUninstallInQueue(packageName);
6795 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006796 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006797 }
6798 }
6799
6800 /**
6801 * @hide
6802 * @param packageName the package containing active DAs to be uninstalled
6803 */
6804 public void uninstallPackageWithActiveAdmins(String packageName) {
6805 try {
6806 mService.uninstallPackageWithActiveAdmins(packageName);
6807 } catch (RemoteException re) {
Jeff Sharkeydbff9ca2016-03-01 19:46:25 -07006808 throw re.rethrowFromSystemServer();
Suprabh Shuklaa2ae2232016-01-28 18:05:14 -08006809 }
6810 }
Benjamin Franzbc33c822016-04-15 08:57:52 +01006811
Kenny Guy38dcca52016-04-19 13:09:18 +01006812 /**
6813 * @hide
6814 * Remove a test admin synchronously without sending it a broadcast about being removed.
6815 * If the admin is a profile owner or device owner it will still be removed.
6816 *
6817 * @param userHandle user id to remove the admin for.
6818 * @param admin The administration compononent to remove.
6819 * @throws SecurityException if the caller is not shell / root or the admin package
6820 * isn't a test application see {@link ApplicationInfo#FLAG_TEST_APP}.
6821 */
6822 public void forceRemoveActiveAdmin(ComponentName adminReceiver, int userHandle) {
6823 try {
6824 mService.forceRemoveActiveAdmin(adminReceiver, userHandle);
6825 } catch (RemoteException re) {
6826 throw re.rethrowFromSystemServer();
6827 }
6828 }
6829
Mahaver Chopra790d1982016-07-07 16:06:49 +01006830 /**
6831 * @hide
6832 * @return whether {@link android.provider.Settings.Global#DEVICE_PROVISIONED} has ever been set
6833 * to 1.
6834 */
6835 public boolean isDeviceProvisioned() {
6836 try {
6837 return mService.isDeviceProvisioned();
6838 } catch (RemoteException re) {
6839 throw re.rethrowFromSystemServer();
6840 }
6841 }
6842
Benjamin Franz2aa9bab2016-07-11 19:10:36 +01006843 /**
6844 * @hide
6845 * Writes that the provisioning configuration has been applied.
6846 */
6847 public void setDeviceProvisioningConfigApplied() {
6848 try {
6849 mService.setDeviceProvisioningConfigApplied();
6850 } catch (RemoteException re) {
6851 throw re.rethrowFromSystemServer();
6852 }
6853 }
6854
6855 /**
6856 * @hide
6857 * @return whether the provisioning configuration has been applied.
6858 */
6859 public boolean isDeviceProvisioningConfigApplied() {
6860 try {
6861 return mService.isDeviceProvisioningConfigApplied();
6862 } catch (RemoteException re) {
6863 throw re.rethrowFromSystemServer();
6864 }
6865 }
6866
Victor Chang9bfc65f2016-08-15 12:27:09 +01006867 /**
6868 * @hide
Victor Chang3577ed22016-08-25 18:49:26 +01006869 * Force update user setup completed status. This API has no effect on user build.
6870 * @throws {@link SecurityException} if the caller has no
6871 * {@link android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
6872 * not {@link UserHandle.SYSTEM_USER}
Victor Chang9bfc65f2016-08-15 12:27:09 +01006873 */
6874 public void forceUpdateUserSetupComplete() {
6875 try {
6876 mService.forceUpdateUserSetupComplete();
6877 } catch (RemoteException re) {
6878 throw re.rethrowFromSystemServer();
6879 }
6880 }
6881
Benjamin Franzbc33c822016-04-15 08:57:52 +01006882 private void throwIfParentInstance(String functionName) {
6883 if (mParentInstance) {
6884 throw new SecurityException(functionName + " cannot be called on the parent instance");
6885 }
6886 }
Vladislav Kuzkokova8202522016-08-18 19:01:27 +02006887
6888 /**
6889 * @hide
6890 * Enable backup service.
6891 * <p>This includes all backup and restore mechanisms.
6892 * Setting this to {@code false} will make backup service no-op or return empty results.
6893 *
6894 * <p>There must be only one user on the device, managed by the device owner.
6895 * Otherwise a {@link SecurityException} will be thrown.
6896 *
6897 * <p>Backup service is off by default when device owner is present.
6898 */
6899 public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
6900 try {
6901 mService.setBackupServiceEnabled(admin, enabled);
6902 } catch (RemoteException re) {
6903 throw re.rethrowFromSystemServer();
6904 }
6905 }
6906
6907 /**
6908 * @hide
6909 * @return {@code true} if backup service is enabled, {@code false} otherwise.
6910 */
6911 public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
6912 try {
6913 return mService.isBackupServiceEnabled(admin);
6914 } catch (RemoteException re) {
6915 throw re.rethrowFromSystemServer();
6916 }
6917 }
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006918
6919 /**
6920 * Called by a device owner to control the network logging feature. Logging can only be
6921 * enabled on single user devices where the sole user is managed by the device owner. If a new
6922 * user is added on the device, logging is disabled.
6923 *
6924 * <p> Network logs contain DNS lookup and connect() library call events.
6925 *
6926 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
6927 * @param enabled whether network logging should be enabled or not.
6928 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006929 * @see #retrieveNetworkLogs
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006930 */
6931 public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
6932 throwIfParentInstance("setNetworkLoggingEnabled");
6933 try {
6934 mService.setNetworkLoggingEnabled(admin, enabled);
6935 } catch (RemoteException re) {
6936 throw re.rethrowFromSystemServer();
6937 }
6938 }
6939
6940 /**
6941 * Return whether network logging is enabled by a device owner.
6942 *
phweissa4e169e2016-11-24 16:20:57 +01006943 * @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
6944 * be {@code null} if the caller has MANAGE_USERS permission.
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006945 * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
phweissa4e169e2016-11-24 16:20:57 +01006946 * @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
6947 * no MANAGE_USERS permission
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006948 */
phweissa4e169e2016-11-24 16:20:57 +01006949 public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
Michal Karpinskidd9bb4f2016-10-12 14:59:26 +01006950 throwIfParentInstance("isNetworkLoggingEnabled");
6951 try {
6952 return mService.isNetworkLoggingEnabled(admin);
6953 } catch (RemoteException re) {
6954 throw re.rethrowFromSystemServer();
6955 }
6956 }
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006957
6958 /**
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006959 * Called by device owner to retrieve the most recent batch of network logging events.
6960 * A device owner has to provide a batchToken provided as part of
6961 * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
6962 * token of the most recent available batch of logs, {@code null} will be returned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006963 *
6964 * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
6965 *
6966 * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
6967 *
6968 * <p> Access to the logs is rate limited and this method will only return a new batch of logs
6969 * after the device device owner has been notified via
6970 * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
6971 *
6972 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006973 * @param batchToken A token of the batch to retrieve
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006974 * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006975 * {@code null} if the batch represented by batchToken is no longer available or if
6976 * logging is disabled.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006977 * @throws {@link SecurityException} if {@code admin} is not a device owner.
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006978 * @see DeviceAdminReceiver#onNetworkLogsAvailable
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006979 */
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006980 public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
6981 long batchToken) {
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006982 throwIfParentInstance("retrieveNetworkLogs");
6983 try {
Michal Karpinskia9ff2062016-11-03 15:46:17 +00006984 return mService.retrieveNetworkLogs(admin, batchToken);
Michal Karpinskif77ee4f2016-10-12 16:40:06 +01006985 } catch (RemoteException re) {
6986 throw re.rethrowFromSystemServer();
6987 }
6988 }
Tony Mak46aabe52016-11-14 12:53:06 +00006989
6990 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006991 * Called by a device owner to bind to a service from a profile owner of a managed profile or
6992 * vice versa. See {@link #getBindDeviceAdminTargetUsers} for a definition of which
6993 * device/profile owners are allowed to bind to services of another profile/device owner.
6994 * <p>
Tony Mak46aabe52016-11-14 12:53:06 +00006995 * The service must be unexported. Note that the {@link Context} used to obtain this
6996 * {@link DevicePolicyManager} instance via {@link Context#getSystemService(Class)} will be used
6997 * to bind to the {@link android.app.Service}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00006998 *
Tony Mak46aabe52016-11-14 12:53:06 +00006999 * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
7000 * @param serviceIntent Identifies the service to connect to. The Intent must specify either an
7001 * explicit component name or a package name to match an
7002 * {@link IntentFilter} published by a service.
7003 * @param conn Receives information as the service is started and stopped. This must be a
7004 * valid {@link ServiceConnection} object; it must not be {@code null}.
7005 * @param flags Operation options for the binding operation. See
7006 * {@link Context#bindService(Intent, ServiceConnection, int)}.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007007 * @param targetUser Which user to bind to. Must be one of the users returned by
7008 * {@link #getBindDeviceAdminTargetUsers}, otherwise a {@link SecurityException} will
7009 * be thrown.
Tony Mak46aabe52016-11-14 12:53:06 +00007010 * @return If you have successfully bound to the service, {@code true} is returned;
7011 * {@code false} is returned if the connection is not made and you will not
7012 * receive the service object.
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007013 *
Tony Mak46aabe52016-11-14 12:53:06 +00007014 * @see Context#bindService(Intent, ServiceConnection, int)
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007015 * @see #getBindDeviceAdminTargetUsers(ComponentName)
Tony Mak46aabe52016-11-14 12:53:06 +00007016 */
7017 public boolean bindDeviceAdminServiceAsUser(
7018 @NonNull ComponentName admin, Intent serviceIntent, @NonNull ServiceConnection conn,
7019 @Context.BindServiceFlags int flags, @NonNull UserHandle targetUser) {
7020 throwIfParentInstance("bindDeviceAdminServiceAsUser");
7021 // Keep this in sync with ContextImpl.bindServiceCommon.
7022 try {
7023 final IServiceConnection sd = mContext.getServiceDispatcher(conn, null, flags);
7024 serviceIntent.prepareToLeaveProcess(mContext);
7025 return mService.bindDeviceAdminServiceAsUser(admin,
7026 mContext.getIApplicationThread(), mContext.getActivityToken(), serviceIntent,
7027 sd, flags, targetUser.getIdentifier());
7028 } catch (RemoteException re) {
7029 throw re.rethrowFromSystemServer();
7030 }
7031 }
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007032
7033 /**
Esteban Talaverafc291bc2016-11-21 13:52:03 +00007034 * Returns the list of target users that the calling device or profile owner can use when
7035 * calling {@link #bindDeviceAdminServiceAsUser}.
7036 * <p>
7037 * A device owner can bind to a service from a profile owner of a managed profile and
7038 * vice versa, provided that:
7039 * <ul>
7040 * <li>Both belong to the same package name.
7041 * <li>The managed profile is a profile of the user where the device owner is set.
7042 * See {@link UserManager#getUserProfiles()}
7043 * <li>Both users are affiliated.
7044 * STOPSHIP(b/32326223) Add reference to setAffiliationIds here once public.
7045 * </ul>
7046 */
7047 public @NonNull List<UserHandle> getBindDeviceAdminTargetUsers(@NonNull ComponentName admin) {
7048 throwIfParentInstance("getBindDeviceAdminTargetUsers");
7049 try {
7050 return mService.getBindDeviceAdminTargetUsers(admin);
7051 } catch (RemoteException re) {
7052 throw re.rethrowFromSystemServer();
7053 }
7054 }
7055
7056 /**
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007057 * Called by the system to get the time at which the device owner last retrieved security
7058 * logging entries.
7059 *
7060 * @return the time at which the device owner most recently retrieved security logging entries,
7061 * in milliseconds since epoch; -1 if security logging entries were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007062 * @throws SecurityException if the caller is not the device owner, does not hold the
7063 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007064 *
7065 * @hide
7066 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007067 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007068 public long getLastSecurityLogRetrievalTime() {
7069 try {
7070 return mService.getLastSecurityLogRetrievalTime();
7071 } catch (RemoteException re) {
7072 throw re.rethrowFromSystemServer();
7073 }
7074 }
7075
7076 /**
7077 * Called by the system to get the time at which the device owner last requested a bug report.
7078 *
7079 * @return the time at which the device owner most recently requested a bug report, in
7080 * milliseconds since epoch; -1 if a bug report was never requested.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007081 * @throws SecurityException if the caller is not the device owner, does not hold the
7082 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007083 *
7084 * @hide
7085 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007086 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007087 public long getLastBugReportRequestTime() {
7088 try {
7089 return mService.getLastBugReportRequestTime();
7090 } catch (RemoteException re) {
7091 throw re.rethrowFromSystemServer();
7092 }
7093 }
7094
7095 /**
7096 * Called by the system to get the time at which the device owner last retrieved network logging
7097 * events.
7098 *
7099 * @return the time at which the device owner most recently retrieved network logging events, in
7100 * milliseconds since epoch; -1 if network logging events were never retrieved.
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007101 * @throws SecurityException if the caller is not the device owner, does not hold the
7102 * MANAGE_USERS permission and is not the system.
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007103 *
7104 * @hide
7105 */
Bartosz Fabianowski8d76e722016-11-25 12:36:20 +01007106 @TestApi
Bartosz Fabianowskib21b2412016-11-17 04:53:33 +01007107 public long getLastNetworkLogRetrievalTime() {
7108 try {
7109 return mService.getLastNetworkLogRetrievalTime();
7110 } catch (RemoteException re) {
7111 throw re.rethrowFromSystemServer();
7112 }
7113 }
Dianne Hackbornd6847842010-01-12 18:14:19 -08007114}